@@ -6,8 +6,6 @@ module SASL
6
6
7
7
# This API is *experimental*, and may change.
8
8
#
9
- # TODO: catch exceptions in #process and send #cancel_response.
10
- # TODO: raise an error if the command succeeds after being canceled.
11
9
# TODO: use with more clients, to verify the API can accommodate them.
12
10
#
13
11
# An AuthenticationExchange represents a single attempt to authenticate
@@ -79,6 +77,9 @@ def self.build(client, mechanism, *args, sasl_ir: true, **kwargs, &block)
79
77
80
78
attr_reader :mechanism , :authenticator
81
79
80
+ # An exception that has been raised by <tt>authenticator.process</tt>.
81
+ attr_reader :process_error
82
+
82
83
def initialize ( client , mechanism , authenticator , sasl_ir : true )
83
84
client => SASL ::ClientAdapter
84
85
@client = client
@@ -94,6 +95,7 @@ def initialize(client, mechanism, authenticator, sasl_ir: true)
94
95
# in <tt>client.response_errors</tt> will drop the connection.
95
96
def authenticate
96
97
client . run_command ( mechanism , initial_response ) { process _1 }
98
+ . tap { raise process_error if process_error }
97
99
. tap { raise AuthenticationIncomplete , _1 unless done? }
98
100
rescue AuthenticationCanceled , *client . response_errors
99
101
raise # but don't drop the connection
@@ -127,9 +129,12 @@ def initial_response
127
129
end
128
130
129
131
def process ( challenge )
130
- client . encode authenticator . process client . decode challenge
131
- ensure
132
132
@processed = true
133
+ return client . cancel_response if process_error
134
+ client . encode authenticator . process client . decode challenge
135
+ rescue => process_error
136
+ @process_error = process_error
137
+ client . cancel_response
133
138
end
134
139
135
140
end
0 commit comments