-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce the functionality to override token_uri in credentials (
#1159) * feat: Introduce the functionality to override token_uri in credentials * update rt
- Loading branch information
1 parent
75326e3
commit 73bc7e9
Showing
10 changed files
with
216 additions
and
4 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
Binary file not shown.
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 |
---|---|---|
|
@@ -483,6 +483,50 @@ def test_with_quota_project(self, sign, get, utcnow): | |
# Check that the signer have been initialized with a Request object | ||
assert isinstance(self.credentials._signer._request, transport.Request) | ||
|
||
@mock.patch( | ||
"google.auth._helpers.utcnow", | ||
return_value=datetime.datetime.utcfromtimestamp(0), | ||
) | ||
@mock.patch("google.auth.compute_engine._metadata.get", autospec=True) | ||
@mock.patch("google.auth.iam.Signer.sign", autospec=True) | ||
def test_with_token_uri(self, sign, get, utcnow): | ||
get.side_effect = [ | ||
{"email": "[email protected]", "scopes": ["one", "two"]} | ||
] | ||
sign.side_effect = [b"signature"] | ||
|
||
request = mock.create_autospec(transport.Request, instance=True) | ||
self.credentials = credentials.IDTokenCredentials( | ||
request=request, | ||
target_audience="https://audience.com", | ||
token_uri="http://xyz.com", | ||
) | ||
assert self.credentials._token_uri == "http://xyz.com" | ||
creds_with_token_uri = self.credentials.with_token_uri("http://abc.com") | ||
assert creds_with_token_uri._token_uri == "http://abc.com" | ||
|
||
@mock.patch( | ||
"google.auth._helpers.utcnow", | ||
return_value=datetime.datetime.utcfromtimestamp(0), | ||
) | ||
@mock.patch("google.auth.compute_engine._metadata.get", autospec=True) | ||
@mock.patch("google.auth.iam.Signer.sign", autospec=True) | ||
def test_with_token_uri_exception(self, sign, get, utcnow): | ||
get.side_effect = [ | ||
{"email": "[email protected]", "scopes": ["one", "two"]} | ||
] | ||
sign.side_effect = [b"signature"] | ||
|
||
request = mock.create_autospec(transport.Request, instance=True) | ||
self.credentials = credentials.IDTokenCredentials( | ||
request=request, | ||
target_audience="https://audience.com", | ||
use_metadata_identity_endpoint=True, | ||
) | ||
assert self.credentials._token_uri is None | ||
with pytest.raises(ValueError): | ||
self.credentials.with_token_uri("http://abc.com") | ||
|
||
@responses.activate | ||
def test_with_quota_project_integration(self): | ||
""" Test that it is possible to refresh credentials | ||
|
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