Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Google\Tests; use Google\Client; use Google\Service\Drive; use Google\Aut..
Decoded Output download
<?php
namespace Google\Tests; use Google\Client; use Google\Service\Drive; use Google\AuthHandler\AuthHandlerFactory; use Google\Auth\FetchAuthTokenCache; use Google\Auth\GCECache; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Exception\ClientException; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use ReflectionClass; use ReflectionMethod; use InvalidArgumentException; use Exception; class ClientTest extends BaseTest { public function testClientConstructor() { $this->assertInstanceOf(Client::class, $this->getClient()); } public function testSignAppKey() { $client = $this->getClient(); $client->setDeveloperKey("devKey"); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "Simple"); } private function checkAuthHandler($http, $className) { $stack = $http->getConfig("handler"); $class = new ReflectionClass(get_class($stack)); $property = $class->getProperty("stack"); $property->setAccessible(true); $middlewares = $property->getValue($stack); $middleware = array_pop($middlewares); if (null === $className) { $this->assertCount(3, $middlewares); } else { $authClass = sprintf("Google\Auth\Middleware\%sMiddleware", $className); $this->assertInstanceOf($authClass, $middleware[0]); } } private function checkCredentials($http, $fetcherClass, $sub = null) { $stack = $http->getConfig("handler"); $class = new ReflectionClass(get_class($stack)); $property = $class->getProperty("stack"); $property->setAccessible(true); $middlewares = $property->getValue($stack); $middleware = array_pop($middlewares); $auth = $middleware[0]; $class = new ReflectionClass(get_class($auth)); $property = $class->getProperty("fetcher"); $property->setAccessible(true); $cacheFetcher = $property->getValue($auth); $this->assertInstanceOf(FetchAuthTokenCache::class, $cacheFetcher); $class = new ReflectionClass(get_class($cacheFetcher)); $property = $class->getProperty("fetcher"); $property->setAccessible(true); $fetcher = $property->getValue($cacheFetcher); $this->assertInstanceOf($fetcherClass, $fetcher); if ($sub) { $class = new ReflectionClass(get_class($fetcher)); $property = $class->getProperty("auth"); $property->setAccessible(true); $auth = $property->getValue($fetcher); $this->assertEquals($sub, $auth->getSub()); } } public function testSignAccessToken() { $client = $this->getClient(); $http = new GuzzleClient(); $client->setAccessToken(array("access_token" => "test_token", "expires_in" => 3600, "created" => time())); $client->setScopes("test_scope"); $client->authorize($http); $this->checkAuthHandler($http, "ScopedAccessToken"); } public function testCreateAuthUrl() { $client = $this->getClient(); $client->setClientId("clientId1"); $client->setClientSecret("clientSecret1"); $client->setRedirectUri("http://localhost"); $client->setDeveloperKey("devKey"); $client->setState("xyz"); $client->setAccessType("offline"); $client->setApprovalPrompt("force"); $client->setRequestVisibleActions("http://foo"); $client->setLoginHint("[email protected]"); $authUrl = $client->createAuthUrl("http://googleapis.com/scope/foo"); $expected = "https://accounts.google.com/o/oauth2/v2/auth" . "?response_type=code" . "&access_type=offline" . "&client_id=clientId1" . "&redirect_uri=http%3A%2F%2Flocalhost" . "&state=xyz" . "&scope=http%3A%2F%2Fgoogleapis.com%2Fscope%2Ffoo" . "&approval_prompt=force" . "&login_hint=bob%40example.org"; $this->assertEquals($expected, $authUrl); $client->setLoginHint(''); $client->setHostedDomain("example.com"); $client->setOpenIdRealm("example.com"); $client->setPrompt("select_account"); $client->setIncludeGrantedScopes(true); $authUrl = $client->createAuthUrl("http://googleapis.com/scope/foo"); $expected = "https://accounts.google.com/o/oauth2/v2/auth" . "?response_type=code" . "&access_type=offline" . "&client_id=clientId1" . "&redirect_uri=http%3A%2F%2Flocalhost" . "&state=xyz" . "&scope=http%3A%2F%2Fgoogleapis.com%2Fscope%2Ffoo" . "&hd=example.com" . "&include_granted_scopes=true" . "&openid.realm=example.com" . "&prompt=select_account"; $this->assertEquals($expected, $authUrl); } public function testPrepareNoScopes() { $client = new Client(); $scopes = $client->prepareScopes(); $this->assertNull($scopes); } public function testNoAuthIsNull() { $client = new Client(); $this->assertNull($client->getAccessToken()); } public function testPrepareService() { $client = new Client(); $client->setScopes(array("scope1", "scope2")); $scopes = $client->prepareScopes(); $this->assertEquals("scope1 scope2", $scopes); $client->setScopes(array('', "scope2")); $scopes = $client->prepareScopes(); $this->assertEquals(" scope2", $scopes); $client->setScopes("scope2"); $client->addScope("scope3"); $client->addScope(array("scope4", "scope5")); $scopes = $client->prepareScopes(); $this->assertEquals("scope2 scope3 scope4 scope5", $scopes); $client->setClientId("test1"); $client->setRedirectUri("http://localhost/"); $client->setState("xyz"); $client->setScopes(array("http://test.com", "scope2")); $scopes = $client->prepareScopes(); $this->assertEquals("http://test.com scope2", $scopes); $this->assertEquals('' . "https://accounts.google.com/o/oauth2/v2/auth" . "?response_type=code" . "&access_type=online" . "&client_id=test1" . "&redirect_uri=http%3A%2F%2Flocalhost%2F" . "&state=xyz" . "&scope=http%3A%2F%2Ftest.com%20scope2" . "&approval_prompt=auto", $client->createAuthUrl()); $stream = $this->prophesize("GuzzleHttp\Psr7\Stream"); $stream->__toString()->willReturn(''); $response = $this->prophesize("Psr\Http\Message\ResponseInterface"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($stream->reveal()); $response->getStatusCode()->willReturn(200); $http = $this->prophesize("GuzzleHttp\ClientInterface"); $http->send(Argument::type("Psr\Http\Message\RequestInterface"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client->setHttpClient($http->reveal()); $dr_service = new Drive($client); $this->assertInstanceOf("Google\Model", $dr_service->files->listFiles()); } public function testDefaultLogger() { $client = new Client(); $logger = $client->getLogger(); $this->assertInstanceOf("Monolog\Logger", $logger); $handler = $logger->popHandler(); $this->assertInstanceOf("Monolog\Handler\StreamHandler", $handler); } public function testDefaultLoggerAppEngine() { $_SERVER["SERVER_SOFTWARE"] = "Google App Engine"; $client = new Client(); $logger = $client->getLogger(); $handler = $logger->popHandler(); unset($_SERVER["SERVER_SOFTWARE"]); $this->assertInstanceOf("Monolog\Logger", $logger); $this->assertInstanceOf("Monolog\Handler\SyslogHandler", $handler); } public function testSettersGetters() { $client = new Client(); $client->setClientId("client1"); $client->setClientSecret("client1secret"); $client->setState("1"); $client->setApprovalPrompt("force"); $client->setAccessType("offline"); $client->setRedirectUri("localhost"); $client->setConfig("application_name", "me"); $cache = $this->prophesize(CacheItemPoolInterface::class); $client->setCache($cache->reveal()); $this->assertInstanceOf(CacheItemPoolInterface::class, $client->getCache()); try { $client->setAccessToken(null); $this->fail("Should have thrown an Exception."); } catch (InvalidArgumentException $e) { $this->assertEquals("invalid json token", $e->getMessage()); } $token = array("access_token" => "token"); $client->setAccessToken($token); $this->assertEquals($token, $client->getAccessToken()); } public function testSetAccessTokenValidation() { $client = new Client(); $client->setAccessToken(array("access_token" => "token", "created" => time())); self::assertEquals(true, $client->isAccessTokenExpired()); } public function testDefaultConfigOptions() { $client = new Client(); $this->assertArrayHasKey("http_errors", $client->getHttpClient()->getConfig()); $this->assertArrayNotHasKey("exceptions", $client->getHttpClient()->getConfig()); $this->assertFalse($client->getHttpClient()->getConfig()["http_errors"]); } public function testJsonConfig() { $client = new Client(); $device = "{"installed":{"auth_uri":"https://accounts.google.com/o/oauth2/v2/auth","client_secret"" . ":"N0aHCBT1qX1VAcF5J1pJAn6S","token_uri":"https://oauth2.googleapis.com/token"," . ""client_email":"","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","oob"],"client_x509_cert_url"" . ":"","client_id":"123456789.apps.googleusercontent.com","auth_provider_x509_cert_url":" . ""https://www.googleapis.com/oauth2/v1/certs"}}"; $dObj = json_decode($device, true); $client->setAuthConfig($dObj); $this->assertEquals($client->getClientId(), $dObj["installed"]["client_id"]); $this->assertEquals($client->getClientSecret(), $dObj["installed"]["client_secret"]); $this->assertEquals($client->getRedirectUri(), $dObj["installed"]["redirect_uris"][0]); $client = new Client(); $web = "{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/v2/auth","client_secret"" . ":"lpoubuib8bj-Fmke_YhhyHGgXc","token_uri":"https://oauth2.googleapis.com/token"" . ","client_email":"[email protected]","client_x509_cert_url":" . ""https://www.googleapis.com/robot/v1/metadata/x509/[email protected]"" . ","client_id":"123456789.apps.googleusercontent.com","auth_provider_x509_cert_url":" . ""https://www.googleapis.com/oauth2/v1/certs"}}"; $wObj = json_decode($web, true); $client->setAuthConfig($wObj); $this->assertEquals($client->getClientId(), $wObj["web"]["client_id"]); $this->assertEquals($client->getClientSecret(), $wObj["web"]["client_secret"]); $this->assertEquals($client->getRedirectUri(), ''); } public function testIniConfig() { $config = parse_ini_file(__DIR__ . "/../config/test.ini"); $client = new Client($config); $this->assertEquals("My Test application", $client->getConfig("application_name")); $this->assertEquals("gjfiwnGinpena3", $client->getClientSecret()); } public function testNoAuth() { $client = new Client(); $client->setDeveloperKey(null); $GOOGLE_APPLICATION_CREDENTIALS = getenv("GOOGLE_APPLICATION_CREDENTIALS"); $HOME = getenv("HOME"); putenv("GOOGLE_APPLICATION_CREDENTIALS="); putenv("HOME=" . sys_get_temp_dir()); $http = new GuzzleClient(); $client->authorize($http); putenv("GOOGLE_APPLICATION_CREDENTIALS={$GOOGLE_APPLICATION_CREDENTIALS}"); putenv("HOME={$HOME}"); $this->checkAuthHandler($http, null); } public function testApplicationDefaultCredentials() { $this->checkServiceAccountCredentials(); $credentialsFile = getenv("GOOGLE_APPLICATION_CREDENTIALS"); $client = new Client(); $client->setAuthConfig($credentialsFile); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "AuthToken"); $this->checkCredentials($http, "Google\Auth\Credentials\ServiceAccountCredentials"); } public function testApplicationDefaultCredentialsWithSubject() { $this->checkServiceAccountCredentials(); $credentialsFile = getenv("GOOGLE_APPLICATION_CREDENTIALS"); $sub = "sub123"; $client = new Client(); $client->setAuthConfig($credentialsFile); $client->setSubject($sub); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "AuthToken"); $this->checkCredentials($http, "Google\Auth\Credentials\ServiceAccountCredentials", $sub); } public function testRefreshTokenSetsValues() { $token = json_encode(array("access_token" => "xyz", "id_token" => "ID_TOKEN")); $postBody = $this->prophesize("GuzzleHttp\Psr7\Stream"); $postBody->__toString()->shouldBeCalledTimes(1)->willReturn($token); $response = $this->prophesize("Psr\Http\Message\ResponseInterface"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($postBody->reveal()); $response->hasHeader("Content-Type")->willReturn(false); $http = $this->prophesize("GuzzleHttp\ClientInterface"); $http->send(Argument::type("Psr\Http\Message\RequestInterface"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken("REFRESH_TOKEN"); $token = $client->getAccessToken(); $this->assertEquals("ID_TOKEN", $token["id_token"]); } public function testRefreshTokenIsSetOnRefresh() { $refreshToken = "REFRESH_TOKEN"; $token = json_encode(array("access_token" => "xyz", "id_token" => "ID_TOKEN")); $postBody = $this->prophesize("Psr\Http\Message\StreamInterface"); $postBody->__toString()->shouldBeCalledTimes(1)->willReturn($token); $response = $this->prophesize("Psr\Http\Message\ResponseInterface"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($postBody->reveal()); $response->hasHeader("Content-Type")->willReturn(false); $http = $this->prophesize("GuzzleHttp\ClientInterface"); $http->send(Argument::type("Psr\Http\Message\RequestInterface"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken($refreshToken); $token = $client->getAccessToken(); $this->assertEquals($refreshToken, $token["refresh_token"]); } public function testRefreshTokenIsNotSetWhenNewRefreshTokenIsReturned() { $refreshToken = "REFRESH_TOKEN"; $token = json_encode(array("access_token" => "xyz", "id_token" => "ID_TOKEN", "refresh_token" => "NEW_REFRESH_TOKEN")); $postBody = $this->prophesize("GuzzleHttp\Psr7\Stream"); $postBody->__toString()->wilLReturn($token); $response = $this->prophesize("Psr\Http\Message\ResponseInterface"); $response->getBody()->willReturn($postBody->reveal()); $response->hasHeader("Content-Type")->willReturn(false); $http = $this->prophesize("GuzzleHttp\ClientInterface"); $http->send(Argument::type("Psr\Http\Message\RequestInterface"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken($refreshToken); $token = $client->getAccessToken(); $this->assertEquals("NEW_REFRESH_TOKEN", $token["refresh_token"]); } public function testFetchAccessTokenWithAssertionFromEnv() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("access_token", $token); } public function testFetchAccessTokenWithAssertionFromFile() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->setAuthConfig(getenv("GOOGLE_APPLICATION_CREDENTIALS")); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("access_token", $token); } public function testFetchAccessTokenWithAssertionAddsCreated() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("created", $token); } public function testBadSubjectThrowsException() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $client->setSubject("bad-subject"); $authHandler = AuthHandlerFactory::build(); $method = new ReflectionMethod($authHandler, "createAuthHttp"); $method->setAccessible(true); $authHttp = $method->invoke($authHandler, $client->getHttpClient()); try { $token = $client->fetchAccessTokenWithAssertion($authHttp); $this->fail("no exception thrown"); } catch (ClientException $e) { $response = $e->getResponse(); $this->assertContains("Invalid impersonation", (string) $response->getBody()); } } public function testTokenCallback() { $this->checkToken(); $client = $this->getClient(); $accessToken = $client->getAccessToken(); if (!isset($accessToken["refresh_token"])) { $this->markTestSkipped("Refresh Token required"); } $accessToken["expires_in"] = 0; $cache = $client->getCache(); $path = sys_get_temp_dir() . "/google-api-php-client-tests-" . time(); $client->setCache($this->getCache($path)); $client->setAccessToken($accessToken); $phpunit = $this; $called = false; $callback = function ($key, $value) use($client, $cache, $phpunit, &$called) { $phpunit->assertNotNull($key); $phpunit->assertNotNull($value); $called = true; $client->setCache($cache); }; $client->setTokenCallback($callback); $http = $client->authorize(); try { $http->get("https://www.googleapis.com/books/v1/volumes?q=Voltaire"); } catch (Exception $e) { } $newToken = $client->getAccessToken(); $client->setCache($cache); $this->assertTrue($called); } public function testDefaultTokenCallback() { $this->checkToken(); $client = $this->getClient(); $accessToken = $client->getAccessToken(); if (!isset($accessToken["refresh_token"])) { $this->markTestSkipped("Refresh Token required"); } $accessToken["expires_in"] = 0; $client->setAccessToken($accessToken); $http = $client->authorize(); try { $http->get("https://www.googleapis.com/books/v1/volumes?q=Voltaire"); } catch (Exception $e) { } $newToken = $client->getAccessToken(); $this->assertNotEquals($accessToken["access_token"], $newToken["access_token"]); $this->assertFalse($client->isAccessTokenExpired()); } public function testOnGceCacheAndCacheOptions() { if (!class_exists(GCECache::class)) { $this->markTestSkipped("Requires google/auth >= 1.12"); } putenv("HOME="); putenv("GOOGLE_APPLICATION_CREDENTIALS="); $prefix = "test_prefix_"; $cacheConfig = array("gce_prefix" => $prefix); $mockCacheItem = $this->prophesize(CacheItemInterface::class); $mockCacheItem->isHit()->willReturn(true); $mockCacheItem->get()->shouldBeCalledTimes(1)->willReturn(true); $mockCache = $this->prophesize(CacheItemPoolInterface::class); $mockCache->getItem($prefix . GCECache::GCE_CACHE_KEY)->shouldBeCalledTimes(1)->willReturn($mockCacheItem->reveal()); $client = new Client(array("cache_config" => $cacheConfig)); $client->setCache($mockCache->reveal()); $client->useApplicationDefaultCredentials(); $client->authorize(); } public function testFetchAccessTokenWithAssertionCache() { $this->checkServiceAccountCredentials(); $cachedValue = array("access_token" => "2/abcdef1234567890"); $mockCacheItem = $this->prophesize(CacheItemInterface::class); $mockCacheItem->isHit()->shouldBeCalledTimes(1)->willReturn(true); $mockCacheItem->get()->shouldBeCalledTimes(1)->willReturn($cachedValue); $mockCache = $this->prophesize(CacheItemPoolInterface::class); $mockCache->getItem(Argument::any())->shouldBeCalledTimes(1)->willReturn($mockCacheItem->reveal()); $client = new Client(); $client->setCache($mockCache->reveal()); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertArrayHasKey("access_token", $token); $this->assertEquals($cachedValue["access_token"], $token["access_token"]); } public function testCacheClientOption() { $mockCache = $this->prophesize(CacheItemPoolInterface::class); $client = new Client(array("cache" => $mockCache->reveal())); $this->assertEquals($mockCache->reveal(), $client->getCache()); } public function testExecuteWithFormat() { $client = new Client(array("api_format_v2" => true)); $guzzle = $this->prophesize("GuzzleHttp\Client"); $guzzle->send(Argument::allOf(Argument::type("Psr\Http\Message\RequestInterface"), Argument::that(function (RequestInterface $request) { return $request->getHeaderLine("X-GOOG-API-FORMAT-VERSION") === "2"; })), array())->shouldBeCalled()->willReturn(new Response(200, array(), null)); $client->setHttpClient($guzzle->reveal()); $request = new Request("POST", "http://foo.bar/"); $client->execute($request); } public function testExecuteSetsCorrectHeaders() { $client = new Client(); $guzzle = $this->prophesize("GuzzleHttp\Client"); $guzzle->send(Argument::that(function (RequestInterface $request) { $userAgent = sprintf("%s%s", Client::USER_AGENT_SUFFIX, Client::LIBVER); $xGoogApiClient = sprintf("gl-php/%s gdcl/%s", phpversion(), Client::LIBVER); if ($request->getHeaderLine("User-Agent") !== $userAgent) { return false; } if ($request->getHeaderLine("x-goog-api-client") !== $xGoogApiClient) { return false; } return true; }), array())->shouldBeCalledTimes(1)->willReturn(new Response(200, array(), null)); $client->setHttpClient($guzzle->reveal()); $request = new Request("POST", "http://foo.bar/"); $client->execute($request); } public function testClientOptions() { $tmpCreds = array("type" => "service_account", "client_id" => "foo", "client_email" => '', "private_key" => ''); $tmpCredFile = tempnam(sys_get_temp_dir(), "creds") . ".json"; file_put_contents($tmpCredFile, json_encode($tmpCreds)); $client = new Client(array("credentials" => $tmpCredFile)); $this->assertEquals("foo", $client->getClientId()); $client = new Client(array("credentials" => $tmpCredFile)); $this->assertEquals("foo", $client->getClientId()); $client = new Client(array("scopes" => "a-scope")); $this->assertEquals(array("a-scope"), $client->getScopes()); $client = new Client(array("scopes" => array("one-scope", "two-scope"))); $this->assertEquals(array("one-scope", "two-scope"), $client->getScopes()); $client = new Client(array("quota_project" => "some-quota-project")); $this->assertEquals("some-quota-project", $client->getConfig("quota_project")); putenv("GOOGLE_APPLICATION_CREDENTIALS=" . $tmpCredFile); $method = new ReflectionMethod($client, "createApplicationDefaultCredentials"); $method->setAccessible(true); $credentials = $method->invoke($client); $this->assertEquals("some-quota-project", $credentials->getQuotaProject()); } public function testCredentialsOptionWithCredentialsLoader() { $request = null; $credentials = $this->prophesize("Google\Auth\CredentialsLoader"); $credentials->getCacheKey()->willReturn("cache-key"); $credentials->updateMetadata(array(), null, Argument::any())->shouldBeCalledOnce()->willReturn(array("authorization" => "Bearer abc")); $credentials->getLastReceivedToken()->shouldBeCalledTimes(2)->willReturn(null); $client = new Client(array("credentials" => $credentials->reveal())); $handler = $this->prophesize("GuzzleHttp\HandlerStack"); $handler->remove("google_auth")->shouldBeCalledOnce(); $handler->push(Argument::any(), "google_auth")->shouldBeCalledOnce()->will(function ($args) use(&$request) { $middleware = $args[0]; $callable = $middleware(function ($req, $res) use(&$request) { $request = $req; }); $callable(new Request("GET", "/fake-uri"), array("auth" => "google_auth")); }); $httpClient = $this->prophesize("GuzzleHttp\ClientInterface"); $httpClient->getConfig()->shouldBeCalled()->willReturn(array("handler" => $handler->reveal())); $httpClient->send(Argument::any(), Argument::any())->shouldNotBeCalled(); $http = $client->authorize($httpClient->reveal()); $this->assertNotNull($request); $authHeader = $request->getHeaderLine("authorization"); $this->assertNotNull($authHeader); $this->assertEquals("Bearer abc", $authHeader); } public function testSetNewRedirectUri() { $client = new Client(); $redirectUri1 = "https://foo.com/test1"; $client->setRedirectUri($redirectUri1); $authUrl1 = $client->createAuthUrl(); $this->assertStringContainsString(urlencode($redirectUri1), $authUrl1); $redirectUri2 = "https://foo.com/test2"; $client->setRedirectUri($redirectUri2); $authUrl2 = $client->createAuthUrl(); $this->assertStringContainsString(urlencode($redirectUri2), $authUrl2); } public function testQueryParamsForAuthUrl() { $client = new Client(); $client->setRedirectUri("https://example.com"); $authUrl1 = $client->createAuthUrl(null, array("enable_serial_consent" => "true")); $this->assertStringContainsString("&enable_serial_consent=true", $authUrl1); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Google\Tests; use Google\Client; use Google\Service\Drive; use Google\AuthHandler\AuthHandlerFactory; use Google\Auth\FetchAuthTokenCache; use Google\Auth\GCECache; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Exception\ClientException; use Prophecy\Argument; use Psr\Http\Message\RequestInterface; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use ReflectionClass; use ReflectionMethod; use InvalidArgumentException; use Exception; class ClientTest extends BaseTest { public function testClientConstructor() { $this->assertInstanceOf(Client::class, $this->getClient()); } public function testSignAppKey() { $client = $this->getClient(); $client->setDeveloperKey("\x64\x65\166\113\145\x79"); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "\123\x69\155\x70\x6c\145"); } private function checkAuthHandler($http, $className) { $stack = $http->getConfig("\150\x61\x6e\x64\154\145\x72"); $class = new ReflectionClass(get_class($stack)); $property = $class->getProperty("\163\164\141\143\x6b"); $property->setAccessible(true); $middlewares = $property->getValue($stack); $middleware = array_pop($middlewares); if (null === $className) { $this->assertCount(3, $middlewares); } else { $authClass = sprintf("\x47\157\157\147\x6c\x65\x5c\x41\x75\164\150\x5c\115\x69\144\144\x6c\145\x77\141\x72\x65\134\45\x73\x4d\151\144\x64\x6c\145\167\141\x72\x65", $className); $this->assertInstanceOf($authClass, $middleware[0]); } } private function checkCredentials($http, $fetcherClass, $sub = null) { $stack = $http->getConfig("\150\x61\156\x64\x6c\x65\x72"); $class = new ReflectionClass(get_class($stack)); $property = $class->getProperty("\163\x74\x61\x63\x6b"); $property->setAccessible(true); $middlewares = $property->getValue($stack); $middleware = array_pop($middlewares); $auth = $middleware[0]; $class = new ReflectionClass(get_class($auth)); $property = $class->getProperty("\146\x65\x74\x63\x68\145\162"); $property->setAccessible(true); $cacheFetcher = $property->getValue($auth); $this->assertInstanceOf(FetchAuthTokenCache::class, $cacheFetcher); $class = new ReflectionClass(get_class($cacheFetcher)); $property = $class->getProperty("\x66\x65\164\143\x68\145\162"); $property->setAccessible(true); $fetcher = $property->getValue($cacheFetcher); $this->assertInstanceOf($fetcherClass, $fetcher); if ($sub) { $class = new ReflectionClass(get_class($fetcher)); $property = $class->getProperty("\x61\165\164\150"); $property->setAccessible(true); $auth = $property->getValue($fetcher); $this->assertEquals($sub, $auth->getSub()); } } public function testSignAccessToken() { $client = $this->getClient(); $http = new GuzzleClient(); $client->setAccessToken(array("\141\x63\143\x65\163\x73\x5f\x74\x6f\x6b\145\x6e" => "\x74\x65\x73\x74\x5f\164\157\153\145\x6e", "\x65\170\x70\151\x72\x65\163\x5f\x69\156" => 3600, "\x63\x72\x65\141\x74\145\144" => time())); $client->setScopes("\x74\145\163\164\137\x73\x63\x6f\x70\x65"); $client->authorize($http); $this->checkAuthHandler($http, "\x53\143\157\x70\145\x64\101\143\x63\x65\163\x73\x54\157\x6b\x65\x6e"); } public function testCreateAuthUrl() { $client = $this->getClient(); $client->setClientId("\x63\154\x69\x65\156\x74\111\144\x31"); $client->setClientSecret("\143\x6c\151\145\156\164\123\145\x63\x72\x65\164\x31"); $client->setRedirectUri("\150\164\x74\160\x3a\57\x2f\x6c\157\x63\141\154\150\x6f\x73\164"); $client->setDeveloperKey("\144\145\166\113\x65\171"); $client->setState("\170\171\172"); $client->setAccessType("\x6f\x66\146\154\x69\156\145"); $client->setApprovalPrompt("\146\x6f\x72\143\145"); $client->setRequestVisibleActions("\150\164\x74\x70\72\57\57\146\x6f\157"); $client->setLoginHint("\x62\157\142\x40\x65\x78\141\155\160\x6c\x65\x2e\x6f\162\x67"); $authUrl = $client->createAuthUrl("\x68\164\164\160\x3a\57\57\147\x6f\157\147\x6c\x65\x61\160\x69\163\56\143\x6f\155\x2f\163\143\157\160\x65\x2f\x66\x6f\x6f"); $expected = "\x68\x74\x74\x70\x73\72\57\x2f\x61\x63\x63\157\165\156\164\163\56\147\x6f\x6f\147\154\145\x2e\143\x6f\155\57\x6f\x2f\157\141\165\x74\x68\62\x2f\x76\62\x2f\x61\165\x74\150" . "\x3f\x72\145\x73\x70\157\x6e\163\145\x5f\x74\171\160\x65\x3d\x63\x6f\x64\145" . "\46\x61\x63\x63\x65\x73\163\x5f\164\171\160\145\75\157\146\x66\x6c\x69\x6e\x65" . "\46\143\x6c\x69\145\x6e\164\x5f\151\x64\x3d\x63\x6c\x69\145\156\164\x49\144\61" . "\x26\x72\x65\144\x69\x72\x65\x63\x74\137\165\x72\151\75\150\164\x74\x70\45\63\101\45\62\106\45\62\x46\x6c\x6f\143\141\x6c\x68\x6f\163\164" . "\46\x73\x74\141\x74\145\x3d\x78\x79\x7a" . "\x26\163\x63\157\160\145\75\150\164\164\160\45\63\101\x25\x32\x46\x25\x32\x46\x67\x6f\x6f\147\x6c\x65\141\160\151\x73\x2e\143\157\x6d\x25\x32\x46\x73\x63\157\x70\x65\x25\62\x46\146\157\157" . "\x26\x61\160\x70\162\x6f\x76\141\154\x5f\160\x72\x6f\155\x70\x74\75\146\157\162\x63\145" . "\46\154\157\x67\x69\x6e\137\150\151\x6e\x74\75\142\x6f\142\45\64\60\x65\x78\x61\155\x70\154\x65\x2e\x6f\162\x67"; $this->assertEquals($expected, $authUrl); $client->setLoginHint(''); $client->setHostedDomain("\x65\x78\x61\155\x70\154\145\56\143\157\155"); $client->setOpenIdRealm("\x65\170\x61\155\160\154\145\x2e\143\157\x6d"); $client->setPrompt("\x73\x65\154\145\143\164\x5f\141\x63\143\157\x75\x6e\x74"); $client->setIncludeGrantedScopes(true); $authUrl = $client->createAuthUrl("\x68\x74\x74\x70\72\x2f\x2f\147\x6f\x6f\147\x6c\145\x61\160\x69\x73\56\143\x6f\x6d\57\x73\143\157\x70\145\57\146\x6f\x6f"); $expected = "\x68\164\x74\160\163\x3a\x2f\x2f\x61\x63\143\x6f\x75\156\x74\163\56\x67\157\157\x67\154\145\56\143\x6f\x6d\x2f\157\x2f\x6f\141\x75\164\150\62\x2f\x76\x32\x2f\141\x75\x74\150" . "\x3f\x72\145\163\x70\157\x6e\x73\145\137\x74\x79\160\145\x3d\143\x6f\x64\x65" . "\x26\141\x63\x63\x65\x73\x73\x5f\164\171\160\x65\75\157\x66\146\x6c\151\156\145" . "\x26\x63\x6c\x69\x65\156\x74\x5f\151\x64\75\x63\x6c\x69\145\x6e\164\x49\x64\x31" . "\x26\162\x65\x64\x69\162\x65\x63\x74\x5f\x75\162\x69\75\150\164\164\x70\x25\63\101\45\x32\x46\45\62\x46\154\157\x63\x61\x6c\x68\x6f\163\x74" . "\x26\163\x74\x61\x74\x65\x3d\x78\x79\172" . "\x26\x73\x63\157\x70\x65\x3d\150\x74\x74\160\45\63\x41\45\x32\x46\x25\x32\x46\x67\x6f\157\147\x6c\145\141\160\x69\163\56\x63\157\155\x25\x32\x46\163\143\x6f\160\145\45\62\106\146\157\157" . "\46\x68\x64\x3d\x65\170\x61\x6d\x70\x6c\145\56\143\x6f\155" . "\46\151\156\143\154\165\x64\145\x5f\x67\x72\x61\x6e\164\145\144\137\x73\143\x6f\160\145\163\75\164\x72\x75\x65" . "\46\157\160\x65\156\x69\144\x2e\x72\x65\x61\154\155\75\x65\x78\141\155\x70\154\x65\56\x63\157\x6d" . "\46\160\x72\157\155\160\164\x3d\163\x65\154\x65\143\164\x5f\141\143\143\x6f\x75\x6e\164"; $this->assertEquals($expected, $authUrl); } public function testPrepareNoScopes() { $client = new Client(); $scopes = $client->prepareScopes(); $this->assertNull($scopes); } public function testNoAuthIsNull() { $client = new Client(); $this->assertNull($client->getAccessToken()); } public function testPrepareService() { $client = new Client(); $client->setScopes(array("\x73\143\157\160\145\x31", "\x73\143\157\x70\145\62")); $scopes = $client->prepareScopes(); $this->assertEquals("\x73\143\x6f\160\145\61\40\163\x63\157\x70\x65\62", $scopes); $client->setScopes(array('', "\163\x63\157\x70\x65\62")); $scopes = $client->prepareScopes(); $this->assertEquals("\x20\x73\x63\157\x70\145\62", $scopes); $client->setScopes("\163\x63\157\x70\x65\62"); $client->addScope("\163\x63\157\x70\x65\63"); $client->addScope(array("\x73\143\157\x70\145\64", "\x73\143\157\x70\145\x35")); $scopes = $client->prepareScopes(); $this->assertEquals("\x73\143\157\160\145\x32\x20\163\143\x6f\160\x65\x33\40\163\x63\157\x70\145\x34\40\163\x63\157\160\145\65", $scopes); $client->setClientId("\164\145\163\164\61"); $client->setRedirectUri("\150\x74\x74\160\x3a\57\57\x6c\x6f\x63\141\x6c\150\x6f\x73\164\x2f"); $client->setState("\170\171\172"); $client->setScopes(array("\x68\164\x74\160\x3a\x2f\x2f\x74\145\x73\x74\56\143\157\155", "\163\x63\157\x70\x65\x32")); $scopes = $client->prepareScopes(); $this->assertEquals("\150\164\x74\x70\72\x2f\x2f\164\x65\x73\164\x2e\x63\157\155\40\163\143\157\160\x65\x32", $scopes); $this->assertEquals('' . "\150\x74\164\x70\x73\72\x2f\57\141\143\x63\x6f\x75\x6e\164\x73\x2e\147\x6f\x6f\x67\154\x65\x2e\x63\x6f\155\57\x6f\x2f\157\x61\x75\164\150\62\57\166\x32\x2f\x61\x75\x74\150" . "\x3f\x72\145\x73\x70\157\156\x73\145\x5f\164\x79\x70\x65\x3d\143\157\144\145" . "\x26\x61\143\143\145\163\163\137\x74\171\x70\145\x3d\x6f\156\x6c\x69\x6e\x65" . "\x26\143\154\151\x65\156\x74\x5f\x69\x64\x3d\164\145\x73\x74\x31" . "\x26\162\145\144\151\162\145\x63\x74\x5f\x75\162\151\x3d\150\x74\x74\160\x25\63\101\45\x32\x46\45\x32\106\154\157\x63\x61\x6c\x68\157\163\x74\x25\62\106" . "\46\163\x74\x61\x74\145\x3d\x78\x79\x7a" . "\46\163\143\x6f\160\145\75\150\x74\164\x70\45\x33\101\x25\62\106\45\x32\x46\164\x65\163\x74\56\x63\157\155\45\x32\60\x73\x63\157\x70\145\x32" . "\x26\141\x70\x70\162\157\x76\141\154\137\x70\x72\157\155\x70\x74\x3d\141\x75\164\x6f", $client->createAuthUrl()); $stream = $this->prophesize("\107\x75\x7a\x7a\154\145\110\164\x74\x70\x5c\120\163\162\x37\x5c\123\164\162\145\x61\x6d"); $stream->__toString()->willReturn(''); $response = $this->prophesize("\x50\x73\162\x5c\x48\164\164\160\134\115\145\163\x73\x61\x67\145\x5c\x52\145\163\x70\157\x6e\163\145\x49\156\164\145\x72\x66\x61\x63\x65"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($stream->reveal()); $response->getStatusCode()->willReturn(200); $http = $this->prophesize("\107\165\x7a\x7a\x6c\x65\x48\x74\164\x70\x5c\x43\154\x69\x65\x6e\164\x49\x6e\x74\x65\x72\146\141\x63\145"); $http->send(Argument::type("\x50\x73\x72\134\x48\x74\164\x70\134\x4d\145\x73\x73\x61\147\145\134\122\x65\x71\x75\x65\163\x74\111\x6e\x74\145\x72\x66\x61\x63\145"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client->setHttpClient($http->reveal()); $dr_service = new Drive($client); $this->assertInstanceOf("\107\x6f\x6f\x67\154\x65\x5c\115\x6f\144\145\154", $dr_service->files->listFiles()); } public function testDefaultLogger() { $client = new Client(); $logger = $client->getLogger(); $this->assertInstanceOf("\x4d\x6f\x6e\157\154\x6f\147\134\114\157\147\147\145\162", $logger); $handler = $logger->popHandler(); $this->assertInstanceOf("\115\x6f\156\x6f\x6c\157\147\x5c\110\141\156\x64\x6c\x65\x72\x5c\123\164\x72\145\x61\155\110\x61\156\x64\x6c\145\162", $handler); } public function testDefaultLoggerAppEngine() { $_SERVER["\x53\105\122\126\105\x52\137\x53\x4f\106\x54\127\101\x52\x45"] = "\x47\x6f\157\x67\154\x65\40\x41\160\x70\x20\x45\156\147\x69\x6e\145"; $client = new Client(); $logger = $client->getLogger(); $handler = $logger->popHandler(); unset($_SERVER["\x53\105\x52\x56\x45\122\137\123\117\106\x54\x57\x41\x52\105"]); $this->assertInstanceOf("\x4d\157\156\157\154\157\147\x5c\x4c\157\147\147\x65\162", $logger); $this->assertInstanceOf("\115\x6f\156\x6f\154\157\x67\x5c\110\141\156\x64\154\145\162\134\x53\171\x73\x6c\157\x67\x48\x61\x6e\x64\154\145\x72", $handler); } public function testSettersGetters() { $client = new Client(); $client->setClientId("\x63\154\151\145\x6e\x74\x31"); $client->setClientSecret("\x63\x6c\x69\145\x6e\164\x31\x73\145\x63\x72\145\x74"); $client->setState("\61"); $client->setApprovalPrompt("\x66\157\x72\143\145"); $client->setAccessType("\157\146\146\154\x69\x6e\145"); $client->setRedirectUri("\x6c\x6f\143\x61\x6c\x68\157\163\x74"); $client->setConfig("\x61\160\160\x6c\151\x63\141\x74\151\x6f\x6e\x5f\x6e\141\x6d\x65", "\x6d\145"); $cache = $this->prophesize(CacheItemPoolInterface::class); $client->setCache($cache->reveal()); $this->assertInstanceOf(CacheItemPoolInterface::class, $client->getCache()); try { $client->setAccessToken(null); $this->fail("\x53\150\x6f\165\154\x64\x20\150\x61\166\x65\x20\164\x68\162\157\x77\156\40\141\x6e\x20\x45\x78\x63\145\x70\x74\151\x6f\156\56"); } catch (InvalidArgumentException $e) { $this->assertEquals("\x69\x6e\x76\x61\154\x69\144\x20\152\x73\x6f\156\40\164\x6f\x6b\145\x6e", $e->getMessage()); } $token = array("\141\143\143\x65\x73\163\x5f\164\x6f\153\145\156" => "\164\x6f\x6b\145\x6e"); $client->setAccessToken($token); $this->assertEquals($token, $client->getAccessToken()); } public function testSetAccessTokenValidation() { $client = new Client(); $client->setAccessToken(array("\x61\x63\x63\x65\163\x73\x5f\x74\x6f\153\145\156" => "\164\x6f\x6b\x65\156", "\143\x72\x65\x61\x74\145\144" => time())); self::assertEquals(true, $client->isAccessTokenExpired()); } public function testDefaultConfigOptions() { $client = new Client(); $this->assertArrayHasKey("\x68\x74\164\x70\x5f\145\x72\162\x6f\x72\x73", $client->getHttpClient()->getConfig()); $this->assertArrayNotHasKey("\x65\170\x63\145\160\164\151\x6f\x6e\x73", $client->getHttpClient()->getConfig()); $this->assertFalse($client->getHttpClient()->getConfig()["\150\x74\164\x70\x5f\145\162\162\x6f\162\x73"]); } public function testJsonConfig() { $client = new Client(); $device = "\173\x22\x69\x6e\x73\x74\x61\x6c\154\145\144\42\x3a\173\42\x61\165\x74\x68\137\x75\162\x69\x22\x3a\42\150\x74\164\x70\x73\72\x2f\57\141\143\x63\x6f\165\x6e\164\x73\56\x67\x6f\157\147\x6c\x65\56\x63\x6f\155\x2f\x6f\57\157\141\x75\x74\150\x32\57\166\62\x2f\141\165\164\x68\x22\54\x22\x63\154\x69\145\156\164\x5f\163\145\x63\162\145\164\42" . "\x3a\42\116\x30\x61\110\x43\x42\x54\61\x71\130\x31\126\101\143\106\65\112\x31\x70\x4a\101\x6e\x36\123\42\x2c\42\164\157\x6b\x65\x6e\x5f\165\x72\151\x22\x3a\42\150\164\x74\160\163\x3a\x2f\57\157\x61\x75\x74\x68\x32\x2e\147\x6f\x6f\147\154\x65\x61\x70\x69\x73\x2e\143\157\x6d\x2f\164\x6f\153\x65\x6e\42\x2c" . "\x22\x63\154\151\x65\156\x74\137\145\x6d\x61\x69\x6c\42\72\42\42\x2c\42\x72\145\x64\x69\162\x65\x63\x74\137\x75\162\x69\x73\42\72\133\x22\165\x72\x6e\72\x69\x65\164\146\x3a\x77\x67\72\157\x61\165\x74\150\72\62\x2e\x30\x3a\x6f\157\142\x22\x2c\x22\x6f\x6f\x62\x22\135\x2c\42\x63\154\x69\x65\x6e\x74\x5f\x78\x35\60\x39\137\143\145\x72\x74\x5f\x75\162\154\42" . "\x3a\x22\42\54\42\x63\x6c\151\145\156\x74\137\x69\144\42\x3a\x22\x31\x32\63\64\65\x36\67\x38\71\x2e\141\x70\x70\163\x2e\x67\157\157\147\154\145\165\163\145\162\x63\x6f\156\x74\x65\x6e\x74\56\143\157\x6d\x22\x2c\42\x61\x75\x74\x68\x5f\160\x72\x6f\166\x69\144\x65\162\x5f\x78\x35\60\71\137\x63\145\162\164\137\x75\162\154\x22\x3a" . "\42\x68\x74\x74\x70\163\x3a\57\x2f\x77\x77\167\x2e\147\157\x6f\147\154\x65\141\x70\x69\163\x2e\143\157\x6d\57\157\141\165\x74\x68\62\57\x76\61\x2f\x63\x65\x72\x74\163\42\175\175"; $dObj = json_decode($device, true); $client->setAuthConfig($dObj); $this->assertEquals($client->getClientId(), $dObj["\x69\x6e\163\164\141\154\x6c\145\x64"]["\x63\154\x69\145\156\x74\137\x69\144"]); $this->assertEquals($client->getClientSecret(), $dObj["\151\156\x73\x74\x61\x6c\154\x65\144"]["\143\x6c\x69\145\156\x74\137\163\x65\143\x72\145\x74"]); $this->assertEquals($client->getRedirectUri(), $dObj["\151\156\x73\x74\141\154\x6c\145\x64"]["\x72\x65\144\151\x72\x65\x63\164\x5f\165\162\151\x73"][0]); $client = new Client(); $web = "\173\x22\x77\x65\142\x22\72\x7b\x22\x61\x75\x74\x68\x5f\x75\162\x69\x22\x3a\x22\x68\x74\x74\160\x73\x3a\57\57\141\143\143\x6f\x75\x6e\x74\163\56\147\x6f\157\x67\x6c\x65\56\143\157\155\57\157\57\x6f\141\165\x74\150\x32\57\x76\62\x2f\141\165\164\150\x22\54\42\143\x6c\151\x65\x6e\x74\137\163\x65\x63\x72\x65\164\42" . "\72\42\x6c\160\x6f\x75\142\165\x69\142\70\x62\x6a\55\106\155\153\x65\x5f\131\x68\x68\x79\110\x47\x67\x58\x63\x22\x2c\42\164\157\153\145\156\x5f\165\x72\x69\42\72\x22\150\x74\x74\x70\x73\72\57\x2f\157\141\165\x74\x68\62\56\x67\x6f\x6f\147\x6c\x65\x61\x70\x69\x73\56\x63\x6f\155\57\164\157\153\x65\x6e\42" . "\54\42\143\154\151\145\156\164\137\x65\155\x61\x69\154\x22\72\x22\61\62\63\x34\x35\x36\67\70\71\x40\144\145\x76\x65\x6c\157\160\x65\162\x2e\147\x73\x65\162\x76\151\x63\145\x61\x63\143\157\165\156\164\x2e\x63\x6f\155\42\x2c\42\143\154\x69\145\156\164\x5f\x78\x35\60\71\137\143\145\x72\164\x5f\x75\162\154\x22\72" . "\x22\150\164\164\x70\x73\x3a\x2f\x2f\167\x77\x77\56\x67\x6f\x6f\147\x6c\145\141\x70\151\x73\x2e\143\x6f\155\57\162\x6f\x62\157\164\x2f\x76\x31\57\155\x65\164\x61\x64\141\x74\141\x2f\x78\x35\x30\71\x2f\x31\62\x33\x34\x35\x36\67\x38\x39\100\144\x65\166\x65\154\x6f\x70\145\162\x2e\x67\163\145\162\166\x69\143\x65\x61\x63\x63\x6f\165\156\164\x2e\143\x6f\155\42" . "\54\42\143\154\x69\145\156\x74\137\151\144\x22\x3a\42\61\x32\x33\64\65\x36\67\70\71\56\141\x70\x70\163\56\147\x6f\157\147\x6c\x65\x75\163\145\162\x63\157\x6e\x74\145\156\164\56\143\157\155\x22\54\x22\x61\165\x74\x68\137\x70\162\157\x76\x69\x64\145\x72\x5f\170\x35\x30\x39\137\143\x65\162\x74\x5f\165\x72\x6c\42\x3a" . "\x22\150\x74\x74\x70\163\x3a\x2f\57\167\x77\x77\56\147\157\157\x67\154\x65\x61\160\x69\163\56\143\x6f\x6d\57\157\141\x75\x74\x68\62\x2f\166\61\x2f\143\x65\x72\x74\x73\42\x7d\175"; $wObj = json_decode($web, true); $client->setAuthConfig($wObj); $this->assertEquals($client->getClientId(), $wObj["\x77\145\142"]["\x63\154\151\x65\156\164\137\151\x64"]); $this->assertEquals($client->getClientSecret(), $wObj["\x77\145\142"]["\x63\x6c\x69\x65\156\164\137\163\x65\x63\162\x65\x74"]); $this->assertEquals($client->getRedirectUri(), ''); } public function testIniConfig() { $config = parse_ini_file(__DIR__ . "\x2f\56\56\x2f\143\157\x6e\146\151\x67\x2f\164\x65\x73\164\x2e\x69\x6e\151"); $client = new Client($config); $this->assertEquals("\115\171\x20\124\x65\x73\x74\40\x61\160\160\x6c\x69\x63\141\x74\x69\x6f\x6e", $client->getConfig("\141\x70\160\x6c\151\143\x61\x74\151\157\x6e\x5f\156\141\x6d\145")); $this->assertEquals("\x67\x6a\146\x69\167\x6e\x47\151\156\160\145\156\x61\63", $client->getClientSecret()); } public function testNoAuth() { $client = new Client(); $client->setDeveloperKey(null); $GOOGLE_APPLICATION_CREDENTIALS = getenv("\107\x4f\x4f\x47\114\105\x5f\101\120\120\x4c\x49\103\x41\x54\x49\117\x4e\x5f\103\x52\105\x44\x45\116\x54\111\101\x4c\123"); $HOME = getenv("\x48\x4f\115\x45"); putenv("\107\117\x4f\x47\114\105\x5f\x41\120\x50\x4c\x49\103\101\x54\111\x4f\116\x5f\x43\122\105\x44\x45\x4e\124\111\x41\114\123\75"); putenv("\x48\x4f\115\105\75" . sys_get_temp_dir()); $http = new GuzzleClient(); $client->authorize($http); putenv("\107\117\x4f\x47\x4c\105\x5f\101\120\x50\x4c\x49\x43\x41\124\111\x4f\x4e\137\x43\x52\x45\104\x45\x4e\124\111\101\114\x53\75{$GOOGLE_APPLICATION_CREDENTIALS}"); putenv("\x48\x4f\115\105\x3d{$HOME}"); $this->checkAuthHandler($http, null); } public function testApplicationDefaultCredentials() { $this->checkServiceAccountCredentials(); $credentialsFile = getenv("\x47\x4f\x4f\107\114\105\x5f\101\x50\x50\114\111\x43\101\x54\x49\117\x4e\137\x43\122\x45\x44\x45\x4e\x54\x49\101\x4c\123"); $client = new Client(); $client->setAuthConfig($credentialsFile); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "\x41\x75\x74\x68\x54\x6f\153\145\156"); $this->checkCredentials($http, "\107\x6f\157\x67\x6c\x65\134\x41\x75\x74\150\134\x43\162\145\x64\x65\156\x74\151\x61\x6c\x73\x5c\123\x65\x72\166\x69\143\x65\x41\143\x63\157\x75\156\x74\x43\x72\x65\144\x65\156\164\x69\x61\154\163"); } public function testApplicationDefaultCredentialsWithSubject() { $this->checkServiceAccountCredentials(); $credentialsFile = getenv("\x47\117\117\107\114\x45\137\101\x50\x50\x4c\x49\x43\x41\124\111\x4f\x4e\x5f\x43\122\x45\104\x45\x4e\x54\x49\101\114\123"); $sub = "\x73\165\142\61\x32\63"; $client = new Client(); $client->setAuthConfig($credentialsFile); $client->setSubject($sub); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "\101\x75\x74\150\124\x6f\x6b\x65\x6e"); $this->checkCredentials($http, "\x47\x6f\x6f\x67\154\145\x5c\101\x75\x74\150\134\x43\x72\x65\144\x65\156\164\151\141\x6c\x73\134\123\x65\x72\166\x69\x63\145\x41\x63\x63\157\165\x6e\x74\x43\162\145\x64\145\156\164\x69\x61\154\163", $sub); } public function testRefreshTokenSetsValues() { $token = json_encode(array("\141\143\143\145\x73\163\137\164\157\x6b\x65\x6e" => "\x78\x79\x7a", "\x69\x64\137\x74\x6f\153\x65\156" => "\111\x44\137\124\117\113\105\x4e")); $postBody = $this->prophesize("\107\x75\172\172\154\145\x48\x74\164\160\134\120\163\162\67\x5c\123\x74\162\x65\x61\155"); $postBody->__toString()->shouldBeCalledTimes(1)->willReturn($token); $response = $this->prophesize("\x50\163\x72\134\x48\x74\x74\x70\x5c\x4d\145\163\163\x61\x67\x65\x5c\x52\x65\163\160\x6f\x6e\x73\x65\111\x6e\x74\x65\162\146\x61\143\145"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($postBody->reveal()); $response->hasHeader("\103\157\x6e\x74\145\156\x74\x2d\124\171\160\145")->willReturn(false); $http = $this->prophesize("\107\x75\x7a\172\x6c\145\110\x74\x74\x70\x5c\103\x6c\151\145\x6e\x74\x49\156\164\x65\162\146\141\143\x65"); $http->send(Argument::type("\120\x73\162\x5c\x48\164\164\160\x5c\x4d\x65\163\x73\x61\x67\145\x5c\x52\x65\x71\x75\x65\x73\164\x49\x6e\x74\145\x72\146\141\143\145"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken("\122\105\x46\x52\105\123\110\x5f\x54\x4f\x4b\105\116"); $token = $client->getAccessToken(); $this->assertEquals("\x49\104\137\x54\117\x4b\x45\x4e", $token["\x69\144\x5f\x74\x6f\153\x65\156"]); } public function testRefreshTokenIsSetOnRefresh() { $refreshToken = "\122\105\106\122\x45\x53\110\137\124\x4f\113\x45\116"; $token = json_encode(array("\x61\x63\x63\145\163\163\x5f\x74\157\x6b\145\156" => "\170\171\x7a", "\x69\144\137\x74\157\x6b\x65\x6e" => "\111\104\x5f\124\x4f\x4b\105\116")); $postBody = $this->prophesize("\120\x73\x72\134\x48\164\164\160\134\x4d\145\163\163\141\147\145\x5c\x53\164\162\x65\x61\x6d\111\156\x74\145\162\146\141\x63\x65"); $postBody->__toString()->shouldBeCalledTimes(1)->willReturn($token); $response = $this->prophesize("\120\163\162\134\110\164\164\160\134\115\145\x73\163\x61\x67\145\x5c\x52\x65\163\x70\x6f\x6e\x73\145\111\156\x74\x65\x72\146\141\x63\x65"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($postBody->reveal()); $response->hasHeader("\103\157\x6e\164\x65\156\x74\x2d\124\x79\160\x65")->willReturn(false); $http = $this->prophesize("\x47\x75\172\172\x6c\x65\x48\x74\x74\160\x5c\x43\x6c\151\x65\x6e\164\x49\156\164\145\162\x66\141\x63\x65"); $http->send(Argument::type("\x50\163\162\x5c\110\164\164\x70\x5c\x4d\145\x73\163\x61\x67\145\x5c\122\145\x71\165\x65\x73\x74\111\156\x74\x65\x72\x66\141\x63\145"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken($refreshToken); $token = $client->getAccessToken(); $this->assertEquals($refreshToken, $token["\x72\145\146\162\x65\163\150\x5f\x74\157\x6b\145\156"]); } public function testRefreshTokenIsNotSetWhenNewRefreshTokenIsReturned() { $refreshToken = "\x52\x45\x46\122\105\x53\x48\x5f\124\117\x4b\105\116"; $token = json_encode(array("\141\143\x63\145\163\163\137\164\x6f\x6b\x65\x6e" => "\170\171\172", "\151\x64\137\x74\157\153\145\156" => "\111\104\x5f\x54\117\x4b\105\x4e", "\162\145\146\162\x65\163\150\137\x74\157\153\x65\156" => "\116\105\127\x5f\x52\105\106\122\x45\123\x48\137\124\x4f\113\105\x4e")); $postBody = $this->prophesize("\x47\165\x7a\172\x6c\145\110\x74\164\x70\x5c\x50\x73\162\67\134\x53\x74\162\145\141\155"); $postBody->__toString()->wilLReturn($token); $response = $this->prophesize("\x50\x73\x72\134\110\x74\164\x70\x5c\x4d\x65\163\163\x61\x67\145\x5c\x52\x65\163\x70\157\156\163\x65\x49\156\164\145\162\x66\141\x63\145"); $response->getBody()->willReturn($postBody->reveal()); $response->hasHeader("\103\157\156\x74\145\156\x74\55\124\x79\x70\145")->willReturn(false); $http = $this->prophesize("\107\x75\x7a\x7a\x6c\145\x48\164\x74\x70\x5c\103\154\151\145\156\x74\x49\156\x74\145\162\146\141\x63\x65"); $http->send(Argument::type("\x50\x73\162\134\110\164\x74\160\x5c\115\x65\163\163\141\147\x65\134\122\145\x71\165\x65\x73\x74\x49\x6e\x74\145\162\146\x61\x63\x65"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken($refreshToken); $token = $client->getAccessToken(); $this->assertEquals("\116\105\127\x5f\x52\105\x46\x52\x45\x53\x48\137\x54\117\x4b\x45\116", $token["\x72\x65\146\x72\145\163\x68\x5f\164\x6f\153\x65\156"]); } public function testFetchAccessTokenWithAssertionFromEnv() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("\x61\143\143\x65\163\x73\137\164\157\x6b\145\156", $token); } public function testFetchAccessTokenWithAssertionFromFile() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->setAuthConfig(getenv("\x47\x4f\x4f\107\x4c\105\137\x41\120\x50\x4c\x49\103\101\x54\x49\117\116\137\103\x52\105\104\105\116\x54\111\x41\114\123")); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("\x61\x63\x63\x65\163\163\x5f\x74\157\153\145\156", $token); } public function testFetchAccessTokenWithAssertionAddsCreated() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("\143\162\x65\141\164\145\144", $token); } public function testBadSubjectThrowsException() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $client->setSubject("\x62\141\144\x2d\x73\165\142\x6a\x65\x63\164"); $authHandler = AuthHandlerFactory::build(); $method = new ReflectionMethod($authHandler, "\x63\x72\x65\141\164\145\x41\165\x74\150\110\164\164\160"); $method->setAccessible(true); $authHttp = $method->invoke($authHandler, $client->getHttpClient()); try { $token = $client->fetchAccessTokenWithAssertion($authHttp); $this->fail("\156\x6f\40\145\170\143\x65\160\x74\x69\157\x6e\40\x74\150\162\157\x77\156"); } catch (ClientException $e) { $response = $e->getResponse(); $this->assertContains("\111\x6e\166\x61\154\151\144\40\151\155\x70\145\162\x73\157\156\141\164\x69\x6f\156", (string) $response->getBody()); } } public function testTokenCallback() { $this->checkToken(); $client = $this->getClient(); $accessToken = $client->getAccessToken(); if (!isset($accessToken["\162\145\x66\x72\x65\163\x68\x5f\x74\x6f\x6b\x65\x6e"])) { $this->markTestSkipped("\122\145\146\x72\145\163\150\x20\x54\x6f\x6b\x65\156\40\162\x65\161\x75\151\x72\145\144"); } $accessToken["\x65\170\160\x69\162\145\x73\137\x69\156"] = 0; $cache = $client->getCache(); $path = sys_get_temp_dir() . "\57\147\x6f\157\147\x6c\145\55\x61\160\x69\55\160\x68\160\55\143\x6c\151\x65\156\x74\55\x74\x65\x73\x74\163\x2d" . time(); $client->setCache($this->getCache($path)); $client->setAccessToken($accessToken); $phpunit = $this; $called = false; $callback = function ($key, $value) use($client, $cache, $phpunit, &$called) { $phpunit->assertNotNull($key); $phpunit->assertNotNull($value); $called = true; $client->setCache($cache); }; $client->setTokenCallback($callback); $http = $client->authorize(); try { $http->get("\x68\x74\164\x70\163\x3a\57\x2f\x77\x77\x77\56\147\x6f\157\147\x6c\x65\141\160\x69\x73\56\x63\157\155\57\x62\x6f\x6f\153\x73\x2f\x76\x31\57\166\x6f\154\165\155\x65\163\x3f\x71\x3d\x56\x6f\x6c\x74\141\x69\x72\145"); } catch (Exception $e) { } $newToken = $client->getAccessToken(); $client->setCache($cache); $this->assertTrue($called); } public function testDefaultTokenCallback() { $this->checkToken(); $client = $this->getClient(); $accessToken = $client->getAccessToken(); if (!isset($accessToken["\x72\x65\146\x72\x65\163\x68\137\x74\x6f\153\x65\x6e"])) { $this->markTestSkipped("\122\145\x66\162\145\163\150\x20\124\x6f\153\x65\156\x20\162\x65\x71\165\x69\x72\145\144"); } $accessToken["\145\x78\160\x69\x72\x65\163\137\x69\156"] = 0; $client->setAccessToken($accessToken); $http = $client->authorize(); try { $http->get("\150\164\164\x70\163\72\x2f\x2f\167\x77\167\x2e\147\157\157\x67\154\145\x61\160\151\x73\56\143\157\155\57\x62\157\x6f\153\x73\57\x76\61\x2f\166\x6f\154\165\155\x65\163\x3f\x71\75\126\157\154\164\x61\151\x72\145"); } catch (Exception $e) { } $newToken = $client->getAccessToken(); $this->assertNotEquals($accessToken["\141\x63\143\145\x73\163\x5f\x74\x6f\x6b\x65\x6e"], $newToken["\x61\x63\143\145\163\x73\x5f\x74\157\153\x65\156"]); $this->assertFalse($client->isAccessTokenExpired()); } public function testOnGceCacheAndCacheOptions() { if (!class_exists(GCECache::class)) { $this->markTestSkipped("\x52\x65\x71\x75\151\x72\x65\x73\40\147\x6f\157\x67\x6c\145\x2f\141\x75\x74\150\x20\x3e\75\x20\61\56\61\62"); } putenv("\110\x4f\115\105\75"); putenv("\x47\117\117\107\x4c\x45\x5f\101\120\120\x4c\x49\x43\101\124\111\117\116\137\x43\x52\x45\104\105\x4e\124\111\x41\114\x53\75"); $prefix = "\x74\145\163\164\137\160\x72\145\x66\151\170\137"; $cacheConfig = array("\147\x63\145\x5f\x70\x72\145\146\x69\x78" => $prefix); $mockCacheItem = $this->prophesize(CacheItemInterface::class); $mockCacheItem->isHit()->willReturn(true); $mockCacheItem->get()->shouldBeCalledTimes(1)->willReturn(true); $mockCache = $this->prophesize(CacheItemPoolInterface::class); $mockCache->getItem($prefix . GCECache::GCE_CACHE_KEY)->shouldBeCalledTimes(1)->willReturn($mockCacheItem->reveal()); $client = new Client(array("\x63\141\143\150\145\137\143\x6f\156\x66\151\147" => $cacheConfig)); $client->setCache($mockCache->reveal()); $client->useApplicationDefaultCredentials(); $client->authorize(); } public function testFetchAccessTokenWithAssertionCache() { $this->checkServiceAccountCredentials(); $cachedValue = array("\141\x63\143\145\163\163\137\x74\157\153\x65\x6e" => "\x32\x2f\141\142\143\x64\x65\146\x31\x32\63\64\x35\x36\67\70\x39\60"); $mockCacheItem = $this->prophesize(CacheItemInterface::class); $mockCacheItem->isHit()->shouldBeCalledTimes(1)->willReturn(true); $mockCacheItem->get()->shouldBeCalledTimes(1)->willReturn($cachedValue); $mockCache = $this->prophesize(CacheItemPoolInterface::class); $mockCache->getItem(Argument::any())->shouldBeCalledTimes(1)->willReturn($mockCacheItem->reveal()); $client = new Client(); $client->setCache($mockCache->reveal()); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertArrayHasKey("\141\x63\x63\x65\163\x73\x5f\x74\157\153\145\x6e", $token); $this->assertEquals($cachedValue["\141\143\143\145\x73\x73\137\164\x6f\153\x65\156"], $token["\141\143\143\x65\163\x73\x5f\x74\157\x6b\x65\156"]); } public function testCacheClientOption() { $mockCache = $this->prophesize(CacheItemPoolInterface::class); $client = new Client(array("\x63\141\143\x68\x65" => $mockCache->reveal())); $this->assertEquals($mockCache->reveal(), $client->getCache()); } public function testExecuteWithFormat() { $client = new Client(array("\141\160\151\137\x66\157\162\155\141\164\137\x76\62" => true)); $guzzle = $this->prophesize("\107\165\172\x7a\154\x65\110\164\164\160\x5c\x43\x6c\151\x65\x6e\x74"); $guzzle->send(Argument::allOf(Argument::type("\120\163\x72\134\x48\x74\x74\x70\134\x4d\145\163\x73\x61\x67\145\x5c\122\145\161\165\x65\x73\164\111\156\x74\x65\162\146\141\x63\145"), Argument::that(function (RequestInterface $request) { return $request->getHeaderLine("\x58\x2d\x47\117\x4f\x47\x2d\101\x50\x49\x2d\x46\x4f\122\x4d\x41\124\55\126\105\122\123\111\x4f\x4e") === "\x32"; })), array())->shouldBeCalled()->willReturn(new Response(200, array(), null)); $client->setHttpClient($guzzle->reveal()); $request = new Request("\120\x4f\123\x54", "\150\x74\x74\x70\x3a\x2f\x2f\146\x6f\157\x2e\x62\141\162\x2f"); $client->execute($request); } public function testExecuteSetsCorrectHeaders() { $client = new Client(); $guzzle = $this->prophesize("\107\165\x7a\172\x6c\x65\110\x74\164\x70\134\x43\154\151\145\156\x74"); $guzzle->send(Argument::that(function (RequestInterface $request) { $userAgent = sprintf("\45\163\45\163", Client::USER_AGENT_SUFFIX, Client::LIBVER); $xGoogApiClient = sprintf("\x67\154\55\x70\150\160\x2f\45\163\x20\x67\x64\143\x6c\57\45\x73", phpversion(), Client::LIBVER); if ($request->getHeaderLine("\x55\x73\x65\x72\55\x41\147\x65\x6e\x74") !== $userAgent) { return false; } if ($request->getHeaderLine("\x78\x2d\147\157\x6f\147\55\x61\x70\x69\x2d\x63\x6c\x69\x65\156\164") !== $xGoogApiClient) { return false; } return true; }), array())->shouldBeCalledTimes(1)->willReturn(new Response(200, array(), null)); $client->setHttpClient($guzzle->reveal()); $request = new Request("\x50\x4f\x53\124", "\150\x74\x74\x70\72\57\x2f\146\x6f\157\x2e\x62\x61\162\x2f"); $client->execute($request); } public function testClientOptions() { $tmpCreds = array("\164\x79\x70\x65" => "\x73\x65\162\166\151\143\145\x5f\141\143\x63\x6f\x75\x6e\164", "\143\x6c\151\145\156\164\x5f\x69\144" => "\x66\157\x6f", "\x63\x6c\151\x65\156\164\x5f\x65\x6d\x61\x69\x6c" => '', "\160\162\x69\166\141\164\x65\x5f\153\145\171" => ''); $tmpCredFile = tempnam(sys_get_temp_dir(), "\143\162\x65\144\163") . "\x2e\152\163\x6f\156"; file_put_contents($tmpCredFile, json_encode($tmpCreds)); $client = new Client(array("\x63\x72\x65\144\145\156\164\x69\x61\x6c\x73" => $tmpCredFile)); $this->assertEquals("\146\x6f\x6f", $client->getClientId()); $client = new Client(array("\143\162\145\x64\145\x6e\164\151\x61\x6c\163" => $tmpCredFile)); $this->assertEquals("\146\157\x6f", $client->getClientId()); $client = new Client(array("\x73\143\157\160\x65\x73" => "\141\x2d\x73\x63\157\x70\145")); $this->assertEquals(array("\141\x2d\163\143\157\160\145"), $client->getScopes()); $client = new Client(array("\x73\x63\157\x70\x65\163" => array("\157\156\145\55\163\143\x6f\x70\145", "\x74\x77\x6f\x2d\x73\x63\157\160\145"))); $this->assertEquals(array("\x6f\156\145\x2d\163\143\x6f\x70\145", "\x74\x77\x6f\55\163\x63\157\x70\x65"), $client->getScopes()); $client = new Client(array("\161\165\157\164\141\x5f\160\162\x6f\x6a\145\143\164" => "\163\x6f\155\145\x2d\161\165\157\164\141\x2d\x70\x72\x6f\x6a\145\143\164")); $this->assertEquals("\163\x6f\x6d\x65\55\161\165\157\164\x61\x2d\x70\x72\x6f\x6a\145\x63\164", $client->getConfig("\161\165\157\164\141\137\x70\x72\x6f\152\145\143\x74")); putenv("\107\x4f\117\x47\x4c\105\x5f\101\120\120\114\x49\103\x41\124\111\x4f\x4e\x5f\x43\x52\x45\104\105\116\x54\111\101\114\123\x3d" . $tmpCredFile); $method = new ReflectionMethod($client, "\x63\x72\x65\x61\x74\x65\x41\160\x70\154\151\143\141\x74\151\157\x6e\x44\x65\146\141\165\x6c\x74\103\162\145\x64\145\156\164\x69\x61\x6c\163"); $method->setAccessible(true); $credentials = $method->invoke($client); $this->assertEquals("\x73\x6f\155\145\55\x71\165\157\x74\141\55\160\x72\157\x6a\145\x63\x74", $credentials->getQuotaProject()); } public function testCredentialsOptionWithCredentialsLoader() { $request = null; $credentials = $this->prophesize("\107\x6f\x6f\147\154\145\x5c\x41\165\x74\x68\x5c\103\162\x65\144\145\156\164\151\141\x6c\163\x4c\157\x61\144\x65\162"); $credentials->getCacheKey()->willReturn("\x63\x61\143\x68\x65\55\x6b\x65\171"); $credentials->updateMetadata(array(), null, Argument::any())->shouldBeCalledOnce()->willReturn(array("\x61\x75\x74\150\157\162\151\x7a\x61\164\x69\x6f\156" => "\x42\x65\141\162\x65\x72\40\141\x62\143")); $credentials->getLastReceivedToken()->shouldBeCalledTimes(2)->willReturn(null); $client = new Client(array("\143\x72\145\144\x65\156\164\x69\141\154\x73" => $credentials->reveal())); $handler = $this->prophesize("\x47\165\x7a\172\154\145\110\x74\x74\x70\134\x48\141\x6e\x64\154\145\162\123\164\141\x63\153"); $handler->remove("\147\x6f\x6f\147\154\x65\x5f\x61\x75\164\150")->shouldBeCalledOnce(); $handler->push(Argument::any(), "\x67\x6f\x6f\x67\154\x65\137\x61\165\164\x68")->shouldBeCalledOnce()->will(function ($args) use(&$request) { $middleware = $args[0]; $callable = $middleware(function ($req, $res) use(&$request) { $request = $req; }); $callable(new Request("\107\x45\x54", "\57\146\x61\153\145\x2d\165\x72\x69"), array("\141\165\x74\x68" => "\x67\x6f\x6f\x67\x6c\145\137\141\165\164\x68")); }); $httpClient = $this->prophesize("\x47\165\172\x7a\154\x65\110\x74\164\160\134\103\x6c\151\x65\x6e\164\111\x6e\x74\x65\x72\x66\141\143\x65"); $httpClient->getConfig()->shouldBeCalled()->willReturn(array("\x68\x61\156\144\x6c\x65\x72" => $handler->reveal())); $httpClient->send(Argument::any(), Argument::any())->shouldNotBeCalled(); $http = $client->authorize($httpClient->reveal()); $this->assertNotNull($request); $authHeader = $request->getHeaderLine("\x61\x75\x74\x68\157\x72\151\172\x61\x74\151\x6f\x6e"); $this->assertNotNull($authHeader); $this->assertEquals("\x42\145\141\x72\x65\162\x20\x61\x62\x63", $authHeader); } public function testSetNewRedirectUri() { $client = new Client(); $redirectUri1 = "\150\x74\164\x70\163\72\x2f\x2f\x66\x6f\157\56\143\x6f\x6d\57\164\145\x73\x74\61"; $client->setRedirectUri($redirectUri1); $authUrl1 = $client->createAuthUrl(); $this->assertStringContainsString(urlencode($redirectUri1), $authUrl1); $redirectUri2 = "\x68\x74\164\x70\x73\x3a\57\x2f\146\x6f\157\x2e\x63\157\x6d\x2f\164\145\x73\x74\x32"; $client->setRedirectUri($redirectUri2); $authUrl2 = $client->createAuthUrl(); $this->assertStringContainsString(urlencode($redirectUri2), $authUrl2); } public function testQueryParamsForAuthUrl() { $client = new Client(); $client->setRedirectUri("\150\x74\x74\160\x73\72\57\x2f\x65\170\x61\155\160\154\x65\56\x63\157\x6d"); $authUrl1 = $client->createAuthUrl(null, array("\x65\x6e\141\142\154\145\x5f\x73\145\162\151\141\x6c\137\143\x6f\x6e\163\x65\156\x74" => "\164\x72\165\x65")); $this->assertStringContainsString("\x26\x65\x6e\141\x62\x6c\x65\x5f\x73\145\x72\151\141\x6c\137\143\x6f\156\163\x65\156\x74\75\164\x72\x75\x65", $authUrl1); } }
Function Calls
| None |
Stats
| MD5 | e09843c6ef5ddb95aa4dd0c53ebdebf4 |
| Eval Count | 0 |
| Decode Time | 104 ms |