From 1cba0f834d18208fac464843b13501768910af1a Mon Sep 17 00:00:00 2001 From: Jon Wayne Parrott Date: Tue, 12 Sep 2017 10:21:02 -0700 Subject: [PATCH] Fix App Engine's expiration calculation (#197) --- google/auth/app_engine.py | 2 +- tests/test_app_engine.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/google/auth/app_engine.py b/google/auth/app_engine.py index 6dc871256..fa13f8ef8 100644 --- a/google/auth/app_engine.py +++ b/google/auth/app_engine.py @@ -114,7 +114,7 @@ def refresh(self, request): # pylint: disable=unused-argument token, ttl = app_identity.get_access_token( self._scopes, self._service_account_id) - expiry = _helpers.utcnow() + datetime.timedelta(seconds=ttl) + expiry = datetime.datetime.utcfromtimestamp(ttl) self.token, self.expiry = token, expiry diff --git a/tests/test_app_engine.py b/tests/test_app_engine.py index 9a6235905..70fa5ca33 100644 --- a/tests/test_app_engine.py +++ b/tests/test_app_engine.py @@ -17,7 +17,6 @@ import mock import pytest -from google.auth import _helpers from google.auth import app_engine @@ -134,7 +133,7 @@ def test_service_account_email_explicit(self, app_identity): return_value=datetime.datetime.min) def test_refresh(self, utcnow, app_identity): token = 'token' - ttl = _helpers.CLOCK_SKEW_SECS + 100 + ttl = 643942923 app_identity.get_access_token.return_value = token, ttl credentials = app_engine.Credentials(scopes=['email']) @@ -143,8 +142,8 @@ def test_refresh(self, utcnow, app_identity): app_identity.get_access_token.assert_called_with( credentials.scopes, credentials._service_account_id) assert credentials.token == token - assert credentials.expiry == ( - utcnow() + datetime.timedelta(seconds=ttl)) + assert credentials.expiry == datetime.datetime( + 1990, 5, 29, 1, 2, 3) assert credentials.valid assert not credentials.expired