mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 18:38:14 -04:00
Don’t re-expire old keys
If a key has already been expired we don’t want to lose the information about when that happened by giving it a new expiry date.
This commit is contained in:
@@ -70,7 +70,8 @@ def set_broadcast_service_type(service, service_mode, broadcast_channel, provide
|
|||||||
|
|
||||||
# Revoke any API keys to avoid a regular API key being used to send alerts
|
# Revoke any API keys to avoid a regular API key being used to send alerts
|
||||||
ApiKey.query.filter_by(
|
ApiKey.query.filter_by(
|
||||||
service_id=service.id
|
service_id=service.id,
|
||||||
|
expiry_date=None,
|
||||||
).update({
|
).update({
|
||||||
ApiKey.expiry_date: datetime.utcnow()
|
ApiKey.expiry_date: datetime.utcnow()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4172,6 +4172,7 @@ def test_set_as_broadcast_service_removes_user_permissions(
|
|||||||
assert service_user.get_permissions(service_id=sample_service_full_permissions.id) == ['send_emails']
|
assert service_user.get_permissions(service_id=sample_service_full_permissions.id) == ['send_emails']
|
||||||
|
|
||||||
|
|
||||||
|
@freeze_time('2021-12-21')
|
||||||
def test_set_as_broadcast_service_revokes_api_keys(
|
def test_set_as_broadcast_service_revokes_api_keys(
|
||||||
admin_request,
|
admin_request,
|
||||||
broadcast_organisation,
|
broadcast_organisation,
|
||||||
@@ -4179,7 +4180,10 @@ def test_set_as_broadcast_service_revokes_api_keys(
|
|||||||
sample_service_full_permissions,
|
sample_service_full_permissions,
|
||||||
):
|
):
|
||||||
api_key_1 = create_api_key(service=sample_service)
|
api_key_1 = create_api_key(service=sample_service)
|
||||||
api_key_2 = create_api_key(service=sample_service_full_permissions)
|
api_key_2 = create_api_key(service=sample_service)
|
||||||
|
api_key_3 = create_api_key(service=sample_service_full_permissions)
|
||||||
|
|
||||||
|
api_key_2.expiry_date = datetime.utcnow() - timedelta(days=365)
|
||||||
|
|
||||||
admin_request.post(
|
admin_request.post(
|
||||||
'service.set_as_broadcast_service',
|
'service.set_as_broadcast_service',
|
||||||
@@ -4190,5 +4194,12 @@ def test_set_as_broadcast_service_revokes_api_keys(
|
|||||||
'provider_restriction': 'all',
|
'provider_restriction': 'all',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
assert api_key_1.expiry_date < datetime.utcnow()
|
|
||||||
assert api_key_2.expiry_date is None
|
# This key should have a new expiry date
|
||||||
|
assert api_key_1.expiry_date.isoformat().startswith('2021-12-21')
|
||||||
|
|
||||||
|
# This key keeps its old expiry date
|
||||||
|
assert api_key_2.expiry_date.isoformat().startswith('2020-12-21')
|
||||||
|
|
||||||
|
# This key is from a different service
|
||||||
|
assert api_key_3.expiry_date is None
|
||||||
|
|||||||
Reference in New Issue
Block a user