File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 2323from google .auth import transport
2424from google .oauth2 import id_token
2525from google .oauth2 import service_account
26+ from google .auth import impersonated_credentials
2627
2728SERVICE_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+
3036ID_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+
265280def test_fetch_id_token_credentials_no_cred_exists (monkeypatch ):
266281 monkeypatch .delenv (environment_vars .CREDENTIALS , raising = False )
267282
You can’t perform that action at this time.
0 commit comments