File tree Expand file tree Collapse file tree 3 files changed +14
-12
lines changed
Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -417,13 +417,11 @@ def _metric_header_for_usage(self):
417417
418418 @_helpers .copy_docstring (credentials .Credentials )
419419 def refresh (self , request ):
420- if (
421- self ._universe_domain != _DEFAULT_UNIVERSE_DOMAIN
422- and not self ._jwt_credentials
423- ):
424- raise exceptions .RefreshError (
425- "self._jwt_credentials is missing for non-default universe domain"
426- )
420+ if self ._always_use_jwt_access and not self ._jwt_credentials :
421+ # If self signed jwt should be used but jwt credential is not
422+ # created, try to create one with scopes
423+ self ._create_self_signed_jwt (None )
424+
427425 if self ._universe_domain != _DEFAULT_UNIVERSE_DOMAIN and self ._subject :
428426 raise exceptions .RefreshError (
429427 "domain wide delegation is not supported for non-default universe domain"
Original file line number Diff line number Diff line change @@ -557,12 +557,16 @@ def test_refresh_jwt_not_used_for_domain_wide_delegation(
557557 assert jwt_grant .called
558558 assert not self_signed_jwt_refresh .called
559559
560- def test_refresh_non_gdu_missing_jwt_credentials (self ):
561- credentials = self .make_credentials (universe_domain = "foo" )
560+ def test_refresh_missing_jwt_credentials (self ):
561+ credentials = self .make_credentials ()
562+ credentials = credentials .with_scopes (["foo" , "bar" ])
563+ credentials = credentials .with_always_use_jwt_access (True )
564+ assert not credentials ._jwt_credentials
562565
563- with pytest .raises (exceptions .RefreshError ) as excinfo :
564- credentials .refresh (None )
565- assert excinfo .match ("self._jwt_credentials is missing" )
566+ credentials .refresh (mock .Mock ())
567+
568+ # jwt credentials should have been automatically created with scopes
569+ assert credentials ._jwt_credentials is not None
566570
567571 def test_refresh_non_gdu_domain_wide_delegation_not_supported (self ):
568572 credentials = self .make_credentials (universe_domain = "foo" )
You can’t perform that action at this time.
0 commit comments