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("\144\x65\x76\113\x65\171"); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "\123\151\155\160\x6c\x65"); } private function checkAuthHandler($http, $className) { $stack = $http->getConfig("\150\141\156\144\154\145\162"); $class = new ReflectionClass(get_class($stack)); $property = $class->getProperty("\163\x74\141\143\x6b"); $property->setAccessible(true); $middlewares = $property->getValue($stack); $middleware = array_pop($middlewares); if (null === $className) { $this->assertCount(3, $middlewares); } else { $authClass = sprintf("\107\x6f\157\x67\x6c\x65\134\x41\165\x74\150\134\115\x69\x64\x64\154\x65\167\x61\x72\x65\x5c\x25\x73\115\151\144\x64\154\145\167\x61\x72\145", $className); $this->assertInstanceOf($authClass, $middleware[0]); } } private function checkCredentials($http, $fetcherClass, $sub = null) { $stack = $http->getConfig("\150\141\x6e\144\154\x65\162"); $class = new ReflectionClass(get_class($stack)); $property = $class->getProperty("\163\x74\141\143\153"); $property->setAccessible(true); $middlewares = $property->getValue($stack); $middleware = array_pop($middlewares); $auth = $middleware[0]; $class = new ReflectionClass(get_class($auth)); $property = $class->getProperty("\x66\145\164\143\x68\x65\x72"); $property->setAccessible(true); $cacheFetcher = $property->getValue($auth); $this->assertInstanceOf(FetchAuthTokenCache::class, $cacheFetcher); $class = new ReflectionClass(get_class($cacheFetcher)); $property = $class->getProperty("\146\145\x74\x63\x68\x65\x72"); $property->setAccessible(true); $fetcher = $property->getValue($cacheFetcher); $this->assertInstanceOf($fetcherClass, $fetcher); if ($sub) { $class = new ReflectionClass(get_class($fetcher)); $property = $class->getProperty("\x61\165\x74\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("\x61\143\143\x65\x73\163\x5f\164\x6f\x6b\x65\x6e" => "\x74\145\163\164\137\x74\157\x6b\145\x6e", "\x65\x78\x70\x69\162\x65\x73\137\151\x6e" => 3600, "\143\x72\145\141\x74\145\x64" => time())); $client->setScopes("\164\x65\163\x74\137\163\x63\157\160\145"); $client->authorize($http); $this->checkAuthHandler($http, "\x53\x63\x6f\160\145\x64\x41\x63\143\x65\x73\163\x54\157\153\145\x6e"); } public function testCreateAuthUrl() { $client = $this->getClient(); $client->setClientId("\x63\154\151\145\156\x74\x49\x64\61"); $client->setClientSecret("\143\x6c\151\145\x6e\164\x53\x65\x63\162\145\164\x31"); $client->setRedirectUri("\x68\x74\x74\x70\72\x2f\57\x6c\x6f\143\141\x6c\x68\x6f\163\164"); $client->setDeveloperKey("\144\x65\x76\x4b\x65\x79"); $client->setState("\170\x79\172"); $client->setAccessType("\x6f\x66\x66\x6c\x69\x6e\x65"); $client->setApprovalPrompt("\x66\157\x72\x63\x65"); $client->setRequestVisibleActions("\x68\164\164\x70\72\x2f\57\146\157\x6f"); $client->setLoginHint("\x62\157\x62\x40\x65\x78\x61\155\x70\x6c\x65\x2e\157\162\147"); $authUrl = $client->createAuthUrl("\x68\164\x74\x70\x3a\57\x2f\x67\157\x6f\x67\x6c\145\x61\160\151\163\x2e\143\x6f\155\x2f\x73\143\157\x70\x65\x2f\146\x6f\x6f"); $expected = "\x68\164\164\x70\163\x3a\x2f\x2f\141\x63\x63\157\165\x6e\164\x73\x2e\147\157\x6f\147\154\145\x2e\143\157\155\57\x6f\x2f\x6f\x61\165\x74\x68\x32\57\x76\x32\x2f\141\x75\164\x68" . "\x3f\x72\x65\x73\x70\x6f\156\x73\145\137\x74\x79\160\145\75\143\x6f\144\145" . "\x26\x61\x63\x63\145\x73\163\137\x74\x79\160\145\75\157\x66\x66\154\151\156\145" . "\46\x63\x6c\x69\145\x6e\x74\x5f\151\x64\75\x63\154\151\145\x6e\164\111\144\61" . "\x26\162\145\144\151\x72\x65\x63\x74\x5f\165\x72\151\x3d\x68\x74\x74\160\45\63\x41\45\x32\x46\45\x32\106\154\157\x63\141\154\150\157\x73\164" . "\x26\x73\164\x61\164\x65\x3d\170\171\172" . "\x26\x73\143\157\x70\145\75\150\x74\164\x70\x25\x33\101\45\62\x46\x25\x32\106\147\x6f\x6f\x67\154\145\x61\160\x69\163\56\x63\x6f\x6d\x25\62\106\x73\143\x6f\x70\x65\x25\62\x46\x66\x6f\157" . "\x26\x61\160\x70\162\157\x76\x61\x6c\137\x70\x72\x6f\155\x70\164\x3d\x66\157\162\x63\145" . "\46\x6c\x6f\x67\151\156\x5f\x68\x69\156\164\x3d\142\x6f\142\45\64\x30\x65\170\x61\x6d\x70\154\x65\56\157\162\147"; $this->assertEquals($expected, $authUrl); $client->setLoginHint(''); $client->setHostedDomain("\x65\170\141\155\x70\154\x65\56\x63\157\x6d"); $client->setOpenIdRealm("\145\x78\x61\155\160\x6c\145\x2e\143\x6f\155"); $client->setPrompt("\163\145\x6c\145\143\164\137\x61\143\143\x6f\x75\156\x74"); $client->setIncludeGrantedScopes(true); $authUrl = $client->createAuthUrl("\x68\164\x74\x70\x3a\x2f\x2f\x67\157\157\147\x6c\x65\141\160\151\x73\x2e\143\157\155\57\x73\143\x6f\160\145\x2f\146\157\x6f"); $expected = "\x68\164\164\x70\x73\x3a\57\x2f\x61\143\x63\157\x75\x6e\164\163\x2e\147\x6f\157\x67\x6c\x65\x2e\x63\x6f\x6d\x2f\x6f\57\157\141\165\x74\150\x32\57\166\62\57\x61\165\164\150" . "\x3f\x72\x65\163\x70\157\x6e\163\145\x5f\x74\171\160\145\75\x63\157\x64\x65" . "\x26\x61\x63\x63\x65\163\163\137\x74\x79\x70\x65\x3d\157\146\146\x6c\x69\156\x65" . "\46\x63\x6c\151\x65\x6e\164\137\151\x64\x3d\143\x6c\x69\x65\x6e\164\x49\x64\x31" . "\x26\162\145\144\x69\162\x65\x63\x74\x5f\x75\x72\151\x3d\x68\164\164\x70\45\x33\101\45\62\x46\45\62\x46\154\x6f\x63\141\x6c\x68\x6f\163\164" . "\46\163\164\141\x74\145\75\x78\x79\x7a" . "\46\x73\143\157\160\x65\75\150\x74\x74\x70\45\63\101\x25\x32\x46\x25\x32\106\147\x6f\x6f\x67\x6c\x65\141\160\x69\163\x2e\x63\x6f\155\x25\x32\106\163\x63\x6f\x70\145\x25\62\106\x66\157\157" . "\x26\150\x64\75\x65\x78\141\x6d\x70\154\145\x2e\143\x6f\155" . "\46\151\x6e\x63\154\165\x64\x65\x5f\147\x72\141\x6e\x74\x65\x64\137\163\143\x6f\x70\x65\163\x3d\164\162\165\x65" . "\46\157\160\145\156\151\x64\x2e\x72\145\141\154\155\75\x65\x78\141\155\160\x6c\145\56\143\157\155" . "\46\x70\x72\x6f\x6d\x70\164\75\163\x65\154\x65\x63\x74\x5f\141\143\143\157\x75\156\x74"; $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\x63\157\x70\x65\61", "\163\x63\x6f\160\145\62")); $scopes = $client->prepareScopes(); $this->assertEquals("\163\143\157\160\145\x31\40\x73\143\x6f\x70\x65\x32", $scopes); $client->setScopes(array('', "\x73\x63\x6f\160\145\62")); $scopes = $client->prepareScopes(); $this->assertEquals("\40\x73\143\x6f\160\x65\62", $scopes); $client->setScopes("\x73\143\x6f\x70\x65\x32"); $client->addScope("\163\x63\x6f\160\145\63"); $client->addScope(array("\163\x63\157\x70\145\x34", "\163\x63\157\160\x65\65")); $scopes = $client->prepareScopes(); $this->assertEquals("\163\x63\157\x70\x65\x32\40\163\143\157\x70\x65\x33\40\163\143\x6f\160\145\x34\x20\163\143\157\160\145\65", $scopes); $client->setClientId("\x74\145\x73\x74\x31"); $client->setRedirectUri("\x68\164\164\x70\x3a\57\57\x6c\x6f\143\141\154\x68\157\x73\x74\57"); $client->setState("\170\x79\172"); $client->setScopes(array("\x68\x74\x74\x70\x3a\x2f\x2f\164\x65\x73\164\x2e\x63\x6f\155", "\163\x63\157\160\x65\x32")); $scopes = $client->prepareScopes(); $this->assertEquals("\x68\x74\x74\160\x3a\57\x2f\x74\145\163\x74\56\143\157\x6d\40\163\143\x6f\160\145\x32", $scopes); $this->assertEquals('' . "\150\x74\x74\x70\163\x3a\57\57\141\143\143\157\x75\156\x74\x73\x2e\x67\x6f\x6f\147\x6c\x65\x2e\x63\x6f\155\57\157\57\157\x61\x75\164\150\62\57\x76\62\57\x61\x75\164\150" . "\x3f\162\145\163\x70\x6f\x6e\163\x65\x5f\164\x79\160\145\x3d\x63\157\144\145" . "\x26\141\143\x63\145\x73\163\137\164\171\x70\x65\75\x6f\x6e\154\151\156\145" . "\x26\143\154\151\145\x6e\x74\x5f\x69\144\75\164\x65\x73\x74\61" . "\x26\x72\145\x64\151\162\x65\143\x74\137\165\x72\151\x3d\150\164\x74\x70\45\63\101\45\62\106\x25\x32\106\154\x6f\x63\141\154\150\x6f\163\x74\x25\62\106" . "\46\163\164\x61\164\145\75\170\x79\x7a" . "\x26\163\143\x6f\x70\x65\x3d\150\x74\164\x70\x25\63\101\45\62\106\x25\62\106\164\145\163\164\56\x63\157\155\45\x32\60\x73\x63\157\160\145\x32" . "\x26\x61\x70\160\x72\x6f\166\141\x6c\137\160\162\157\x6d\x70\x74\x3d\x61\165\x74\x6f", $client->createAuthUrl()); $stream = $this->prophesize("\x47\165\172\x7a\154\145\110\164\x74\160\134\x50\163\162\x37\x5c\123\164\x72\145\141\155"); $stream->__toString()->willReturn(''); $response = $this->prophesize("\x50\x73\x72\134\110\x74\x74\160\x5c\x4d\x65\x73\x73\x61\147\x65\134\x52\145\163\160\x6f\156\x73\x65\x49\x6e\164\x65\x72\x66\x61\x63\145"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($stream->reveal()); $response->getStatusCode()->willReturn(200); $http = $this->prophesize("\107\165\172\x7a\x6c\145\110\x74\164\x70\134\x43\154\x69\x65\156\x74\111\x6e\x74\x65\x72\146\141\143\x65"); $http->send(Argument::type("\x50\x73\x72\134\110\164\164\x70\x5c\x4d\x65\163\x73\141\147\145\134\122\x65\161\x75\145\163\x74\111\x6e\164\145\x72\146\x61\143\x65"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client->setHttpClient($http->reveal()); $dr_service = new Drive($client); $this->assertInstanceOf("\107\157\157\147\154\x65\134\x4d\157\144\145\x6c", $dr_service->files->listFiles()); } public function testDefaultLogger() { $client = new Client(); $logger = $client->getLogger(); $this->assertInstanceOf("\x4d\x6f\x6e\x6f\x6c\x6f\147\x5c\x4c\x6f\x67\x67\145\162", $logger); $handler = $logger->popHandler(); $this->assertInstanceOf("\115\157\156\x6f\154\157\x67\x5c\x48\x61\x6e\144\154\x65\162\134\123\164\162\145\x61\x6d\x48\141\x6e\144\154\145\x72", $handler); } public function testDefaultLoggerAppEngine() { $_SERVER["\123\105\x52\126\x45\122\x5f\x53\x4f\106\124\x57\101\122\105"] = "\107\157\x6f\x67\x6c\145\x20\x41\x70\160\x20\105\x6e\x67\151\x6e\145"; $client = new Client(); $logger = $client->getLogger(); $handler = $logger->popHandler(); unset($_SERVER["\x53\105\122\x56\x45\122\x5f\x53\117\106\124\x57\101\x52\x45"]); $this->assertInstanceOf("\115\x6f\156\x6f\x6c\157\x67\134\114\157\147\x67\x65\162", $logger); $this->assertInstanceOf("\115\x6f\x6e\157\154\x6f\147\134\x48\141\156\144\154\x65\x72\134\123\171\163\154\157\x67\x48\141\x6e\144\154\x65\162", $handler); } public function testSettersGetters() { $client = new Client(); $client->setClientId("\x63\x6c\151\145\156\x74\x31"); $client->setClientSecret("\x63\154\x69\x65\x6e\164\x31\163\145\143\162\145\x74"); $client->setState("\61"); $client->setApprovalPrompt("\146\x6f\162\143\x65"); $client->setAccessType("\157\x66\x66\154\x69\156\145"); $client->setRedirectUri("\x6c\157\143\141\154\150\x6f\163\x74"); $client->setConfig("\x61\160\x70\154\151\x63\141\x74\151\x6f\156\x5f\x6e\141\155\145", "\x6d\145"); $cache = $this->prophesize(CacheItemPoolInterface::class); $client->setCache($cache->reveal()); $this->assertInstanceOf(CacheItemPoolInterface::class, $client->getCache()); try { $client->setAccessToken(null); $this->fail("\x53\x68\x6f\x75\154\x64\40\x68\x61\166\x65\x20\x74\150\162\157\x77\x6e\40\x61\156\x20\105\170\x63\x65\x70\x74\151\x6f\x6e\56"); } catch (InvalidArgumentException $e) { $this->assertEquals("\x69\x6e\x76\141\x6c\151\x64\40\152\x73\x6f\x6e\x20\x74\157\x6b\x65\x6e", $e->getMessage()); } $token = array("\141\143\143\145\163\163\137\164\x6f\153\x65\x6e" => "\164\x6f\153\145\x6e"); $client->setAccessToken($token); $this->assertEquals($token, $client->getAccessToken()); } public function testSetAccessTokenValidation() { $client = new Client(); $client->setAccessToken(array("\141\x63\x63\x65\x73\163\137\x74\157\x6b\x65\156" => "\164\157\x6b\145\156", "\x63\162\x65\141\164\145\144" => time())); self::assertEquals(true, $client->isAccessTokenExpired()); } public function testDefaultConfigOptions() { $client = new Client(); $this->assertArrayHasKey("\x68\164\164\160\137\x65\162\x72\157\162\x73", $client->getHttpClient()->getConfig()); $this->assertArrayNotHasKey("\145\x78\143\145\x70\164\151\x6f\x6e\163", $client->getHttpClient()->getConfig()); $this->assertFalse($client->getHttpClient()->getConfig()["\x68\x74\x74\x70\x5f\145\x72\x72\157\162\x73"]); } public function testJsonConfig() { $client = new Client(); $device = "\x7b\x22\x69\x6e\x73\164\141\154\154\x65\144\42\72\173\x22\x61\x75\x74\150\137\x75\x72\151\x22\72\42\x68\164\x74\160\163\72\57\x2f\141\143\143\x6f\165\x6e\164\x73\56\x67\x6f\x6f\147\x6c\x65\x2e\143\157\x6d\57\x6f\57\157\141\165\164\150\62\x2f\166\62\57\141\x75\x74\x68\x22\x2c\42\x63\x6c\151\145\156\x74\137\x73\145\143\162\x65\x74\42" . "\x3a\42\x4e\60\x61\x48\x43\x42\124\x31\161\130\61\x56\x41\x63\x46\65\x4a\61\x70\x4a\x41\156\x36\x53\42\54\x22\164\157\153\145\156\x5f\165\x72\x69\42\x3a\x22\150\164\x74\160\x73\72\x2f\x2f\x6f\141\165\x74\150\x32\x2e\x67\x6f\157\147\x6c\x65\x61\x70\151\163\56\x63\x6f\155\57\x74\x6f\x6b\145\156\x22\54" . "\42\x63\154\151\x65\156\x74\137\145\x6d\x61\x69\154\x22\72\42\x22\54\42\x72\145\x64\151\162\145\x63\x74\137\165\x72\151\163\42\x3a\133\x22\x75\162\156\x3a\x69\x65\164\146\72\x77\147\x3a\157\141\165\164\x68\x3a\62\x2e\x30\x3a\157\x6f\142\42\54\42\157\x6f\142\x22\x5d\54\42\x63\154\x69\x65\x6e\x74\x5f\x78\65\x30\x39\137\143\x65\x72\x74\x5f\165\162\154\42" . "\72\x22\42\x2c\x22\x63\x6c\151\x65\x6e\x74\137\151\x64\x22\x3a\42\x31\62\x33\x34\65\x36\67\x38\71\56\x61\x70\160\x73\x2e\147\x6f\157\x67\x6c\x65\x75\x73\145\x72\143\x6f\x6e\x74\x65\156\164\56\143\x6f\x6d\x22\54\42\141\165\x74\150\137\160\x72\x6f\166\151\x64\145\162\137\170\65\60\x39\137\143\x65\162\x74\x5f\x75\x72\154\42\x3a" . "\x22\x68\x74\x74\160\x73\x3a\57\x2f\167\x77\x77\56\x67\157\157\x67\154\x65\x61\x70\x69\x73\56\x63\157\155\x2f\x6f\x61\x75\x74\x68\x32\x2f\166\61\x2f\143\x65\x72\164\163\x22\175\x7d"; $dObj = json_decode($device, true); $client->setAuthConfig($dObj); $this->assertEquals($client->getClientId(), $dObj["\x69\x6e\163\x74\141\154\154\x65\x64"]["\143\x6c\x69\145\x6e\x74\x5f\151\x64"]); $this->assertEquals($client->getClientSecret(), $dObj["\151\156\x73\x74\141\x6c\154\145\x64"]["\x63\x6c\x69\145\156\164\137\163\145\143\x72\145\164"]); $this->assertEquals($client->getRedirectUri(), $dObj["\151\x6e\163\164\x61\154\x6c\x65\144"]["\162\145\144\x69\162\145\x63\x74\137\165\x72\151\163"][0]); $client = new Client(); $web = "\173\x22\167\x65\142\x22\x3a\x7b\x22\x61\165\164\150\x5f\165\162\151\42\x3a\x22\150\x74\164\160\163\72\x2f\57\141\x63\143\157\x75\156\164\x73\56\x67\x6f\x6f\147\x6c\x65\x2e\143\x6f\155\x2f\157\57\157\x61\165\164\x68\x32\x2f\166\62\57\x61\x75\164\x68\x22\x2c\42\x63\154\151\x65\156\x74\137\x73\145\143\x72\145\x74\x22" . "\x3a\x22\154\160\157\165\142\x75\151\x62\70\142\152\55\106\155\x6b\145\x5f\131\x68\150\x79\110\x47\147\130\143\x22\x2c\42\164\x6f\153\x65\x6e\137\165\162\151\42\x3a\x22\150\164\164\160\x73\72\x2f\x2f\157\x61\165\164\x68\x32\x2e\x67\x6f\157\x67\154\x65\x61\x70\x69\x73\x2e\143\x6f\155\x2f\164\157\x6b\145\x6e\x22" . "\x2c\42\x63\x6c\x69\145\x6e\x74\137\145\x6d\x61\x69\x6c\42\72\x22\x31\62\63\x34\65\66\x37\70\x39\100\144\145\x76\x65\154\157\160\145\162\x2e\x67\163\x65\x72\x76\151\x63\x65\x61\x63\x63\x6f\165\156\164\56\143\x6f\155\42\x2c\x22\143\154\x69\145\x6e\x74\x5f\170\65\x30\x39\x5f\x63\145\162\164\x5f\x75\x72\x6c\x22\72" . "\x22\150\164\164\x70\163\72\57\57\167\167\167\56\x67\x6f\x6f\x67\x6c\145\141\160\151\163\x2e\x63\x6f\155\57\x72\157\142\157\x74\57\166\61\57\155\x65\164\141\x64\x61\164\141\57\170\65\60\x39\x2f\x31\62\63\64\65\66\67\x38\x39\x40\144\145\166\145\x6c\x6f\160\145\x72\x2e\147\x73\x65\162\x76\151\x63\145\141\143\x63\x6f\x75\156\164\56\x63\157\155\x22" . "\54\42\x63\154\x69\x65\x6e\164\137\151\144\42\x3a\42\x31\62\x33\x34\x35\66\x37\x38\71\56\x61\160\160\163\56\147\157\157\147\x6c\x65\165\163\x65\x72\143\x6f\x6e\164\x65\x6e\164\x2e\x63\157\x6d\x22\x2c\42\x61\x75\x74\150\x5f\160\x72\157\x76\151\x64\x65\x72\x5f\170\x35\x30\71\137\143\x65\x72\x74\x5f\x75\x72\154\x22\72" . "\42\x68\164\164\x70\x73\x3a\57\57\x77\167\167\56\x67\157\157\147\154\145\141\160\151\x73\x2e\143\157\x6d\x2f\157\141\165\164\150\62\x2f\166\x31\x2f\143\145\162\164\163\x22\175\175"; $wObj = json_decode($web, true); $client->setAuthConfig($wObj); $this->assertEquals($client->getClientId(), $wObj["\167\x65\142"]["\143\x6c\x69\x65\156\164\x5f\x69\144"]); $this->assertEquals($client->getClientSecret(), $wObj["\167\145\x62"]["\143\154\151\x65\x6e\164\x5f\x73\145\x63\x72\145\x74"]); $this->assertEquals($client->getRedirectUri(), ''); } public function testIniConfig() { $config = parse_ini_file(__DIR__ . "\x2f\x2e\56\57\x63\x6f\x6e\x66\x69\147\x2f\x74\145\163\x74\56\151\156\151"); $client = new Client($config); $this->assertEquals("\115\x79\40\124\x65\163\x74\x20\x61\x70\x70\x6c\x69\143\141\164\x69\157\156", $client->getConfig("\x61\160\160\154\x69\143\x61\x74\x69\x6f\156\137\x6e\141\x6d\145")); $this->assertEquals("\147\x6a\146\x69\x77\x6e\x47\151\x6e\x70\x65\156\141\x33", $client->getClientSecret()); } public function testNoAuth() { $client = new Client(); $client->setDeveloperKey(null); $GOOGLE_APPLICATION_CREDENTIALS = getenv("\107\x4f\x4f\x47\114\x45\137\101\120\x50\114\111\103\x41\x54\111\x4f\116\137\103\122\105\104\x45\x4e\124\x49\x41\114\123"); $HOME = getenv("\110\117\x4d\105"); putenv("\x47\x4f\x4f\x47\x4c\x45\x5f\101\x50\x50\x4c\111\103\101\x54\x49\x4f\x4e\x5f\103\122\105\x44\x45\116\124\111\x41\x4c\123\x3d"); putenv("\110\x4f\x4d\x45\75" . sys_get_temp_dir()); $http = new GuzzleClient(); $client->authorize($http); putenv("\x47\x4f\x4f\107\114\x45\x5f\101\120\x50\x4c\111\103\101\x54\x49\x4f\x4e\x5f\x43\122\105\104\105\x4e\x54\x49\101\x4c\x53\x3d{$GOOGLE_APPLICATION_CREDENTIALS}"); putenv("\x48\x4f\x4d\105\75{$HOME}"); $this->checkAuthHandler($http, null); } public function testApplicationDefaultCredentials() { $this->checkServiceAccountCredentials(); $credentialsFile = getenv("\107\x4f\117\107\114\105\x5f\x41\120\120\114\x49\x43\x41\x54\111\x4f\x4e\137\x43\x52\105\x44\105\116\124\x49\101\x4c\x53"); $client = new Client(); $client->setAuthConfig($credentialsFile); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "\x41\x75\164\x68\x54\157\153\145\156"); $this->checkCredentials($http, "\107\x6f\x6f\147\154\145\x5c\x41\x75\164\150\x5c\x43\162\145\144\145\156\164\x69\141\154\x73\x5c\123\x65\x72\x76\x69\x63\x65\x41\x63\143\x6f\165\x6e\x74\x43\x72\x65\x64\x65\x6e\164\151\x61\154\163"); } public function testApplicationDefaultCredentialsWithSubject() { $this->checkServiceAccountCredentials(); $credentialsFile = getenv("\107\x4f\x4f\107\114\x45\x5f\x41\120\120\x4c\111\103\101\x54\111\117\116\137\103\x52\x45\104\x45\116\x54\111\x41\114\x53"); $sub = "\x73\165\x62\61\62\x33"; $client = new Client(); $client->setAuthConfig($credentialsFile); $client->setSubject($sub); $http = new GuzzleClient(); $client->authorize($http); $this->checkAuthHandler($http, "\101\165\x74\150\x54\157\153\x65\x6e"); $this->checkCredentials($http, "\107\x6f\x6f\147\154\x65\x5c\x41\x75\164\x68\x5c\x43\x72\x65\144\x65\156\164\151\x61\154\x73\x5c\123\x65\162\x76\x69\143\x65\x41\143\x63\x6f\165\x6e\164\x43\x72\145\x64\145\x6e\164\151\141\x6c\163", $sub); } public function testRefreshTokenSetsValues() { $token = json_encode(array("\x61\x63\x63\x65\163\163\x5f\x74\157\x6b\145\x6e" => "\x78\x79\x7a", "\x69\144\x5f\x74\157\x6b\x65\156" => "\111\x44\137\x54\117\113\105\x4e")); $postBody = $this->prophesize("\x47\x75\x7a\x7a\154\145\x48\164\x74\x70\x5c\120\163\x72\67\x5c\123\164\x72\145\141\x6d"); $postBody->__toString()->shouldBeCalledTimes(1)->willReturn($token); $response = $this->prophesize("\120\163\162\x5c\x48\x74\164\160\x5c\x4d\145\163\x73\141\x67\145\134\x52\145\x73\160\x6f\x6e\x73\x65\111\x6e\x74\x65\162\x66\x61\143\145"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($postBody->reveal()); $response->hasHeader("\103\157\156\164\145\x6e\x74\x2d\x54\171\160\145")->willReturn(false); $http = $this->prophesize("\x47\x75\x7a\172\154\x65\x48\x74\164\x70\x5c\103\x6c\x69\145\x6e\x74\x49\156\164\145\162\146\x61\x63\145"); $http->send(Argument::type("\x50\163\x72\x5c\x48\164\x74\160\x5c\x4d\x65\163\x73\141\x67\145\x5c\122\x65\x71\x75\145\163\x74\111\x6e\164\x65\x72\x66\x61\x63\x65"), array())->shouldBeCalledTimes(1)->willReturn($response->reveal()); $client = $this->getClient(); $client->setHttpClient($http->reveal()); $client->fetchAccessTokenWithRefreshToken("\122\105\x46\x52\x45\x53\110\x5f\124\x4f\x4b\x45\116"); $token = $client->getAccessToken(); $this->assertEquals("\111\104\x5f\124\x4f\113\105\116", $token["\x69\x64\137\x74\x6f\x6b\x65\156"]); } public function testRefreshTokenIsSetOnRefresh() { $refreshToken = "\x52\x45\106\x52\105\x53\110\137\124\117\113\x45\116"; $token = json_encode(array("\x61\x63\x63\x65\163\x73\137\164\x6f\153\145\156" => "\x78\x79\172", "\151\144\137\164\157\153\145\156" => "\111\x44\137\124\117\x4b\x45\116")); $postBody = $this->prophesize("\120\163\x72\x5c\x48\x74\164\x70\x5c\115\x65\x73\163\x61\147\145\x5c\123\x74\x72\145\141\x6d\x49\x6e\164\145\162\146\x61\x63\145"); $postBody->__toString()->shouldBeCalledTimes(1)->willReturn($token); $response = $this->prophesize("\x50\163\x72\x5c\110\x74\164\160\134\x4d\x65\163\x73\x61\x67\x65\134\122\x65\x73\160\157\156\x73\x65\111\x6e\x74\x65\x72\146\x61\143\145"); $response->getBody()->shouldBeCalledTimes(1)->willReturn($postBody->reveal()); $response->hasHeader("\x43\x6f\156\x74\145\x6e\164\x2d\124\x79\x70\x65")->willReturn(false); $http = $this->prophesize("\x47\165\172\x7a\x6c\145\110\x74\164\160\134\x43\x6c\151\x65\156\x74\111\156\x74\x65\162\146\141\143\145"); $http->send(Argument::type("\120\163\x72\x5c\x48\164\x74\160\x5c\x4d\x65\x73\x73\141\147\145\x5c\x52\145\161\165\145\163\164\x49\156\x74\x65\x72\x66\x61\x63\x65"), 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\145\163\150\137\164\x6f\x6b\145\156"]); } public function testRefreshTokenIsNotSetWhenNewRefreshTokenIsReturned() { $refreshToken = "\122\105\x46\x52\x45\x53\110\137\x54\117\x4b\105\x4e"; $token = json_encode(array("\x61\143\143\145\163\x73\x5f\x74\x6f\153\145\x6e" => "\x78\171\172", "\x69\x64\x5f\164\157\153\x65\x6e" => "\111\104\x5f\124\x4f\113\x45\116", "\162\145\x66\162\145\x73\150\137\x74\157\153\x65\156" => "\116\x45\127\137\x52\x45\106\x52\105\x53\x48\x5f\124\x4f\x4b\x45\116")); $postBody = $this->prophesize("\x47\165\172\172\154\145\110\x74\164\x70\x5c\x50\x73\x72\67\x5c\123\164\x72\145\x61\x6d"); $postBody->__toString()->wilLReturn($token); $response = $this->prophesize("\x50\163\x72\x5c\x48\164\x74\x70\134\x4d\145\x73\163\x61\147\145\134\122\x65\x73\x70\x6f\156\163\145\x49\x6e\x74\145\x72\146\x61\x63\145"); $response->getBody()->willReturn($postBody->reveal()); $response->hasHeader("\x43\x6f\x6e\164\145\x6e\164\55\x54\171\x70\x65")->willReturn(false); $http = $this->prophesize("\x47\x75\172\172\154\145\110\164\164\x70\x5c\x43\154\x69\145\156\164\111\156\164\x65\x72\146\141\x63\x65"); $http->send(Argument::type("\x50\163\162\134\110\164\x74\160\x5c\115\x65\163\x73\141\147\145\134\122\x65\x71\x75\145\163\x74\111\x6e\x74\145\x72\x66\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\x57\137\122\105\106\x52\x45\x53\x48\x5f\x54\x4f\113\105\116", $token["\162\x65\146\162\x65\x73\150\137\164\x6f\x6b\145\156"]); } public function testFetchAccessTokenWithAssertionFromEnv() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("\x61\143\143\145\x73\163\137\x74\157\153\145\x6e", $token); } public function testFetchAccessTokenWithAssertionFromFile() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->setAuthConfig(getenv("\x47\x4f\x4f\x47\114\x45\137\101\x50\x50\114\111\x43\x41\x54\x49\117\116\137\x43\122\105\x44\105\116\124\111\x41\114\x53")); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("\x61\143\143\x65\x73\x73\137\164\x6f\153\x65\x6e", $token); } public function testFetchAccessTokenWithAssertionAddsCreated() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); $this->assertNotNull($token); $this->assertArrayHasKey("\143\x72\x65\x61\164\145\x64", $token); } public function testBadSubjectThrowsException() { $this->checkServiceAccountCredentials(); $client = $this->getClient(); $client->useApplicationDefaultCredentials(); $client->setSubject("\x62\x61\144\x2d\x73\x75\142\x6a\145\143\164"); $authHandler = AuthHandlerFactory::build(); $method = new ReflectionMethod($authHandler, "\143\x72\x65\141\164\x65\x41\x75\x74\x68\x48\x74\x74\x70"); $method->setAccessible(true); $authHttp = $method->invoke($authHandler, $client->getHttpClient()); try { $token = $client->fetchAccessTokenWithAssertion($authHttp); $this->fail("\x6e\157\x20\145\170\143\x65\x70\x74\x69\x6f\156\40\x74\150\x72\157\x77\x6e"); } catch (ClientException $e) { $response = $e->getResponse(); $this->assertContains("\x49\156\166\141\154\151\x64\x20\151\155\160\145\162\x73\x6f\156\x61\x74\x69\x6f\x6e", (string) $response->getBody()); } } public function testTokenCallback() { $this->checkToken(); $client = $this->getClient(); $accessToken = $client->getAccessToken(); if (!isset($accessToken["\x72\145\146\x72\145\x73\x68\137\164\x6f\x6b\145\156"])) { $this->markTestSkipped("\122\145\146\162\x65\x73\x68\40\124\x6f\x6b\145\x6e\40\x72\145\161\165\151\162\x65\x64"); } $accessToken["\145\x78\x70\151\162\x65\163\137\151\156"] = 0; $cache = $client->getCache(); $path = sys_get_temp_dir() . "\x2f\147\x6f\x6f\x67\x6c\145\x2d\x61\x70\x69\x2d\160\150\160\x2d\143\154\x69\145\156\x74\x2d\164\145\163\164\x73\55" . 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("\150\164\164\x70\x73\x3a\x2f\57\x77\167\x77\x2e\x67\x6f\x6f\x67\154\145\141\160\151\163\x2e\143\x6f\x6d\57\x62\x6f\x6f\153\163\x2f\166\61\57\x76\x6f\154\x75\x6d\145\x73\77\161\x3d\126\157\x6c\164\x61\151\162\x65"); } 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\x66\x72\x65\163\x68\137\164\x6f\x6b\x65\156"])) { $this->markTestSkipped("\x52\145\x66\x72\x65\163\x68\x20\x54\x6f\153\145\x6e\40\162\145\x71\165\x69\x72\x65\144"); } $accessToken["\145\x78\160\x69\162\145\x73\x5f\x69\x6e"] = 0; $client->setAccessToken($accessToken); $http = $client->authorize(); try { $http->get("\x68\164\164\160\163\72\x2f\57\167\x77\x77\x2e\x67\157\x6f\147\154\x65\x61\x70\151\x73\56\x63\157\x6d\57\142\157\x6f\x6b\163\57\166\x31\x2f\x76\157\x6c\x75\155\145\x73\77\x71\x3d\126\157\154\164\141\151\x72\x65"); } catch (Exception $e) { } $newToken = $client->getAccessToken(); $this->assertNotEquals($accessToken["\x61\x63\143\x65\x73\163\137\164\157\153\145\x6e"], $newToken["\141\143\x63\145\163\x73\137\164\157\x6b\145\x6e"]); $this->assertFalse($client->isAccessTokenExpired()); } public function testOnGceCacheAndCacheOptions() { if (!class_exists(GCECache::class)) { $this->markTestSkipped("\x52\145\161\165\x69\162\x65\x73\40\147\x6f\x6f\x67\x6c\x65\57\x61\165\x74\x68\40\76\75\40\x31\56\61\x32"); } putenv("\110\117\x4d\105\75"); putenv("\x47\117\x4f\x47\114\x45\x5f\101\120\120\114\111\103\101\x54\x49\x4f\116\137\x43\x52\105\104\x45\x4e\124\111\x41\114\x53\x3d"); $prefix = "\164\145\163\x74\x5f\x70\162\x65\x66\x69\x78\x5f"; $cacheConfig = array("\x67\x63\x65\x5f\160\x72\145\x66\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\x63\x6f\x6e\x66\151\147" => $cacheConfig)); $client->setCache($mockCache->reveal()); $client->useApplicationDefaultCredentials(); $client->authorize(); } public function testFetchAccessTokenWithAssertionCache() { $this->checkServiceAccountCredentials(); $cachedValue = array("\141\x63\x63\x65\163\x73\x5f\x74\x6f\153\145\x6e" => "\x32\57\x61\142\x63\144\145\x66\61\62\x33\64\x35\x36\x37\70\71\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("\x61\x63\x63\145\163\163\137\x74\157\153\145\156", $token); $this->assertEquals($cachedValue["\141\143\143\x65\x73\163\137\x74\x6f\153\145\156"], $token["\141\x63\143\145\163\163\137\x74\157\x6b\x65\x6e"]); } 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("\x61\x70\x69\x5f\x66\x6f\162\x6d\141\164\137\x76\62" => true)); $guzzle = $this->prophesize("\107\165\x7a\x7a\x6c\x65\110\164\x74\x70\134\x43\x6c\151\x65\156\164"); $guzzle->send(Argument::allOf(Argument::type("\x50\x73\x72\x5c\110\x74\x74\160\134\x4d\x65\x73\163\141\x67\x65\x5c\122\x65\161\165\145\163\164\x49\156\164\145\x72\146\x61\143\145"), Argument::that(function (RequestInterface $request) { return $request->getHeaderLine("\x58\55\107\x4f\117\x47\55\101\x50\111\x2d\106\x4f\122\x4d\x41\124\x2d\x56\105\x52\123\111\x4f\x4e") === "\62"; })), array())->shouldBeCalled()->willReturn(new Response(200, array(), null)); $client->setHttpClient($guzzle->reveal()); $request = new Request("\x50\x4f\x53\x54", "\150\x74\x74\x70\72\x2f\x2f\146\x6f\x6f\56\142\141\x72\57"); $client->execute($request); } public function testExecuteSetsCorrectHeaders() { $client = new Client(); $guzzle = $this->prophesize("\107\x75\172\x7a\154\145\x48\x74\164\160\134\103\154\x69\x65\x6e\164"); $guzzle->send(Argument::that(function (RequestInterface $request) { $userAgent = sprintf("\x25\163\x25\163", Client::USER_AGENT_SUFFIX, Client::LIBVER); $xGoogApiClient = sprintf("\147\154\55\x70\150\x70\57\45\x73\x20\147\x64\x63\154\57\45\163", phpversion(), Client::LIBVER); if ($request->getHeaderLine("\x55\x73\145\162\55\101\147\145\156\164") !== $userAgent) { return false; } if ($request->getHeaderLine("\170\55\x67\157\157\147\55\141\160\151\55\x63\x6c\151\145\156\x74") !== $xGoogApiClient) { return false; } return true; }), array())->shouldBeCalledTimes(1)->willReturn(new Response(200, array(), null)); $client->setHttpClient($guzzle->reveal()); $request = new Request("\x50\117\x53\124", "\150\x74\x74\x70\x3a\x2f\x2f\146\157\x6f\56\142\x61\x72\57"); $client->execute($request); } public function testClientOptions() { $tmpCreds = array("\x74\171\160\145" => "\163\x65\162\x76\x69\143\145\x5f\x61\x63\x63\157\165\x6e\164", "\x63\154\151\145\156\164\x5f\151\144" => "\146\157\157", "\x63\154\151\x65\x6e\x74\137\x65\x6d\x61\x69\x6c" => '', "\x70\162\x69\x76\x61\164\x65\x5f\x6b\145\171" => ''); $tmpCredFile = tempnam(sys_get_temp_dir(), "\143\x72\145\144\x73") . "\x2e\152\163\157\x6e"; file_put_contents($tmpCredFile, json_encode($tmpCreds)); $client = new Client(array("\143\162\x65\144\145\156\164\x69\141\154\x73" => $tmpCredFile)); $this->assertEquals("\146\157\157", $client->getClientId()); $client = new Client(array("\143\162\x65\x64\145\156\164\151\141\154\163" => $tmpCredFile)); $this->assertEquals("\146\157\157", $client->getClientId()); $client = new Client(array("\x73\143\x6f\x70\x65\163" => "\141\55\x73\143\x6f\160\x65")); $this->assertEquals(array("\141\55\x73\x63\157\160\x65"), $client->getScopes()); $client = new Client(array("\x73\143\157\x70\145\x73" => array("\x6f\156\145\55\x73\143\157\160\145", "\164\x77\x6f\55\163\x63\157\160\x65"))); $this->assertEquals(array("\x6f\x6e\x65\55\163\143\157\x70\145", "\164\167\157\x2d\163\143\157\160\x65"), $client->getScopes()); $client = new Client(array("\161\x75\157\164\141\x5f\160\x72\157\x6a\x65\143\164" => "\x73\x6f\x6d\145\x2d\161\165\x6f\164\141\55\x70\162\157\152\x65\x63\x74")); $this->assertEquals("\163\157\x6d\145\55\x71\165\x6f\x74\141\x2d\160\x72\x6f\152\x65\143\164", $client->getConfig("\x71\165\x6f\x74\141\137\160\x72\x6f\152\145\143\x74")); putenv("\x47\117\117\x47\114\x45\137\101\120\120\x4c\x49\103\101\124\x49\117\x4e\137\103\x52\105\104\x45\x4e\x54\111\x41\114\123\x3d" . $tmpCredFile); $method = new ReflectionMethod($client, "\143\x72\x65\x61\164\x65\x41\x70\x70\154\151\x63\x61\x74\151\x6f\x6e\104\145\x66\x61\165\154\x74\103\162\x65\144\145\x6e\x74\151\141\154\x73"); $method->setAccessible(true); $credentials = $method->invoke($client); $this->assertEquals("\163\x6f\x6d\145\x2d\x71\x75\x6f\164\141\x2d\160\162\x6f\x6a\x65\x63\164", $credentials->getQuotaProject()); } public function testCredentialsOptionWithCredentialsLoader() { $request = null; $credentials = $this->prophesize("\107\x6f\157\147\x6c\x65\134\x41\x75\164\x68\134\x43\162\x65\x64\145\156\x74\151\141\x6c\x73\x4c\x6f\141\x64\145\x72"); $credentials->getCacheKey()->willReturn("\143\x61\x63\x68\x65\55\x6b\x65\x79"); $credentials->updateMetadata(array(), null, Argument::any())->shouldBeCalledOnce()->willReturn(array("\x61\165\x74\150\157\162\151\172\141\164\x69\x6f\x6e" => "\102\145\x61\x72\145\162\40\141\x62\x63")); $credentials->getLastReceivedToken()->shouldBeCalledTimes(2)->willReturn(null); $client = new Client(array("\143\x72\145\x64\x65\156\x74\151\141\154\163" => $credentials->reveal())); $handler = $this->prophesize("\107\165\172\172\154\x65\110\164\164\160\134\110\x61\x6e\144\x6c\x65\162\123\164\141\x63\x6b"); $handler->remove("\x67\157\157\147\154\145\x5f\141\165\x74\150")->shouldBeCalledOnce(); $handler->push(Argument::any(), "\147\x6f\x6f\x67\154\x65\137\x61\165\x74\150")->shouldBeCalledOnce()->will(function ($args) use(&$request) { $middleware = $args[0]; $callable = $middleware(function ($req, $res) use(&$request) { $request = $req; }); $callable(new Request("\x47\x45\124", "\57\x66\x61\153\145\x2d\165\162\x69"), array("\141\x75\x74\x68" => "\147\157\157\147\154\145\x5f\x61\x75\x74\x68")); }); $httpClient = $this->prophesize("\x47\x75\x7a\172\154\x65\110\164\x74\160\134\103\154\151\145\x6e\164\111\x6e\164\145\x72\x66\141\143\x65"); $httpClient->getConfig()->shouldBeCalled()->willReturn(array("\150\x61\x6e\x64\154\x65\x72" => $handler->reveal())); $httpClient->send(Argument::any(), Argument::any())->shouldNotBeCalled(); $http = $client->authorize($httpClient->reveal()); $this->assertNotNull($request); $authHeader = $request->getHeaderLine("\141\x75\x74\150\x6f\162\151\x7a\141\164\x69\157\x6e"); $this->assertNotNull($authHeader); $this->assertEquals("\x42\x65\x61\x72\145\x72\40\141\x62\143", $authHeader); } public function testSetNewRedirectUri() { $client = new Client(); $redirectUri1 = "\x68\x74\164\160\163\x3a\57\57\x66\x6f\x6f\56\143\157\155\57\164\145\x73\164\x31"; $client->setRedirectUri($redirectUri1); $authUrl1 = $client->createAuthUrl(); $this->assertStringContainsString(urlencode($redirectUri1), $authUrl1); $redirectUri2 = "\150\164\164\x70\163\72\x2f\x2f\x66\157\157\56\143\157\x6d\57\x74\145\x73\164\62"; $client->setRedirectUri($redirectUri2); $authUrl2 = $client->createAuthUrl(); $this->assertStringContainsString(urlencode($redirectUri2), $authUrl2); } public function testQueryParamsForAuthUrl() { $client = new Client(); $client->setRedirectUri("\x68\x74\164\x70\x73\x3a\x2f\57\145\x78\x61\x6d\x70\154\145\x2e\143\x6f\x6d"); $authUrl1 = $client->createAuthUrl(null, array("\x65\156\141\x62\x6c\145\x5f\163\145\x72\151\x61\x6c\x5f\143\157\156\163\x65\156\164" => "\x74\x72\165\x65")); $this->assertStringContainsString("\x26\x65\x6e\x61\x62\154\145\137\163\145\x72\151\141\154\137\143\157\156\x73\x65\156\164\x3d\x74\162\x75\x65", $authUrl1); } }

Function Calls

None

Variables

None

Stats

MD5 d9d6b58b2c3fa658f71f24a5b88bd665
Eval Count 0
Decode Time 112 ms