Fix bug in service key rotation and fix associated flaky test

We were using `datetime.now` in both the rotation code and the test, but the model uses `utcnow`.
This commit is contained in:
Joseph Schorr 2017-07-28 14:20:11 -04:00
parent ae9bd8b727
commit 74e8bc296e
2 changed files with 3 additions and 2 deletions

View file

@ -20,7 +20,7 @@ class ServiceKeyWorker(Worker):
"""
expiration = timedelta(minutes=instance_keys.service_key_expiration)
logger.debug('Starting refresh of automatic service keys')
model.set_key_expiration(instance_keys.local_key_id, datetime.now() + expiration)
model.set_key_expiration(instance_keys.local_key_id, datetime.utcnow() + expiration)
logger.debug('Finished refresh of automatic service keys')

View file

@ -10,8 +10,9 @@ from workers.servicekeyworker.models_pre_oci import pre_oci_model as model
def test_refresh_service_key(initialized_db):
# Create a service key for testing.
original_expiration = datetime.now() + timedelta(minutes=10)
original_expiration = datetime.utcnow() + timedelta(minutes=10)
test_key_kid = model.create_service_key_for_testing(original_expiration)
assert model.get_service_key_expiration(test_key_kid)
instance_keys = AttrDict(dict(local_key_id=test_key_kid, service_key_expiration=30))
with patch('workers.servicekeyworker.servicekeyworker.instance_keys', instance_keys):