Skip to content

Commit 7629c21

Browse files
committed
🔒 Don't raise ArgumentError for overriding args
Instead of raising an exception, conflicting arguments are silently ignored. This allows more specific argument (like `authcid` or a keyword argument) to be used like an override to more generic terms (like `username` or a positional argument). It should also simplify using a single set of keyword credentials with multiple SASL mechanisms, which could facilitate dynamically negotiating the mechanism, or automatically retrying multiple acceptable mechanisms.
1 parent f36d753 commit 7629c21

File tree

4 files changed

+0
-14
lines changed

4 files changed

+0
-14
lines changed

lib/net/imap/sasl/oauthbearer_authenticator.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ class OAuthBearerAuthenticator < OAuthAuthenticator
176176
def initialize(arg1 = nil, arg2 = nil, oauth2_token: nil, **args, &blk)
177177
username, oauth2_token_arg = arg2.nil? ? [nil, arg1] : [arg1, arg2]
178178
super(username: username, **args, &blk)
179-
oauth2_token && oauth2_token_arg and
180-
raise ArgumentError, "conflicting values for oauth2_token"
181179
@oauth2_token = oauth2_token || oauth2_token_arg or
182180
raise ArgumentError, "missing oauth2_token"
183181
end

lib/net/imap/sasl/plain_authenticator.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ class Net::IMAP::SASL::PlainAuthenticator
6666
def initialize(user = nil, pass = nil,
6767
authcid: nil,
6868
username: nil, password: nil, authzid: nil, **)
69-
[authcid, username, user].compact.count <= 1 or
70-
raise ArgumentError, "conflicting values for username (authcid)"
71-
[password, pass].compact.count <= 1 or
72-
raise ArgumentError, "conflicting values for password"
7369
username ||= authcid || user or
7470
raise ArgumentError, "missing username (authcid)"
7571
password ||= pass or raise ArgumentError, "missing password"

lib/net/imap/sasl/scram_authenticator.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,8 @@ def initialize(username_arg = nil, password_arg = nil,
8686
**options)
8787
@username = username || username_arg || authcid or
8888
raise ArgumentError, "missing username (authcid)"
89-
[username, username_arg, authcid].compact.count == 1 or
90-
raise ArgumentError, "conflicting values for username (authcid)"
9189
@password = password || password_arg or
9290
raise ArgumentError, "missing password"
93-
[password, password_arg].compact.count == 1 or
94-
raise ArgumentError, "conflicting values for password"
9591
@authzid = authzid
9692

9793
@min_iterations = Integer min_iterations

lib/net/imap/sasl/xoauth2_authenticator.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ def initialize(user = nil, token = nil, username: nil, oauth2_token: nil,
7373
raise ArgumentError, "missing username (authzid)"
7474
@oauth2_token = oauth2_token || token or
7575
raise ArgumentError, "missing oauth2_token"
76-
[username, user].compact.count == 1 or
77-
raise ArgumentError, "conflicting values for username"
78-
[oauth2_token, token].compact.count == 1 or
79-
raise ArgumentError, "conflicting values for oauth2_token"
8076
@done = false
8177
end
8278

0 commit comments

Comments
 (0)