Skip to content

Commit

Permalink
🥅 Add SASL::AuthenticationIncomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Sep 29, 2023
1 parent 74e4687 commit 80c6e96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
end
if authenticator.respond_to?(:done?) && !authenticator.done?
logout!
raise SASL::AuthenticationFailed, "authentication ended prematurely"
raise SASL::AuthenticationIncomplete, result
end
@capabilities = capabilities_from_resp_code result
result
Expand Down
12 changes: 12 additions & 0 deletions lib/net/imap/sasl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ module SASL
# messages has not passed integrity checks.
AuthenticationFailed = Class.new(Error)

# Indicates that authentication cannot proceed because one of the server's
# ended authentication prematurely.
class AuthenticationIncomplete < AuthenticationFailed
# The success response from the server
attr_reader :response

def initialize(response, message = "authentication ended prematurely")
super(message)
@response = response
end
end

# autoloading to avoid loading all of the regexps when they aren't used.
sasl_stringprep_rb = File.expand_path("sasl/stringprep", __dir__)
autoload :StringPrep, sasl_stringprep_rb
Expand Down
2 changes: 1 addition & 1 deletion test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def test_id
server.state.authenticate(server.config.user)
cmd.done_ok
end
assert_raise(Net::IMAP::SASL::AuthenticationFailed) do
assert_raise(Net::IMAP::SASL::AuthenticationIncomplete) do
imap.authenticate("DIGEST-MD5", "test_user", "test-password",
warn_deprecation: false)
end
Expand Down

0 comments on commit 80c6e96

Please sign in to comment.