Skip to content

Commit 078ea33

Browse files
committed
🚨 SASL: add_authenticator warns on reassignment [🚧WIP: no test]
1 parent bf4bee6 commit 078ea33

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/net/imap/authenticators.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@ module Net::IMAP::Authenticators
77
# {SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
88
# implemented by +authenticator+ (for instance, <tt>"PLAIN"</tt>).
99
#
10+
# If +mechanism+ refers to an existing authenticator, a warning will be
11+
# printed and the old authenticator will be replaced.
12+
#
1013
# The +authenticator+ must respond to +#new+ (or #call), receiving the
1114
# authenticator configuration and return a configured authentication session.
1215
# The authenticator session must respond to +#process+, receiving the server's
1316
# challenge and returning the client's response.
1417
#
1518
# See PlainAuthenticator, XOauth2Authenticator, and DigestMD5Authenticator for
1619
# examples.
17-
def add_authenticator(auth_type, authenticator)
18-
authenticators[auth_type] = authenticator
20+
def add_authenticator(mechanism, authenticator, warn_overwrite: true)
21+
if warn_overwrite && (original = authenticators[mechanism])
22+
warn("%p: replacing %p authenticator: %p" % [ self, mechanism, original],
23+
uplevel: 1)
24+
end
25+
authenticators[mechanism] = authenticator
1926
end
2027

2128
# :call-seq:

0 commit comments

Comments
 (0)