Skip to content

Commit c8a7e30

Browse files
authored
test: add more tests for service account quota projects (#527)
Follow up to #519
1 parent 57cf500 commit c8a7e30

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/google-auth/tests/oauth2/test_credentials.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ def test_apply_with_quota_project_id(self):
309309
headers = {}
310310
creds.apply(headers)
311311
assert headers["x-goog-user-project"] == "quota-project-123"
312+
assert "token" in headers["authorization"]
312313

313314
def test_apply_with_no_quota_project_id(self):
314315
creds = credentials.Credentials(
@@ -322,6 +323,7 @@ def test_apply_with_no_quota_project_id(self):
322323
headers = {}
323324
creds.apply(headers)
324325
assert "x-goog-user-project" not in headers
326+
assert "token" in headers["authorization"]
325327

326328
def test_with_quota_project(self):
327329
creds = credentials.Credentials(

packages/google-auth/tests/oauth2/test_service_account.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,31 @@ def test__make_authorization_grant_assertion_subject(self):
178178
payload = jwt.decode(token, PUBLIC_CERT_BYTES)
179179
assert payload["sub"] == subject
180180

181+
def test_apply_with_quota_project_id(self):
182+
credentials = service_account.Credentials(
183+
SIGNER,
184+
self.SERVICE_ACCOUNT_EMAIL,
185+
self.TOKEN_URI,
186+
quota_project_id="quota-project-123",
187+
)
188+
189+
headers = {}
190+
credentials.apply(headers, token="token")
191+
192+
assert headers["x-goog-user-project"] == "quota-project-123"
193+
assert "token" in headers["authorization"]
194+
195+
def test_apply_with_no_quota_project_id(self):
196+
credentials = service_account.Credentials(
197+
SIGNER, self.SERVICE_ACCOUNT_EMAIL, self.TOKEN_URI
198+
)
199+
200+
headers = {}
201+
credentials.apply(headers, token="token")
202+
203+
assert "x-goog-user-project" not in headers
204+
assert "token" in headers["authorization"]
205+
181206
@mock.patch("google.oauth2._client.jwt_grant", autospec=True)
182207
def test_refresh_success(self, jwt_grant):
183208
credentials = self.make_credentials()

0 commit comments

Comments
 (0)