From a08d6dc1331fce1e7b0e784e28826f19cec2d001 Mon Sep 17 00:00:00 2001 From: nick evans Date: Mon, 9 Oct 2023 13:20:12 -0400 Subject: [PATCH] Allow case-insensitive strings for SASL mechanism In particular, this erases the difference between :scram_sha_256 (the Net::SMTP authtype) and "SCRAM-SHA-256" (the SASL mechanism). --- lib/net/smtp/authenticator.rb | 4 +++- test/net/smtp/test_smtp.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/net/smtp/authenticator.rb b/lib/net/smtp/authenticator.rb index 75350f0..756bfa9 100644 --- a/lib/net/smtp/authenticator.rb +++ b/lib/net/smtp/authenticator.rb @@ -6,11 +6,13 @@ def self.auth_classes end def self.auth_type(type) + type = type.to_s.upcase.tr(?_, ?-).to_sym Authenticator.auth_classes[type] = self end def self.auth_class(type) - Authenticator.auth_classes[type.intern] + type = type.to_s.upcase.tr(?_, ?-).to_sym + Authenticator.auth_classes[type] end attr_reader :smtp diff --git a/test/net/smtp/test_smtp.rb b/test/net/smtp/test_smtp.rb index 4467e7b..85bc1bc 100644 --- a/test/net/smtp/test_smtp.rb +++ b/test/net/smtp/test_smtp.rb @@ -485,7 +485,7 @@ def test_start_auth_cram_md5 omit "openssl or digest library not loaded" unless defined? OpenSSL or defined? Digest port = fake_server_start(auth: 'CRAM-MD5') - Net::SMTP.start('localhost', port, user: 'account', password: 'password', authtype: :cram_md5){} + Net::SMTP.start('localhost', port, user: 'account', password: 'password', authtype: "CRAM-MD5"){} port = fake_server_start(auth: 'CRAM-MD5') assert_raise Net::SMTPAuthenticationError do