-
Notifications
You must be signed in to change notification settings - Fork 307
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
1 parent
17d1d1b
commit 93340f7
Showing
7 changed files
with
65 additions
and
35 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
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 |
---|---|---|
|
@@ -789,7 +789,7 @@ def test_refresh_iam_flow(self, call_iam_generate_id_token_endpoint): | |
) | ||
request = mock.Mock() | ||
credentials.refresh(request) | ||
req, iam_endpoint, signer_email, target_audience, access_token = call_iam_generate_id_token_endpoint.call_args[ | ||
req, iam_endpoint, signer_email, target_audience, access_token, universe_domain = call_iam_generate_id_token_endpoint.call_args[ | ||
0 | ||
] | ||
assert req == request | ||
|
@@ -798,6 +798,7 @@ def test_refresh_iam_flow(self, call_iam_generate_id_token_endpoint): | |
assert target_audience == "https://example.com" | ||
decoded_access_token = jwt.decode(access_token, verify=False) | ||
assert decoded_access_token["scope"] == "https://www.googleapis.com/auth/iam" | ||
assert universe_domain == "googleapis.com" | ||
|
||
@mock.patch( | ||
"google.oauth2._client.call_iam_generate_id_token_endpoint", autospec=True | ||
|
@@ -811,18 +812,19 @@ def test_refresh_iam_flow_non_gdu(self, call_iam_generate_id_token_endpoint): | |
) | ||
request = mock.Mock() | ||
credentials.refresh(request) | ||
req, iam_endpoint, signer_email, target_audience, access_token = call_iam_generate_id_token_endpoint.call_args[ | ||
req, iam_endpoint, signer_email, target_audience, access_token, universe_domain = call_iam_generate_id_token_endpoint.call_args[ | ||
0 | ||
] | ||
assert req == request | ||
assert ( | ||
iam_endpoint | ||
== "https://iamcredentials.fake-universe/v1/projects/-/serviceAccounts/{}:generateIdToken" | ||
== "https://iamcredentials.{}/v1/projects/-/serviceAccounts/{}:generateIdToken" | ||
) | ||
assert signer_email == "[email protected]" | ||
assert target_audience == "https://example.com" | ||
decoded_access_token = jwt.decode(access_token, verify=False) | ||
assert decoded_access_token["scope"] == "https://www.googleapis.com/auth/iam" | ||
assert universe_domain == "fake-universe" | ||
|
||
@mock.patch("google.oauth2._client.id_token_jwt_grant", autospec=True) | ||
def test_before_request_refreshes(self, id_token_jwt_grant): | ||
|
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 |
---|---|---|
|
@@ -124,7 +124,7 @@ def make_credentials( | |
lifetime=LIFETIME, | ||
target_principal=TARGET_PRINCIPAL, | ||
iam_endpoint_override=None, | ||
universe_domain=credentials.DEFAULT_UNIVERSE_DOMAIN | ||
universe_domain=None | ||
): | ||
|
||
return Credentials( | ||
|
@@ -146,22 +146,27 @@ def test_get_cred_info(self): | |
"credential_source": "/path/to/file", | ||
"credential_type": "impersonated credentials", | ||
"principal": "[email protected]", | ||
"iam_endpoint_override": None, | ||
} | ||
|
||
def test_get_cred_info_universe_domain(self): | ||
credentials = self.make_credentials(universe_domain="foo.bar") | ||
assert not credentials.get_cred_info() | ||
|
||
credentials._cred_file_path = "/path/to/file" | ||
assert credentials.get_cred_info() == { | ||
"credential_source": "/path/to/file", | ||
"credential_type": "impersonated credentials", | ||
"principal": "[email protected]", | ||
"universe_domain": "foo.bar", | ||
"iam_endpoint_override": "https://iamcredentials.foo.bar/v1/projects/-" | ||
+ "/serviceAccounts/[email protected]:generateAccessToken" | ||
} | ||
def test_explicit_universe_domain_matching_source(self): | ||
source_credentials = service_account.Credentials( | ||
SIGNER, "[email protected]", TOKEN_URI, universe_domain="foo.bar" | ||
) | ||
credentials = self.make_credentials(universe_domain="foo.bar", source_credentials=source_credentials) | ||
assert credentials.universe_domain == "foo.bar" | ||
|
||
def test_universe_domain_from_source(self): | ||
source_credentials = service_account.Credentials( | ||
SIGNER, "[email protected]", TOKEN_URI, universe_domain="foo.bar" | ||
) | ||
credentials = self.make_credentials(source_credentials=source_credentials) | ||
assert credentials.universe_domain == "foo.bar" | ||
|
||
def test_explicit_universe_domain_not_matching_source(self): | ||
with pytest.raises(exceptions.InvalidOperation) as excinfo: | ||
self.make_credentials(universe_domain="foo.bar") | ||
|
||
assert excinfo.match(impersonated_credentials._UNIVERSE_DOMAIN_MATCH_SOURCE_ERROR) | ||
|
||
def test__make_copy_get_cred_info(self): | ||
credentials = self.make_credentials() | ||
|
@@ -409,9 +414,18 @@ def test_signer_email(self): | |
assert credentials.signer_email == self.TARGET_PRINCIPAL | ||
|
||
def test_sign_endpoint(self): | ||
credentials = self.make_credentials(universe_domain="foo.bar") | ||
assert credentials.get_iam_sign_endpoint == "https://iamcredentials.foo.bar/v1/projects/-" | ||
+ "/serviceAccounts/[email protected]:signBlob" | ||
source_credentials = service_account.Credentials( | ||
SIGNER, "[email protected]", TOKEN_URI, universe_domain="foo.bar" | ||
) | ||
credentials = self.make_credentials(source_credentials=source_credentials) | ||
assert credentials.get_iam_sign_endpoint() == "https://iamcredentials.foo.bar/v1/projects/-/serviceAccounts/[email protected]:signBlob" | ||
|
||
def test_sign_endpoint_explicit_universe_domain(self): | ||
source_credentials = service_account.Credentials( | ||
SIGNER, "[email protected]", TOKEN_URI, universe_domain="foo.bar" | ||
) | ||
credentials = self.make_credentials(universe_domain="foo.bar", source_credentials=source_credentials) | ||
assert credentials.get_iam_sign_endpoint() == "https://iamcredentials.foo.bar/v1/projects/-/serviceAccounts/[email protected]:signBlob" | ||
|
||
def test_service_account_email(self): | ||
credentials = self.make_credentials(target_principal=self.TARGET_PRINCIPAL) | ||
|