-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
use Google\Auth\CredentialsLoader; | ||
use Google\Auth\OAuth2; | ||
use GuzzleHttp\Psr7; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Response; | ||
use GuzzleHttp\Psr7\Utils; | ||
use InvalidArgumentException; | ||
|
@@ -307,6 +308,36 @@ public function testShouldBeIdTokenWhenTargetAudienceIsSet() | |
$this->assertEquals(1, $timesCalled); | ||
} | ||
|
||
public function testShouldUseIamWhenTargetAudienceAndUniverseDomainIsSet() | ||
{ | ||
$testJson = $this->createTestJson(); | ||
$testJson['universe_domain'] = 'abc.xyz'; | ||
|
||
$timesCalled = 0; | ||
$httpHandler = function (Request $request) use (&$timesCalled) { | ||
$timesCalled++; | ||
|
||
// Verify Request | ||
$this->assertStringContainsString(':generateIdToken', $request->getUri()); | ||
$json = json_decode($request->getBody(), true); | ||
$this->assertArrayHasKey('audience', $json); | ||
$this->assertEquals('a target audience', $json['audience']); | ||
|
||
// Verify JWT Bearer Token | ||
$jwt = str_replace('Bearer ', '', $request->getHeaderLine('Authorization')); | ||
list($header, $payload, $sig) = explode('.', $jwt); | ||
$jwtParams = json_decode(base64_decode($payload), true); | ||
$this->assertArrayHasKey('iss', $jwtParams); | ||
$this->assertEquals('[email protected]', $jwtParams['iss']); | ||
|
||
// return expected IAM ID token response | ||
return new Psr7\Response(200, [], json_encode(['token' => 'idtoken12345'])); | ||
}; | ||
$sa = new ServiceAccountCredentials(null, $testJson, null, 'a target audience'); | ||
$this->assertEquals('idtoken12345', $sa->fetchAuthToken($httpHandler)['id_token']); | ||
$this->assertEquals(1, $timesCalled); | ||
} | ||
|
||
public function testShouldBeOAuthRequestWhenSubIsSet() | ||
{ | ||
$testJson = $this->createTestJson(); | ||
|