Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: invalid expiry type #481

Merged
merged 2 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion google/auth/compute_engine/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ def _call_metadata_identity_endpoint(self, request):
request (google.auth.transport.Request): The object used to make
HTTP requests.

Returns:
str: The ID token.
datetime.datetime: Expiry of the ID token.

arithmetic1728 marked this conversation as resolved.
Show resolved Hide resolved
Raises:
google.auth.exceptions.RefreshError: If the Compute Engine metadata
service can't be reached or if the instance has no credentials.
Expand All @@ -291,7 +295,7 @@ def _call_metadata_identity_endpoint(self, request):
six.raise_from(new_exc, caught_exc)

_, payload, _, _ = jwt._unverified_decode(id_token)
return id_token, payload["exp"]
return id_token, datetime.datetime.fromtimestamp(payload["exp"])

def refresh(self, request):
"""Refreshes the ID token.
Expand Down
5 changes: 4 additions & 1 deletion system_tests/test_compute_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime

import pytest

import google.auth
Expand Down Expand Up @@ -61,8 +63,9 @@ def test_id_token_from_metadata(http_request):
credentials.refresh(http_request)

_, payload, _, _ = jwt._unverified_decode(credentials.token)
assert credentials.valid
assert payload["aud"] == AUDIENCE
assert payload["exp"] == credentials.expiry
assert datetime.fromtimestamp(payload["exp"]) == credentials.expiry


def test_fetch_id_token(http_request):
Expand Down
2 changes: 1 addition & 1 deletion tests/compute_engine/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_get_id_token_from_metadata(self, get, get_service_account_info):
cred.refresh(request=mock.Mock())

assert cred.token == SAMPLE_ID_TOKEN
assert cred.expiry == SAMPLE_ID_TOKEN_EXP
assert cred.expiry == datetime.datetime.fromtimestamp(SAMPLE_ID_TOKEN_EXP)
assert cred._use_metadata_identity_endpoint
assert cred._signer is None
assert cred._token_uri is None
Expand Down