[depot_tools] Fix timestamp issues related to local auth

Bug: 509672
Change-Id: I5abb813d5f78291b4bf2d8e856c6fd71fcad5b68
Reviewed-on: https://chromium-review.googlesource.com/791472
Commit-Queue: Mun Yong Jang <myjang@google.com>
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
changes/72/791472/3
Mun Yong Jang 8 years ago committed by Commit Bot
parent ad3e639bae
commit 1728f5f3e6

@ -200,11 +200,17 @@ def _get_luci_context_access_token(env, now):
if expiry: if expiry:
try: try:
expiry_dt = datetime.datetime.utcfromtimestamp(expiry) expiry_dt = datetime.datetime.utcfromtimestamp(expiry)
logging.debug(
'local_auth: got an access token for '
'account "%s" that expires in %d sec',
account_id, (expiry_dt - now).total_seconds())
except (TypeError, ValueError): except (TypeError, ValueError):
authErr('Invalid expiry in returned token') authErr('Invalid expiry in returned token')
logging.debug( else:
'local_auth: got an access token for account "%s" that expires in %d sec', logging.debug(
account_id, expiry - time.mktime(now.timetuple())) 'local auth: got an access token for '
'account "%s" that does not expire',
account_id)
access_token = AccessToken(access_token, expiry_dt) access_token = AccessToken(access_token, expiry_dt)
if _needs_refresh(access_token, now=now): if _needs_refresh(access_token, now=now):
authErr('local_auth: the returned access token needs to be refreshed') authErr('local_auth: the returned access token needs to be refreshed')

@ -45,12 +45,13 @@ class TestGetLuciContextAccessToken(auto_stub.TestCase):
def test_correct_local_auth_format(self): def test_correct_local_auth_format(self):
self._mock_local_auth('dead', 'beef', 10) self._mock_local_auth('dead', 'beef', 10)
expiry_time = datetime.datetime.min + datetime.timedelta(minutes=60) expiry_time = datetime.datetime.min + datetime.timedelta(hours=1)
resp_content = { resp_content = {
'error_code': None, 'error_code': None,
'error_message': None, 'error_message': None,
'access_token': 'token', 'access_token': 'token',
'expiry': time.mktime(expiry_time.timetuple()), 'expiry': (expiry_time
- datetime.datetime.utcfromtimestamp(0)).total_seconds(),
} }
self._mock_loc_server_resp(200, json.dumps(resp_content)) self._mock_loc_server_resp(200, json.dumps(resp_content))
token = auth._get_luci_context_access_token( token = auth._get_luci_context_access_token(

Loading…
Cancel
Save