Skip to content

Commit a249e3b

Browse files
committed
Add token_id unit test for impersonated service account credentials.
1 parent 6fd04d5 commit a249e3b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/oauth2/test_id_token.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323
from google.auth import transport
2424
from google.oauth2 import id_token
2525
from google.oauth2 import service_account
26+
from google.auth import impersonated_credentials
2627

2728
SERVICE_ACCOUNT_FILE = os.path.join(
2829
os.path.dirname(__file__), "../data/service_account.json"
2930
)
31+
32+
IMPERSONATED_SERVICE_ACCOUNT_FILE = os.path.join(
33+
os.path.dirname(__file__), "../data/impersonated_service_account_authorized_user_source.json"
34+
)
35+
3036
ID_TOKEN_AUDIENCE = "https://pubsub.googleapis.com"
3137

3238

@@ -262,6 +268,15 @@ def test_fetch_id_token_credentials_from_explicit_cred_json_file(monkeypatch):
262268
assert cred._target_audience == ID_TOKEN_AUDIENCE
263269

264270

271+
def test_fetch_id_token_credentials_from_impersonated_cred_json_file(monkeypatch):
272+
## Test: Can I Fetch ID token Credentials?
273+
monkeypatch.setenv(environment_vars.CREDENTIALS, IMPERSONATED_SERVICE_ACCOUNT_FILE)
274+
275+
cred = id_token.fetch_id_token_credentials(ID_TOKEN_AUDIENCE)
276+
assert isinstance(cred, impersonated_credentials.IDTokenCredentials)
277+
assert cred._target_audience == ID_TOKEN_AUDIENCE
278+
279+
265280
def test_fetch_id_token_credentials_no_cred_exists(monkeypatch):
266281
monkeypatch.delenv(environment_vars.CREDENTIALS, raising=False)
267282

0 commit comments

Comments
 (0)