Skip to content

Commit

Permalink
Remove obsolete Authenticator implementations
Browse files Browse the repository at this point in the history
The versions from `net-imap` are more full-featured.  E.g: they support
`authzid` and print deprecation warnings for MD5 authenticators.

The tests are updated to silence deprecation warnings, which are printed
by the authenticators from `net-imap`.
  • Loading branch information
nevans committed Nov 9, 2023
1 parent 92b67d4 commit c65246a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 94 deletions.
53 changes: 0 additions & 53 deletions lib/net/smtp/auth_cram_md5.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/net/smtp/auth_login.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/net/smtp/auth_plain.rb

This file was deleted.

35 changes: 24 additions & 11 deletions test/net/smtp/test_smtp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,28 @@ def test_unsucessful_auth_plain
def test_auth_cram_md5
server = FakeServer.start(auth: 'CRAM-MD5')
smtp = Net::SMTP.start 'localhost', server.port
assert smtp.auth(:cram_md5, "account", password: "password").success?
assert smtp.auth(:cram_md5, "account", password: "password",
warn_deprecation: false).success?
end

def test_auth_login
server = FakeServer.start(auth: 'login')
smtp = Net::SMTP.start 'localhost', server.port
assert smtp.authenticate("account", "password", :login).success?
assert smtp.auth(:login, "account", "password",
warn_deprecation: false).success?

server = FakeServer.start(auth: 'login')
smtp = Net::SMTP.start 'localhost', server.port
assert smtp.auth("LOGIN", username: "account", secret: "password").success?
assert smtp.auth(username: "account", secret: "password",
type: :login, warn_deprecation: false).success?
end

def test_unsucessful_auth_login
server = FakeServer.start(auth: 'login')
smtp = Net::SMTP.start 'localhost', server.port
err = assert_raise(Net::SMTPAuthenticationError) { smtp.authenticate("foo", "bar", :login) }
err = assert_raise(Net::SMTPAuthenticationError) {
smtp.auth(:login, "foo", "bar", warn_deprecation: false)
}
assert_equal "535 5.7.8 Error: authentication failed: authentication failure\n", err.message
assert_equal "535", err.response.status
end
Expand All @@ -167,7 +172,9 @@ def server.auth(*)
@sock.puts "235 2.7.0 Authentication successful\r\n"
end
smtp = Net::SMTP.start 'localhost', server.port
err = assert_raise(Net::SMTPUnknownError) { smtp.authenticate("account", "password", :login) }
err = assert_raise(Net::SMTPUnknownError) {
smtp.auth(:login, "account", "password", warn_deprecation: false)
}
assert_equal "235 2.7.0 Authentication successful\n", err.message
assert_equal "235", err.response.status
end
Expand Down Expand Up @@ -502,33 +509,39 @@ def test_start_auth_plain

def test_start_auth_login
port = fake_server_start(auth: 'LOGIN')
Net::SMTP.start('localhost', port, user: 'account', password: 'password', authtype: :login){}
Net::SMTP.start('localhost', port, user: 'account', password: 'password',
authtype: :login, auth: {warn_deprecation: false}){}

port = fake_server_start(auth: 'LOGIN')
assert_raise Net::SMTPAuthenticationError do
Net::SMTP.start('localhost', port, user: 'account', password: 'invalid', authtype: :login){}
Net::SMTP.start('localhost', port, user: 'account', password: 'invalid',
authtype: :login, auth: {warn_deprecation: false}){}
end

port = fake_server_start(auth: 'PLAIN')
assert_raise Net::SMTPAuthenticationError do
Net::SMTP.start('localhost', port, user: 'account', password: 'password', authtype: :login){}
Net::SMTP.start('localhost', port, user: 'account', password: 'password',
authtype: :login, auth: {warn_deprecation: false}){}
end
end

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", auth: {warn_deprecation: false}){}

port = fake_server_start(auth: 'CRAM-MD5')
assert_raise Net::SMTPAuthenticationError do
Net::SMTP.start('localhost', port, user: 'account', password: 'invalid', authtype: :cram_md5){}
Net::SMTP.start('localhost', port, user: 'account', password: 'invalid',
authtype: :cram_md5, auth: {warn_deprecation: false}){}
end

port = fake_server_start(auth: 'PLAIN')
assert_raise Net::SMTPAuthenticationError do
Net::SMTP.start('localhost', port, user: 'account', password: 'password', authtype: :cram_md5){}
Net::SMTP.start('localhost', port, user: 'account', password: 'password',
authtype: :cram_md5, auth: {warn_deprecation: false}){}
end
end

Expand Down

0 comments on commit c65246a

Please sign in to comment.