From 7a089d945074d6d45cce7e1b4d2bb9996d888eca Mon Sep 17 00:00:00 2001 From: nick evans Date: Mon, 7 Nov 2022 22:27:42 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20SASL=20PLAIN:=20update=20Argumen?= =?UTF-8?q?tError=20and=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/net/imap/sasl/plain_authenticator.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/net/imap/sasl/plain_authenticator.rb b/lib/net/imap/sasl/plain_authenticator.rb index 8b04ab7f..5b1f41eb 100644 --- a/lib/net/imap/sasl/plain_authenticator.rb +++ b/lib/net/imap/sasl/plain_authenticator.rb @@ -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 @@ -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: