Skip to content

Commit

Permalink
Merge branch 'main' into ud
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 authored Nov 13, 2023
2 parents 49289e1 + 3f426bc commit 4910f14
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
9 changes: 8 additions & 1 deletion google/auth/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ def utcnow():
Returns:
datetime: The current time in UTC.
"""
return datetime.datetime.utcnow()
# We used datetime.utcnow() before, since it's deprecated from python 3.12,
# we are using datetime.now(timezone.utc) now. "utcnow()" is offset-native
# (no timezone info), but "now()" is offset-aware (with timezone info).
# This will cause datetime comparison problem. For backward compatibility,
# we need to remove the timezone info.
now = datetime.datetime.now(datetime.timezone.utc)
now = now.replace(tzinfo=None)
return now


def datetime_to_secs(value):
Expand Down
5 changes: 3 additions & 2 deletions google/oauth2/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
class Credentials(credentials.ReadOnlyScoped, credentials.CredentialsWithQuotaProject):
"""Credentials using OAuth 2.0 access and refresh tokens.
The credentials are considered immutable. If you want to modify the
quota project, use :meth:`with_quota_project` or ::
The credentials are considered immutable except the tokens and the token
expiry, which are updated after refresh. If you want to modify the quota
project, use :meth:`with_quota_project` or ::
credentials = credentials.with_quota_project('myproject-123')
Expand Down
Binary file modified system_tests/secrets.tar.enc
Binary file not shown.
6 changes: 2 additions & 4 deletions tests/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@ def test_expired_and_valid():
# Set the expiration to one second more than now plus the clock skew
# accomodation. These credentials should be valid.
credentials.expiry = (
datetime.datetime.utcnow()
+ _helpers.REFRESH_THRESHOLD
+ datetime.timedelta(seconds=1)
_helpers.utcnow() + _helpers.REFRESH_THRESHOLD + datetime.timedelta(seconds=1)
)

assert credentials.valid
assert not credentials.expired

# Set the credentials expiration to now. Because of the clock skew
# accomodation, these credentials should report as expired.
credentials.expiry = datetime.datetime.utcnow()
credentials.expiry = _helpers.utcnow()

assert not credentials.valid
assert credentials.expired
Expand Down
6 changes: 2 additions & 4 deletions tests_async/test_credentials_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ def test_expired_and_valid():
# Set the expiration to one second more than now plus the clock skew
# accomodation. These credentials should be valid.
credentials.expiry = (
datetime.datetime.utcnow()
+ _helpers.REFRESH_THRESHOLD
+ datetime.timedelta(seconds=1)
_helpers.utcnow() + _helpers.REFRESH_THRESHOLD + datetime.timedelta(seconds=1)
)

assert credentials.valid
assert not credentials.expired

# Set the credentials expiration to now. Because of the clock skew
# accomodation, these credentials should report as expired.
credentials.expiry = datetime.datetime.utcnow()
credentials.expiry = _helpers.utcnow()

assert not credentials.valid
assert credentials.expired
Expand Down

0 comments on commit 4910f14

Please sign in to comment.