Skip to content

Commit

Permalink
fix: fix user cred universe domain issue (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 authored Dec 8, 2023
1 parent d5fc84f commit ae314a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion google/oauth2/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def __setstate__(self, d):
self._rapt_token = d.get("_rapt_token")
self._enable_reauth_refresh = d.get("_enable_reauth_refresh")
self._trust_boundary = d.get("_trust_boundary")
self._universe_domain = d.get("_universe_domain")
self._universe_domain = d.get("_universe_domain") or _DEFAULT_UNIVERSE_DOMAIN
# The refresh_handler setter should be used to repopulate this.
self._refresh_handler = None

Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/oauth2/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,17 @@ def test_pickle_and_unpickle(self):
for attr in list(creds.__dict__):
assert getattr(creds, attr) == getattr(unpickled, attr)

def test_pickle_and_unpickle_universe_domain(self):
# old version of auth lib doesn't have _universe_domain, so the pickled
# cred doesn't have such a field.
creds = self.make_credentials()
del creds._universe_domain

unpickled = pickle.loads(pickle.dumps(creds))

# make sure the unpickled cred sets _universe_domain to default.
assert unpickled.universe_domain == "googleapis.com"

def test_pickle_and_unpickle_with_refresh_handler(self):
expected_expiry = _helpers.utcnow() + datetime.timedelta(seconds=2800)
refresh_handler = mock.Mock(return_value=("TOKEN", expected_expiry))
Expand Down

0 comments on commit ae314a8

Please sign in to comment.