From 8ee0bfa85168b3ed6b124c063506360d76554815 Mon Sep 17 00:00:00 2001 From: "nicholas a. evans" Date: Mon, 7 Nov 2022 21:07:43 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8=20SASL:=20add=5Fauthenticator=20wa?= =?UTF-8?q?rns=20on=20reassignment=20[=F0=9F=9A=A7WIP:=20no=20test]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/net/imap/authenticators.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/net/imap/authenticators.rb b/lib/net/imap/authenticators.rb index 3659274b..e7a3af2f 100644 --- a/lib/net/imap/authenticators.rb +++ b/lib/net/imap/authenticators.rb @@ -7,6 +7,9 @@ module Net::IMAP::Authenticators # {SASL mechanism}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml] # implemented by +authenticator+ (for instance, "PLAIN"). # + # If +mechanism+ refers to an existing authenticator, a warning will be + # printed and the old authenticator will be replaced. + # # The +authenticator+ must respond to +#new+ (or #call), receiving the # authenticator configuration and return a configured authentication session. # The authenticator session must respond to +#process+, receiving the server's @@ -14,8 +17,12 @@ module Net::IMAP::Authenticators # # See PlainAuthenticator, XOauth2Authenticator, and DigestMD5Authenticator for # examples. - def add_authenticator(auth_type, authenticator) - authenticators[auth_type] = authenticator + def add_authenticator(mechanism, authenticator, warn_overwrite: true) + if warn_overwrite && (original = authenticators[mechanism]) + warn("%p: replacing %p authenticator: %p" % [ self, mechanism, original], + uplevel: 1) + end + authenticators[mechanism] = authenticator end # :call-seq: