@@ -394,17 +394,54 @@ def cred_json_text_with_universe_domain missing = nil
394394 end
395395 end
396396
397+ describe "logging during revoke" do
398+ let ( :response_body ) { '{"foo": "bar"}' }
399+ let :stub do
400+ stub_request ( :post , "https://oauth2.googleapis.com/revoke" )
401+ . with ( body : hash_including ( "token" => "refreshtoken" ) )
402+ . to_return ( status : 200 ,
403+ body : response_body ,
404+ headers : { "Content-Type" => "application/json" } )
405+ end
406+
407+ it "logs the response body" do
408+ stub
409+ strio = StringIO . new
410+ logger = Logger . new strio
411+ logger . level = Logger ::DEBUG
412+ @client . logger = logger
413+ @client . revoke!
414+ expect ( strio . string ) . to include ( "Received auth token response" )
415+ end
416+
417+ it "logs transient errors when they occur" do
418+ allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post ) . and_raise ( Faraday ::TimeoutError )
419+ strio = StringIO . new
420+ logger = Logger . new strio
421+ @client . logger = logger
422+
423+ # Stub sleep to avoid slow tests
424+ allow ( @client ) . to receive ( :sleep )
425+
426+ expect { @client . revoke! } . to raise_error Signet ::AuthorizationError
427+ expect ( strio . string ) . to include ( "Transient error when fetching auth token" )
428+ expect ( strio . string ) . to include ( "Exhausted retries when fetching auth token" )
429+ end
430+ end
431+
397432 describe "when errors occurred with request" do
398433 it "should fail with Signet::AuthorizationError if request times out" do
399434 allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post )
400435 . and_raise ( Faraday ::TimeoutError )
436+ expect ( @client ) . to receive ( :sleep ) . exactly ( 5 ) . times . with ( kind_of ( Numeric ) )
401437 expect { @client . revoke! }
402438 . to raise_error Signet ::AuthorizationError
403439 end
404440
405441 it "should fail with Signet::AuthorizationError if request fails" do
406442 allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post )
407443 . and_raise ( Faraday ::ConnectionFailed , nil )
444+ expect ( @client ) . to receive ( :sleep ) . exactly ( 5 ) . times . with ( kind_of ( Numeric ) )
408445 expect { @client . revoke! }
409446 . to raise_error Signet ::AuthorizationError
410447 end
0 commit comments