Skip to content

Commit

Permalink
Fix App Engine's expiration calculation (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott authored Sep 12, 2017
1 parent 4460a96 commit 1cba0f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion google/auth/app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions tests/test_app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import mock
import pytest

from google.auth import _helpers
from google.auth import app_engine


Expand Down Expand Up @@ -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'])

Expand All @@ -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

Expand Down

0 comments on commit 1cba0f8

Please sign in to comment.