ComputeEngineAuthTest

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Defined (1)

The class is defined in the following location(s).

/vendor/google/apiclient/tests/general/ComputeEngineAuthTest.php  
  1. class ComputeEngineAuthTest extends BaseTest 
  2. public function testTokenAcquisition() 
  3. $client = new Google_Client(); 
  4.  
  5. /** Mock out refresh call */ 
  6. $response_data = json_encode( 
  7. array( 
  8. 'access_token' => "ACCESS_TOKEN",  
  9. 'expires_in' => "12345" 
  10. ); 
  11. $response = $this->getMock("Google_Http_Request", array(), array('')); 
  12. $response->expects($this->any()) 
  13. ->method('getResponseHttpCode') 
  14. ->will($this->returnValue(200)); 
  15. $response->expects($this->any()) 
  16. ->method('getResponseBody') 
  17. ->will($this->returnValue($response_data)); 
  18. $io = $this->getMock("Google_IO_Stream", array(), array($client)); 
  19. $client->setIo($io);$io->expects($this->any()) 
  20. ->method('makeRequest') 
  21. ->will( 
  22. $this->returnCallback( 
  23. function ($request) use ($response) { 
  24. return $response; 
  25. ); 
  26.  
  27. /** Run method */ 
  28. $oauth = new Google_Auth_ComputeEngine($client); 
  29. $oauth->acquireAccessToken(); 
  30. $token = json_decode($oauth->getAccessToken(), true); 
  31.  
  32. /** Check results */ 
  33. $this->assertEquals($token['access_token'], "ACCESS_TOKEN"); 
  34. $this->assertEquals($token['expires_in'], "12345"); 
  35. $this->assertTrue($token['created'] > 0); 
  36.  
  37. public function testSign() 
  38. $client = new Google_Client(); 
  39. $oauth = new Google_Auth_ComputeEngine($client); 
  40.  
  41. /** Load mock access token */ 
  42. $oauth->setAccessToken( 
  43. json_encode( 
  44. array( 
  45. 'access_token' => "ACCESS_TOKEN",  
  46. 'expires_in' => "12345" 
  47. ); 
  48.  
  49. /** Sign a URL and verify auth header is correctly set */ 
  50. $req = new Google_Http_Request('http://localhost'); 
  51. $req = $oauth->sign($req); 
  52. $auth = $req->getRequestHeader('authorization'); 
  53. $this->assertEquals('Bearer ACCESS_TOKEN', $auth);