From 74e8bc296e3a33262bf10975064a34e2ea08a749 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 28 Jul 2017 14:20:11 -0400 Subject: [PATCH] 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`. --- workers/servicekeyworker/servicekeyworker.py | 2 +- workers/servicekeyworker/test/test_servicekeyworker.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/workers/servicekeyworker/servicekeyworker.py b/workers/servicekeyworker/servicekeyworker.py index 23ad26024..96457e0e8 100644 --- a/workers/servicekeyworker/servicekeyworker.py +++ b/workers/servicekeyworker/servicekeyworker.py @@ -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') diff --git a/workers/servicekeyworker/test/test_servicekeyworker.py b/workers/servicekeyworker/test/test_servicekeyworker.py index 2cf6103d3..2bab8b132 100644 --- a/workers/servicekeyworker/test/test_servicekeyworker.py +++ b/workers/servicekeyworker/test/test_servicekeyworker.py @@ -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):