Skip to content

Commit

Permalink
test: add more tests for service account quota projects (#527)
Browse files Browse the repository at this point in the history
Follow up to #519
  • Loading branch information
busunkim96 authored Jul 21, 2020
1 parent ecd88d4 commit 18d5ae6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/oauth2/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def test_apply_with_quota_project_id(self):
headers = {}
creds.apply(headers)
assert headers["x-goog-user-project"] == "quota-project-123"
assert "token" in headers["authorization"]

def test_apply_with_no_quota_project_id(self):
creds = credentials.Credentials(
Expand All @@ -322,6 +323,7 @@ def test_apply_with_no_quota_project_id(self):
headers = {}
creds.apply(headers)
assert "x-goog-user-project" not in headers
assert "token" in headers["authorization"]

def test_with_quota_project(self):
creds = credentials.Credentials(
Expand Down
25 changes: 25 additions & 0 deletions tests/oauth2/test_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,31 @@ def test__make_authorization_grant_assertion_subject(self):
payload = jwt.decode(token, PUBLIC_CERT_BYTES)
assert payload["sub"] == subject

def test_apply_with_quota_project_id(self):
credentials = service_account.Credentials(
SIGNER,
self.SERVICE_ACCOUNT_EMAIL,
self.TOKEN_URI,
quota_project_id="quota-project-123",
)

headers = {}
credentials.apply(headers, token="token")

assert headers["x-goog-user-project"] == "quota-project-123"
assert "token" in headers["authorization"]

def test_apply_with_no_quota_project_id(self):
credentials = service_account.Credentials(
SIGNER, self.SERVICE_ACCOUNT_EMAIL, self.TOKEN_URI
)

headers = {}
credentials.apply(headers, token="token")

assert "x-goog-user-project" not in headers
assert "token" in headers["authorization"]

@mock.patch("google.oauth2._client.jwt_grant", autospec=True)
def test_refresh_success(self, jwt_grant):
credentials = self.make_credentials()
Expand Down

0 comments on commit 18d5ae6

Please sign in to comment.