Skip to content

Commit

Permalink
🔒 SASL PLAIN: update ArgumentError and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Sep 21, 2023
1 parent 0fbf55a commit 7a089d9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/net/imap/sasl/plain_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Net::IMAP::SASL::PlainAuthenticator

# Authentication identity: the identity that matches the #password.
#
# RFC-2831[https://tools.ietf.org/html/rfc2831] uses the term +username+.
# "Authentication identity" is the generic term used by
# RFC-4422[https://tools.ietf.org/html/rfc4422].
# RFC-4616[https://tools.ietf.org/html/rfc4616] and many later RFCs abbreviate
# this to +authcid+.
attr_reader :username
Expand Down Expand Up @@ -53,14 +56,16 @@ class Net::IMAP::SASL::PlainAuthenticator
# See attribute documentation for more details.
def initialize(user = nil, pass = nil,
username: nil, password: nil, authzid: nil, **)
username ||= user or raise ArgumentError, "missing username"
password ||= pass or raise ArgumentError, "missing password"
raise ArgumentError, "username contains NULL" if username.include?(NULL)
raise ArgumentError, "password contains NULL" if password.include?(NULL)
raise ArgumentError, "authzid contains NULL" if authzid&.include?(NULL)
@username = username
@password = password
@username = username || user or raise ArgumentError, "missing username"
@password = password || pass or raise ArgumentError, "missing password"
@authzid = authzid
[username, user].compact.count == 1 or
raise ArgumentError, "conflicting values for username"
[password, pass].compact.count == 1 or
raise ArgumentError, "conflicting values for password"
raise ArgumentError, "username contains NULL" if @username.include?(NULL)
raise ArgumentError, "password contains NULL" if @password.include?(NULL)
raise ArgumentError, "authzid contains NULL" if @authzid&.include?(NULL)
end

# :call-seq:
Expand Down

0 comments on commit 7a089d9

Please sign in to comment.