Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function provideCertsFromUrl()

public function testRetrieveCertsFromLocationLocalFile()
{
$certsLocation = __DIR__ . '/fixtures/federated-certs.json';
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs.json';
$certsData = json_decode(file_get_contents($certsLocation), true);

$item = $this->prophesize('Psr\Cache\CacheItemInterface');
Expand Down Expand Up @@ -336,7 +336,7 @@ public function testRetrieveCertsFromLocationLocalFileInvalidFilePath()
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Failed to retrieve verification certificates from path');

$certsLocation = __DIR__ . '/fixtures/federated-certs-does-not-exist.json';
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs-does-not-exist.json';

$item = $this->prophesize('Psr\Cache\CacheItemInterface');
$item->get()
Expand Down Expand Up @@ -409,7 +409,7 @@ public function testRetrieveCertsFromLocationLocalFileInvalidFileData()

public function testRetrieveCertsFromLocationRespectsCacheControl()
{
$certsLocation = __DIR__ . '/fixtures/federated-certs.json';
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs.json';
$certsJson = file_get_contents($certsLocation);
$certsData = json_decode($certsJson, true);

Expand Down Expand Up @@ -454,7 +454,7 @@ public function testRetrieveCertsFromLocationRespectsCacheControl()

public function testRetrieveCertsFromLocationRemote()
{
$certsLocation = __DIR__ . '/fixtures/federated-certs.json';
$certsLocation = __DIR__ . '/fixtures/fixtures1/federated-certs.json';
$certsJson = file_get_contents($certsLocation);
$certsData = json_decode($certsJson, true);

Expand Down
54 changes: 27 additions & 27 deletions tests/ApplicationDefaultCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public function testGetCredentialsFailsIfEnvSpecifiesNonExistentFile()
{
$this->expectException(DomainException::class);

$keyFile = __DIR__ . '/fixtures' . '/does-not-exist-private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/does-not-exist-private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
ApplicationDefaultCredentials::getCredentials('a scope');
}

public function testLoadsOKIfEnvSpecifiedIsValid()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$this->assertNotNull(
ApplicationDefaultCredentials::getCredentials('a scope')
Expand All @@ -70,7 +70,7 @@ public function testLoadsOKIfEnvSpecifiedIsValid()

public function testLoadsDefaultFileIfPresentAndEnvVarIsNotSet()
{
setHomeEnv(__DIR__ . '/fixtures');
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
$this->assertNotNull(
ApplicationDefaultCredentials::getCredentials('a scope')
);
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testGceCredentials()

public function testImpersonatedServiceAccountCredentials()
{
setHomeEnv(__DIR__ . '/fixtures5');
setHomeEnv(__DIR__ . '/fixtures/fixtures5');
$creds = ApplicationDefaultCredentials::getCredentials(
null,
null,
Expand All @@ -181,7 +181,7 @@ public function testImpersonatedServiceAccountCredentials()

public function testUserRefreshCredentials()
{
setHomeEnv(__DIR__ . '/fixtures2');
setHomeEnv(__DIR__ . '/fixtures/fixtures2');

$creds = ApplicationDefaultCredentials::getCredentials(
null, // $scope
Expand Down Expand Up @@ -216,7 +216,7 @@ public function testUserRefreshCredentials()

public function testServiceAccountCredentials()
{
setHomeEnv(__DIR__ . '/fixtures');
setHomeEnv(__DIR__ . '/fixtures/fixtures1');

$creds = ApplicationDefaultCredentials::getCredentials(
null, // $scope
Expand Down Expand Up @@ -251,7 +251,7 @@ public function testServiceAccountCredentials()

public function testDefaultScopeArray()
{
setHomeEnv(__DIR__ . '/fixtures2');
setHomeEnv(__DIR__ . '/fixtures/fixtures2');

$creds = ApplicationDefaultCredentials::getCredentials(
null, // $scope
Expand All @@ -273,21 +273,21 @@ public function testGetMiddlewareFailsIfEnvSpecifiesNonExistentFile()
{
$this->expectException(DomainException::class);

$keyFile = __DIR__ . '/fixtures' . '/does-not-exist-private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/does-not-exist-private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
ApplicationDefaultCredentials::getMiddleware('a scope');
}

public function testGetMiddlewareLoadsOKIfEnvSpecifiedIsValid()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$this->assertNotNull(ApplicationDefaultCredentials::getMiddleware('a scope'));
}

public function testLGetMiddlewareoadsDefaultFileIfPresentAndEnvVarIsNotSet()
{
setHomeEnv(__DIR__ . '/fixtures');
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
$this->assertNotNull(ApplicationDefaultCredentials::getMiddleware('a scope'));
}

Expand All @@ -309,7 +309,7 @@ public function testGetMiddlewareFailsIfNotOnGceAndNoDefaultFileFound()

public function testGetMiddlewareWithCacheOptions()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$httpHandler = getHandler([
Expand Down Expand Up @@ -452,14 +452,14 @@ public function testGetIdTokenCredentialsFailsIfEnvSpecifiesNonExistentFile()
{
$this->expectException(DomainException::class);

$keyFile = __DIR__ . '/fixtures' . '/does-not-exist-private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/does-not-exist-private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
ApplicationDefaultCredentials::getIdTokenCredentials($this->targetAudience);
}

public function testGetIdTokenCredentialsLoadsOKIfEnvSpecifiedIsValid()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$creds = ApplicationDefaultCredentials::getIdTokenCredentials($this->targetAudience);
Expand All @@ -468,7 +468,7 @@ public function testGetIdTokenCredentialsLoadsOKIfEnvSpecifiedIsValid()

public function testGetIdTokenCredentialsLoadsDefaultFileIfPresentAndEnvVarIsNotSet()
{
setHomeEnv(__DIR__ . '/fixtures');
setHomeEnv(__DIR__ . '/fixtures/fixtures1');
$creds = ApplicationDefaultCredentials::getIdTokenCredentials($this->targetAudience);
$this->assertInstanceOf(ServiceAccountCredentials::class, $creds);
}
Expand All @@ -495,14 +495,14 @@ public function testGetIdTokenCredentialsFailsIfNotOnGceAndNoDefaultFileFound()

public function testGetIdTokenCredentialsWithImpersonatedServiceAccountCredentials()
{
setHomeEnv(__DIR__ . '/fixtures5');
setHomeEnv(__DIR__ . '/fixtures/fixtures5');
$creds = ApplicationDefaultCredentials::getIdTokenCredentials('123@456.com');
$this->assertInstanceOf(ImpersonatedServiceAccountCredentials::class, $creds);
}

public function testGetIdTokenCredentialsWithCacheOptions()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$httpHandler = getHandler([
Expand Down Expand Up @@ -548,7 +548,7 @@ public function testGetIdTokenCredentialsSuccedsIfNoDefaultFilesButIsOnGCE()

public function testGetIdTokenCredentialsWithUserRefreshCredentials()
{
setHomeEnv(__DIR__ . '/fixtures2');
setHomeEnv(__DIR__ . '/fixtures/fixtures2');

$creds = ApplicationDefaultCredentials::getIdTokenCredentials(
$this->targetAudience,
Expand All @@ -567,7 +567,7 @@ public function testGetIdTokenCredentialsWithUserRefreshCredentials()

public function testWithServiceAccountCredentialsAndExplicitQuotaProject()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$credentials = ApplicationDefaultCredentials::getCredentials(
Expand All @@ -588,7 +588,7 @@ public function testWithServiceAccountCredentialsAndExplicitQuotaProject()

public function testGetCredentialsUtilizesQuotaProjectInKeyFile()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$credentials = ApplicationDefaultCredentials::getCredentials();
Expand All @@ -604,7 +604,7 @@ public function testGetCredentialsUtilizesQuotaProjectEnvVar()
{
$quotaProject = 'quota-project-from-env-var';
putenv(CredentialsLoader::QUOTA_PROJECT_ENV_VAR . '=' . $quotaProject);
setHomeEnv(__DIR__ . '/fixtures');
setHomeEnv(__DIR__ . '/fixtures/fixtures1');

$credentials = ApplicationDefaultCredentials::getCredentials();

Expand All @@ -619,7 +619,7 @@ public function testGetCredentialsUtilizesQuotaProjectParameterOverEnvVar()
{
$quotaProject = 'quota-project-from-parameter';
putenv(CredentialsLoader::QUOTA_PROJECT_ENV_VAR . '=quota-project-from-env-var');
setHomeEnv(__DIR__ . '/fixtures');
setHomeEnv(__DIR__ . '/fixtures/fixtures1');

$credentials = ApplicationDefaultCredentials::getCredentials(
null, // $scope
Expand All @@ -640,7 +640,7 @@ public function testGetCredentialsUtilizesQuotaProjectParameterOverEnvVar()
public function testGetCredentialsUtilizesQuotaProjectEnvVarOverKeyFile()
{
$quotaProject = 'quota-project-from-env-var';
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(CredentialsLoader::QUOTA_PROJECT_ENV_VAR . '=' . $quotaProject);
putenv(CredentialsLoader::ENV_VAR . '=' . $keyFile);

Expand All @@ -654,7 +654,7 @@ public function testGetCredentialsUtilizesQuotaProjectEnvVarOverKeyFile()

public function testWithFetchAuthTokenCacheAndExplicitQuotaProject()
{
$keyFile = __DIR__ . '/fixtures' . '/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);

$httpHandler = getHandler([
Expand Down Expand Up @@ -756,7 +756,7 @@ public function testAppEngineFlexibleIdToken()
*/
public function testExternalAccountCredentials(string $jsonFile, string $expectedCredSource)
{
putenv(sprintf('GOOGLE_APPLICATION_CREDENTIALS=%s/fixtures6/%s', __DIR__, $jsonFile));
putenv(sprintf('GOOGLE_APPLICATION_CREDENTIALS=%s/fixtures/fixtures6/%s', __DIR__, $jsonFile));

$creds = ApplicationDefaultCredentials::getCredentials('a_scope');

Expand Down Expand Up @@ -827,19 +827,19 @@ public function provideExternalAccountCredentials()
public function testUniverseDomainInKeyFile()
{
// Test no universe domain in keyfile defaults to "googleapis.com"
$keyFile = __DIR__ . '/fixtures3/service_account_credentials.json';
$keyFile = __DIR__ . '/fixtures/fixtures3/service_account_credentials.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$creds = ApplicationDefaultCredentials::getCredentials();
$this->assertEquals(CredentialsLoader::DEFAULT_UNIVERSE_DOMAIN, $creds->getUniverseDomain());

// Test universe domain in "service_account" keyfile
$keyFile = __DIR__ . '/fixtures/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$creds = ApplicationDefaultCredentials::getCredentials();
$this->assertEquals('example-universe.com', $creds->getUniverseDomain());

// Test universe domain in "authenticated_user" keyfile is not read.
$keyFile = __DIR__ . '/fixtures2/private.json';
$keyFile = __DIR__ . '/fixtures/fixtures2/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$creds2 = ApplicationDefaultCredentials::getCredentials();
$this->assertEquals(CredentialsLoader::DEFAULT_UNIVERSE_DOMAIN, $creds2->getUniverseDomain());
Expand Down
1 change: 0 additions & 1 deletion tests/Credentials/GCECredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public function testOnWindowsGceWithResidencyWithNoCom()
$method = (new ReflectionClass(GCECredentials::class))
->getMethod('detectResidencyWindows');


$this->assertFalse($method->invoke(null, 'thisShouldBeFalse'));
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Credentials/ServiceAccountCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function createTestJson()
'client_id' => 'client123',
'type' => 'service_account',
'project_id' => 'example_project',
'private_key' => file_get_contents(__DIR__ . '/../fixtures/private.pem'),
'private_key' => file_get_contents(__DIR__ . '/../fixtures/fixtures1/private.pem'),
];
}

Expand Down Expand Up @@ -138,13 +138,13 @@ public function testFailsToInitalizeFromANonExistentFile()
{
$this->expectException(InvalidArgumentException::class);

$keyFile = __DIR__ . '/../fixtures' . '/does-not-exist-private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/does-not-exist-private.json';
new ServiceAccountCredentials('scope/1', $keyFile);
}

public function testInitalizeFromAFile()
{
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
$this->assertNotNull(
new ServiceAccountCredentials('scope/1', $keyFile)
);
Expand Down Expand Up @@ -176,15 +176,15 @@ public function testIsNullIfEnvVarIsNotSet()
public function testFailsIfEnvSpecifiesNonExistentFile()
{
$this->expectException(DomainException::class);
$keyFile = __DIR__ . '/../fixtures' . '/does-not-exist-private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/does-not-exist-private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
ApplicationDefaultCredentials::getCredentials('a scope');
}

/** @runInSeparateProcess */
public function testSucceedIfFileExists()
{
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$this->assertNotNull(ApplicationDefaultCredentials::getCredentials('a scope'));
}
Expand All @@ -201,7 +201,7 @@ public function testIsNullIfFileDoesNotExist()
/** @runInSeparateProcess */
public function testSucceedIfFileIsPresent()
{
setHomeEnv(__DIR__ . '/../fixtures');
setHomeEnv(__DIR__ . '/../fixtures/fixtures1');
$this->assertNotNull(
ApplicationDefaultCredentials::getCredentials('a scope')
);
Expand Down Expand Up @@ -420,7 +420,7 @@ public function testGetProjectId()

public function testGetQuotaProject()
{
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
$sa = new ServiceAccountCredentials('scope/1', $keyFile);
$this->assertEquals('test_quota_project', $sa->getQuotaProject());
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Credentials/ServiceAccountJwtAccessCredentialsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ private function createTestJson()
'client_id' => 'client123',
'type' => 'service_account',
'project_id' => 'example_project',
'private_key' => file_get_contents(__DIR__ . '/../fixtures' . '/private.pem'),
'private_key' => file_get_contents(__DIR__ . '/../fixtures/fixtures1/private.pem'),
];
}

public function testFailsToInitalizeFromANonExistentFile()
{
$this->expectException(InvalidArgumentException::class);

$keyFile = __DIR__ . '/../fixtures' . '/does-not-exist-private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/does-not-exist-private.json';
new ServiceAccountJwtAccessCredentials($keyFile);
}

public function testInitalizeFromAFile()
{
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
$this->assertNotNull(
new ServiceAccountJwtAccessCredentials($keyFile)
);
Expand Down Expand Up @@ -392,7 +392,7 @@ public function testFetchAuthTokenWithScopeAndUseJwtAccessWithScopeParameterAndA
/** @runInSeparateProcess */
public function testAccessFromApplicationDefault()
{
$keyFile = __DIR__ . '/../fixtures3/service_account_credentials.json';
$keyFile = __DIR__ . '/../fixtures/fixtures3/service_account_credentials.json';
putenv(ServiceAccountCredentials::ENV_VAR . '=' . $keyFile);
$creds = ApplicationDefaultCredentials::getCredentials(
null, // $scope
Expand All @@ -408,7 +408,7 @@ public function testAccessFromApplicationDefault()

$this->assertArrayHasKey('authorization', $metadata);
$token = str_replace('Bearer ', '', $metadata['authorization'][0]);
$key = file_get_contents(__DIR__ . '/../fixtures3/key.pub');
$key = file_get_contents(__DIR__ . '/../fixtures/fixtures3/key.pub');
$result = JWT::decode($token, new Key($key, 'RS256'));

$this->assertEquals($authUri, $result->aud);
Expand Down Expand Up @@ -509,7 +509,7 @@ public function testGetProjectId()

public function testGetQuotaProject()
{
$keyFile = __DIR__ . '/../fixtures' . '/private.json';
$keyFile = __DIR__ . '/../fixtures/fixtures1/private.json';
$sa = new ServiceAccountJwtAccessCredentials($keyFile);
$this->assertEquals('test_quota_project', $sa->getQuotaProject());
}
Expand Down
Loading