Skip to content

Commit

Permalink
Silence deprecation warnings in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Oct 11, 2023
1 parent dfebf5e commit b310bd9
Showing 1 changed file with 24 additions and 11 deletions.
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 b310bd9

Please sign in to comment.