File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,8 @@ class Server
63
63
:replica_set_name ,
64
64
:secondary? ,
65
65
:standalone? ,
66
- :unknown?
66
+ :unknown? ,
67
+ :unknown!
67
68
68
69
# Is this server equal to another?
69
70
#
@@ -229,5 +230,24 @@ def reconnect!
229
230
def with_connection ( &block )
230
231
pool . with_connection ( &block )
231
232
end
233
+
234
+ # Handle authentication failure.
235
+ #
236
+ # @example Handle possible authentication failure.
237
+ # server.handle_auth_failure! do
238
+ # Auth.get(user).login(self)
239
+ # end
240
+ #
241
+ # @raise [ Auth::Unauthorized ] If the authentication failed.
242
+ #
243
+ # @return [ Object ] The result of the block execution.
244
+ #
245
+ # @since 2.3.0
246
+ def handle_auth_failure!
247
+ yield
248
+ rescue Auth ::Unauthorized
249
+ unknown!
250
+ raise
251
+ end
232
252
end
233
253
end
Original file line number Diff line number Diff line change @@ -162,7 +162,9 @@ def deliver(messages)
162
162
def authenticate!
163
163
if options [ :user ]
164
164
user = Auth ::User . new ( Options ::Redacted . new ( :auth_mech => default_mechanism ) . merge ( options ) )
165
- Auth . get ( user ) . login ( self )
165
+ @server . handle_auth_failure! do
166
+ Auth . get ( user ) . login ( self )
167
+ end
166
168
end
167
169
end
168
170
Original file line number Diff line number Diff line change 130
130
end
131
131
132
132
it 'marks the server as unknown' do
133
- pending 'Server must be set as unknown'
134
133
expect ( server ) . to be_unknown
135
134
end
136
135
end
You can’t perform that action at this time.
0 commit comments