4444BASIC_AUTH_ENCODING = "dXNlcm5hbWU6cGFzc3dvcmQ="
4545SCOPES = ["email" , "profile" ]
4646NOW = datetime .datetime (1990 , 8 , 27 , 6 , 54 , 30 )
47+ FAKE_UNIVERSE_DOMAIN = "fake-universe-domain"
48+ DEFAULT_UNIVERSE_DOMAIN = external_account_authorized_user ._DEFAULT_UNIVERSE_DOMAIN
4749
4850
4951class TestCredentials (object ):
@@ -98,13 +100,15 @@ def test_default_state(self):
98100 assert creds .refresh_token == REFRESH_TOKEN
99101 assert creds .audience == AUDIENCE
100102 assert creds .token_url == TOKEN_URL
103+ assert creds .universe_domain == DEFAULT_UNIVERSE_DOMAIN
101104
102105 def test_basic_create (self ):
103106 creds = external_account_authorized_user .Credentials (
104107 token = ACCESS_TOKEN ,
105108 expiry = datetime .datetime .max ,
106109 scopes = SCOPES ,
107110 revoke_url = REVOKE_URL ,
111+ universe_domain = FAKE_UNIVERSE_DOMAIN ,
108112 )
109113
110114 assert creds .expiry == datetime .datetime .max
@@ -115,6 +119,7 @@ def test_basic_create(self):
115119 assert creds .scopes == SCOPES
116120 assert creds .is_user
117121 assert creds .revoke_url == REVOKE_URL
122+ assert creds .universe_domain == FAKE_UNIVERSE_DOMAIN
118123
119124 def test_stunted_create_no_refresh_token (self ):
120125 with pytest .raises (ValueError ) as excinfo :
@@ -339,6 +344,7 @@ def test_info(self):
339344 assert info ["token_info_url" ] == TOKEN_INFO_URL
340345 assert info ["client_id" ] == CLIENT_ID
341346 assert info ["client_secret" ] == CLIENT_SECRET
347+ assert info ["universe_domain" ] == DEFAULT_UNIVERSE_DOMAIN
342348 assert "token" not in info
343349 assert "expiry" not in info
344350 assert "revoke_url" not in info
@@ -350,6 +356,7 @@ def test_info_full(self):
350356 expiry = NOW ,
351357 revoke_url = REVOKE_URL ,
352358 quota_project_id = QUOTA_PROJECT_ID ,
359+ universe_domain = FAKE_UNIVERSE_DOMAIN ,
353360 )
354361 info = creds .info
355362
@@ -363,6 +370,7 @@ def test_info_full(self):
363370 assert info ["expiry" ] == NOW .isoformat () + "Z"
364371 assert info ["revoke_url" ] == REVOKE_URL
365372 assert info ["quota_project_id" ] == QUOTA_PROJECT_ID
373+ assert info ["universe_domain" ] == FAKE_UNIVERSE_DOMAIN
366374
367375 def test_to_json (self ):
368376 creds = self .make_credentials ()
@@ -375,6 +383,7 @@ def test_to_json(self):
375383 assert info ["token_info_url" ] == TOKEN_INFO_URL
376384 assert info ["client_id" ] == CLIENT_ID
377385 assert info ["client_secret" ] == CLIENT_SECRET
386+ assert info ["universe_domain" ] == DEFAULT_UNIVERSE_DOMAIN
378387 assert "token" not in info
379388 assert "expiry" not in info
380389 assert "revoke_url" not in info
@@ -386,6 +395,7 @@ def test_to_json_full(self):
386395 expiry = NOW ,
387396 revoke_url = REVOKE_URL ,
388397 quota_project_id = QUOTA_PROJECT_ID ,
398+ universe_domain = FAKE_UNIVERSE_DOMAIN ,
389399 )
390400 json_info = creds .to_json ()
391401 info = json .loads (json_info )
@@ -400,6 +410,7 @@ def test_to_json_full(self):
400410 assert info ["expiry" ] == NOW .isoformat () + "Z"
401411 assert info ["revoke_url" ] == REVOKE_URL
402412 assert info ["quota_project_id" ] == QUOTA_PROJECT_ID
413+ assert info ["universe_domain" ] == FAKE_UNIVERSE_DOMAIN
403414
404415 def test_to_json_full_with_strip (self ):
405416 creds = self .make_credentials (
@@ -467,6 +478,26 @@ def test_with_token_uri(self):
467478 assert new_creds ._revoke_url == creds ._revoke_url
468479 assert new_creds ._quota_project_id == creds ._quota_project_id
469480
481+ def test_with_universe_domain (self ):
482+ creds = self .make_credentials (
483+ token = ACCESS_TOKEN ,
484+ expiry = NOW ,
485+ revoke_url = REVOKE_URL ,
486+ quota_project_id = QUOTA_PROJECT_ID ,
487+ )
488+ new_creds = creds .with_universe_domain (FAKE_UNIVERSE_DOMAIN )
489+ assert new_creds ._audience == creds ._audience
490+ assert new_creds ._refresh_token == creds ._refresh_token
491+ assert new_creds ._token_url == creds ._token_url
492+ assert new_creds ._token_info_url == creds ._token_info_url
493+ assert new_creds ._client_id == creds ._client_id
494+ assert new_creds ._client_secret == creds ._client_secret
495+ assert new_creds .token == creds .token
496+ assert new_creds .expiry == creds .expiry
497+ assert new_creds ._revoke_url == creds ._revoke_url
498+ assert new_creds ._quota_project_id == QUOTA_PROJECT_ID
499+ assert new_creds .universe_domain == FAKE_UNIVERSE_DOMAIN
500+
470501 def test_from_file_required_options_only (self , tmpdir ):
471502 from_creds = self .make_credentials ()
472503 config_file = tmpdir .join ("config.json" )
0 commit comments