From 44f3c79eadcf58784c2c506e39abc44bcbf6e059 Mon Sep 17 00:00:00 2001 From: nicholas evans Date: Sun, 1 Oct 2023 18:53:02 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20authenticate=20using=20Sym?= =?UTF-8?q?bol=20mechanism=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on `net-smtp`, I had added the ability to use symbols to lookup authenticator. But it had two issues: 1) dealing with dashes vs underscores, and 2) sending the mechanism name using flag syntax. This fixes both issues. --- lib/net/imap.rb | 1 + test/net/imap/test_imap.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 69fdc3f1..63fcfd09 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -1248,6 +1248,7 @@ def starttls(**options) # completes. If the TaggedResponse to #authenticate includes updated # capabilities, they will be cached. def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback) + mechanism = mechanism.to_s.tr("_", "-").upcase authenticator = SASL.authenticator(mechanism, *creds, **props, &callback) cmdargs = ["AUTHENTICATE", mechanism] if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) && diff --git a/test/net/imap/test_imap.rb b/test/net/imap/test_imap.rb index 03700447..8981d3a4 100644 --- a/test/net/imap/test_imap.rb +++ b/test/net/imap/test_imap.rb @@ -934,7 +934,7 @@ def test_id server.state.authenticate(server.config.user) cmd.done_ok end - imap.authenticate("DIGEST-MD5", "test_user", "test-password", + imap.authenticate(:digest_md5, "test_user", "test-password", warn_deprecation: false) cmd, cont1, cont2 = 3.times.map { server.commands.pop } assert_equal %w[AUTHENTICATE DIGEST-MD5], [cmd.name, *cmd.args]