Ejemplo n.º 1
0
 public function testGetAccessTokenScopes()
 {
     $req = new \google\appengine\GetAccessTokenRequest();
     $scope1 = 'mail.google.com/send';
     $scope2 = 'google.cloud.scope/foo';
     $req->addScope($scope1);
     $req->addScope($scope2);
     $resp = new \google\appengine\GetAccessTokenResponse();
     $resp->setAccessToken('foo token');
     $resp->setExpirationTime(12345);
     $this->apiProxyMock->expectCall('app_identity_service', 'GetAccessToken', $req, $resp);
     $result = AppIdentityService::getAccessToken([$scope1, $scope2]);
     $this->assertEquals($result['access_token'], 'foo token');
     $this->assertEquals($result['expiration_time'], 12345);
     $this->apiProxyMock->verify();
 }
Ejemplo n.º 2
0
 private function expectGetAccessTokenRequest($scopes, $cached, $exception = null)
 {
     $req = new \google\appengine\MemcacheGetRequest();
     $memcache_key = AppIdentityService::MEMCACHE_KEY_PREFIX . AppIdentityService::DOMAIN_SEPARATOR . implode(AppIdentityService::DOMAIN_SEPARATOR, $scopes);
     $req->addKey($memcache_key);
     $resp = new \google\appengine\MemcacheGetResponse();
     if ($cached) {
         $item = $resp->addItem();
         $item->setKey($memcache_key);
         $item->setValue(serialize(['access_token' => 'foo token', 'expiration_time' => 12345]));
         $item->setFlags(\google\appengine\runtime\MemcacheUtils::TYPE_PHP_SERIALIZED);
     }
     $this->apiProxyMock->expectCall('memcache', 'Get', $req, $resp);
     if ($cached) {
         return;
     }
     $req = new \google\appengine\GetAccessTokenRequest();
     foreach ($scopes as $scope) {
         $req->addScope($scope);
     }
     if (is_null($exception)) {
         $resp = new \google\appengine\GetAccessTokenResponse();
         $resp->setAccessToken('foo token');
         $resp->setExpirationTime(12345);
     } else {
         $resp = $exception;
     }
     $this->apiProxyMock->expectCall('app_identity_service', 'GetAccessToken', $req, $resp);
     if (!is_null($exception)) {
         return;
     }
     $req = new \google\appengine\MemcacheSetRequest();
     $item = $req->addItem();
     $item->setKey($memcache_key);
     $item->setValue(serialize(['access_token' => $resp->getAccessToken(), 'expiration_time' => $resp->getExpirationTime()]));
     $item->setExpirationTime($resp->getExpirationTime() - AppIdentityService::EXPIRY_SAFETY_MARGIN_SECS - AppIdentityService::EXPIRY_SHORT_MARGIN_SECS);
     $item->setFlags(\google\appengine\runtime\MemcacheUtils::TYPE_PHP_SERIALIZED);
     $item->setSetPolicy(1);
     // Add
     $resp = new \google\appengine\MemcacheSetResponse();
     $resp->addSetStatus(1);
     // Stored
     $this->apiProxyMock->expectCall('memcache', 'Set', $req, $resp);
 }