Skip to content

Commit 7a089d9

Browse files
committed
🔒 SASL PLAIN: update ArgumentError and docs
1 parent 0fbf55a commit 7a089d9

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/net/imap/sasl/plain_authenticator.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class Net::IMAP::SASL::PlainAuthenticator
1616

1717
# Authentication identity: the identity that matches the #password.
1818
#
19+
# RFC-2831[https://tools.ietf.org/html/rfc2831] uses the term +username+.
20+
# "Authentication identity" is the generic term used by
21+
# RFC-4422[https://tools.ietf.org/html/rfc4422].
1922
# RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
2023
# this to +authcid+.
2124
attr_reader :username
@@ -53,14 +56,16 @@ class Net::IMAP::SASL::PlainAuthenticator
5356
# See attribute documentation for more details.
5457
def initialize(user = nil, pass = nil,
5558
username: nil, password: nil, authzid: nil, **)
56-
username ||= user or raise ArgumentError, "missing username"
57-
password ||= pass or raise ArgumentError, "missing password"
58-
raise ArgumentError, "username contains NULL" if username.include?(NULL)
59-
raise ArgumentError, "password contains NULL" if password.include?(NULL)
60-
raise ArgumentError, "authzid contains NULL" if authzid&.include?(NULL)
61-
@username = username
62-
@password = password
59+
@username = username || user or raise ArgumentError, "missing username"
60+
@password = password || pass or raise ArgumentError, "missing password"
6361
@authzid = authzid
62+
[username, user].compact.count == 1 or
63+
raise ArgumentError, "conflicting values for username"
64+
[password, pass].compact.count == 1 or
65+
raise ArgumentError, "conflicting values for password"
66+
raise ArgumentError, "username contains NULL" if @username.include?(NULL)
67+
raise ArgumentError, "password contains NULL" if @password.include?(NULL)
68+
raise ArgumentError, "authzid contains NULL" if @authzid&.include?(NULL)
6469
end
6570

6671
# :call-seq:

0 commit comments

Comments
 (0)