Skip to content

Commit

Permalink
implement GetUniverseDomainInterface for credentials cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Oct 25, 2023
1 parent f5ece95 commit 0c47f37
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/FetchAuthTokenCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class FetchAuthTokenCache implements
FetchAuthTokenInterface,
GetQuotaProjectInterface,
GetUniverseDomainInterface,
SignBlobInterface,
ProjectIdProviderInterface,
UpdateMetadataInterface
Expand Down Expand Up @@ -191,6 +192,20 @@ public function getProjectId(callable $httpHandler = null)
return $this->fetcher->getProjectId($httpHandler);
}

/*
* Get the Universe Domain from the fetcher.
*
* @return string
*/
public function getUniverseDomain(): string
{
if ($this->fetcher instanceof GetUniverseDomainInterface) {
return $this->fetcher->getUniverseDomain();
}

return GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN;
}

/**
* Updates metadata with the authorization token.
*
Expand Down
36 changes: 36 additions & 0 deletions tests/FetchAuthTokenCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Google\Auth\Credentials\ServiceAccountCredentials;
use Google\Auth\CredentialsLoader;
use Google\Auth\FetchAuthTokenCache;
use Google\Auth\GetUniverseDomainInterface;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use RuntimeException;
Expand Down Expand Up @@ -603,6 +604,41 @@ public function testGetProjectIdInvalidFetcher()
$fetcher->getProjectId();
}

public function testGetUniverseDomain()
{
$universeDomain = 'foobar';

$mockFetcher = $this->prophesize('Google\Auth\GetUniverseDomainInterface');
$mockFetcher->willImplement('Google\Auth\FetchAuthTokenInterface');
$mockFetcher->getUniverseDomain()
->shouldBeCalled()
->willReturn($universeDomain);

$fetcher = new FetchAuthTokenCache(
$mockFetcher->reveal(),
[],
$this->mockCache->reveal()
);

$this->assertEquals($universeDomain, $fetcher->getUniverseDomain());
}

public function testGetUniverseDomainInvalidFetcher()
{
$mockFetcher = $this->prophesize('Google\Auth\FetchAuthTokenInterface');

$fetcher = new FetchAuthTokenCache(
$mockFetcher->reveal(),
[],
$this->mockCache->reveal()
);

$this->assertEquals(
GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN,
$fetcher->getUniverseDomain()
);
}

public function testGetFetcher()
{
$mockFetcher = $this->prophesize('Google\Auth\FetchAuthTokenInterface')
Expand Down

0 comments on commit 0c47f37

Please sign in to comment.