@@ -326,37 +326,53 @@ def cred_json_text_with_universe_domain missing = nil
326326 end
327327
328328 describe "when revoking a refresh token" do
329+ let ( :response_body ) { "{}" }
329330 let :stub do
330331 stub_request ( :post , "https://oauth2.googleapis.com/revoke" )
331332 . with ( body : hash_including ( "token" => "refreshtoken" ) )
332333 . to_return ( status : 200 ,
334+ body : response_body ,
333335 headers : { "Content-Type" => "application/json" } )
334336 end
335337
336338 before :example do
337339 stub
338- @client . revoke!
340+ @result = @ client. revoke!
339341 end
340342
341343 it_behaves_like "revoked token"
344+
345+ # The return value is passed through retry_with_error's logging pipeline,
346+ # which expects a JSON-parseable string.
347+ it "returns the response body" do
348+ expect ( @result ) . to eq ( response_body )
349+ end
342350 end
343351
344352 describe "when revoking an access token" do
353+ let ( :response_body ) { "{}" }
345354 let :stub do
346355 stub_request ( :post , "https://oauth2.googleapis.com/revoke" )
347356 . with ( body : hash_including ( "token" => "accesstoken" ) )
348357 . to_return ( status : 200 ,
358+ body : response_body ,
349359 headers : { "Content-Type" => "application/json" } )
350360 end
351361
352362 before :example do
353363 stub
354364 @client . refresh_token = nil
355365 @client . access_token = "accesstoken"
356- @client . revoke!
366+ @result = @ client. revoke!
357367 end
358368
359369 it_behaves_like "revoked token"
370+
371+ # The return value is passed through retry_with_error's logging pipeline,
372+ # which expects a JSON-parseable string.
373+ it "returns the response body" do
374+ expect ( @result ) . to eq ( response_body )
375+ end
360376 end
361377
362378 describe "when revoking an invalid token" do
@@ -378,17 +394,54 @@ def cred_json_text_with_universe_domain missing = nil
378394 end
379395 end
380396
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+
381432 describe "when errors occurred with request" do
382433 it "should fail with Signet::AuthorizationError if request times out" do
383434 allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post )
384435 . and_raise ( Faraday ::TimeoutError )
436+ expect ( @client ) . to receive ( :sleep ) . exactly ( 5 ) . times . with ( kind_of ( Numeric ) )
385437 expect { @client . revoke! }
386438 . to raise_error Signet ::AuthorizationError
387439 end
388440
389441 it "should fail with Signet::AuthorizationError if request fails" do
390442 allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post )
391443 . and_raise ( Faraday ::ConnectionFailed , nil )
444+ expect ( @client ) . to receive ( :sleep ) . exactly ( 5 ) . times . with ( kind_of ( Numeric ) )
392445 expect { @client . revoke! }
393446 . to raise_error Signet ::AuthorizationError
394447 end
0 commit comments