Skip to content

Commit b73bbf4

Browse files
committed
🚨 SASL: add_authenticator warns on reassignment [🚧 test]
1 parent 7e1c3fb commit b73bbf4

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/net/imap/sasl/authenticators.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ def authenticators; @authenticators.dup end
2020
# {SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
2121
# implemented by +authenticator+ (for instance, <tt>"PLAIN"</tt>).
2222
#
23+
# If +mechanism+ refers to an existing authenticator, a warning will be
24+
# printed and the old authenticator will be replaced.
25+
#
2326
# The +authenticator+ must respond to +#new+ (or #call), receiving the
2427
# authenticator configuration and return a configured authentication session.
2528
# The authenticator session must respond to +#process+, receiving the server's
2629
# challenge and returning the client's response.
2730
#
2831
# See PlainAuthenticator, XOauth2Authenticator, and DigestMD5Authenticator for
2932
# examples.
30-
def add_authenticator(mechanism, authenticator)
31-
@authenticators[mechanism.upcase] = authenticator
33+
def add_authenticator(mechanism, authenticator, warn_overwrite: true)
34+
mechanism = mechanism.to_str
35+
upcased = mechanism.upcase
36+
if warn_overwrite && (original = authenticators[upcased])
37+
warn("%p: replacing %p authenticator: %p" % [ self, upcased, original],
38+
uplevel: 1)
39+
end
40+
@authenticators[upcased] = authenticator
3241
end
3342

3443
# :call-seq:

0 commit comments

Comments
 (0)