aboutsummaryrefslogtreecommitdiff
path: root/tests/test_impersonated_credentials.py
diff options
context:
space:
mode:
authorBu Sun Kim <8822365+busunkim96@users.noreply.github.com>2020-07-09 10:39:39 -0700
committerGitHub <noreply@github.com>2020-07-09 10:39:39 -0700
commit3dda7b2ab88aba7941b8b5281b4acbc7db74169b (patch)
tree64f8ebe2b7565df4e32bf702a7977e50a294039a /tests/test_impersonated_credentials.py
parent218a159f646c81021c890b92f9cff003aed949a8 (diff)
downloadgoogle-auth-library-python-3dda7b2ab88aba7941b8b5281b4acbc7db74169b.tar.gz
feat: add quota project to base credentials class (#546)
Diffstat (limited to 'tests/test_impersonated_credentials.py')
-rw-r--r--tests/test_impersonated_credentials.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_impersonated_credentials.py b/tests/test_impersonated_credentials.py
index e0b5b11..46850a0 100644
--- a/tests/test_impersonated_credentials.py
+++ b/tests/test_impersonated_credentials.py
@@ -311,6 +311,12 @@ class TestImpersonatedCredentials(object):
signature = credentials.sign_bytes(b"signed bytes")
assert signature == b"signature"
+ def test_with_quota_project(self):
+ credentials = self.make_credentials()
+
+ quota_project_creds = credentials.with_quota_project("project-foo")
+ assert quota_project_creds._quota_project_id == "project-foo"
+
def test_id_token_success(
self, mock_donor_credentials, mock_authorizedsession_idtoken
):
@@ -435,3 +441,32 @@ class TestImpersonatedCredentials(object):
id_creds.refresh(request)
assert id_creds.token == ID_TOKEN_DATA
+
+ def test_id_token_with_quota_project(
+ self, mock_donor_credentials, mock_authorizedsession_idtoken
+ ):
+ credentials = self.make_credentials(lifetime=None)
+ token = "token"
+ target_audience = "https://foo.bar"
+
+ expire_time = (
+ _helpers.utcnow().replace(microsecond=0) + datetime.timedelta(seconds=500)
+ ).isoformat("T") + "Z"
+ response_body = {"accessToken": token, "expireTime": expire_time}
+
+ request = self.make_request(
+ data=json.dumps(response_body), status=http_client.OK
+ )
+
+ credentials.refresh(request)
+
+ assert credentials.valid
+ assert not credentials.expired
+
+ id_creds = impersonated_credentials.IDTokenCredentials(
+ credentials, target_audience=target_audience
+ )
+ id_creds = id_creds.with_quota_project("project-foo")
+ id_creds.refresh(request)
+
+ assert id_creds.quota_project_id == "project-foo"