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
6363 :replica_set_name ,
6464 :secondary? ,
6565 :standalone? ,
66- :unknown?
66+ :unknown? ,
67+ :unknown!
6768
6869 # Is this server equal to another?
6970 #
@@ -229,5 +230,24 @@ def reconnect!
229230 def with_connection ( &block )
230231 pool . with_connection ( &block )
231232 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
232252 end
233253end
Original file line number Diff line number Diff line change @@ -162,7 +162,9 @@ def deliver(messages)
162162 def authenticate!
163163 if options [ :user ]
164164 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
166168 end
167169 end
168170
Original file line number Diff line number Diff line change 130130 end
131131
132132 it 'marks the server as unknown' do
133- pending 'Server must be set as unknown'
134133 expect ( server ) . to be_unknown
135134 end
136135 end
You can’t perform that action at this time.
0 commit comments