Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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