Revoke API keys when changing broadcast settings

On a regular Notify service anyone with permission can create an API
key. If this service then is given permission to send emergency alerts
it will have an API key which can create emergency alerts. This feels
dangerous.

Secondly, if a service which legitimately has an API key for sending
alerts in training mode is changed to live mode you now have an API key
which people will think isn’t going to create a real alert but actually
will. This feels really dangerous.

Neither of these scenarios are things we should be doing, but having
them possible still makes me feel uncomfortable.

This commit revokes all API keys for a service when its broadcast
settings change, same way we remove all permissions for its users.
This commit is contained in:
Chris Hill-Scott
2021-07-29 09:56:17 +01:00
parent 312a895822
commit 43bcb56ff4
2 changed files with 30 additions and 0 deletions

View File

@@ -4170,3 +4170,25 @@ def test_set_as_broadcast_service_removes_user_permissions(
# Permissions for other services remain
assert service_user.get_permissions(service_id=sample_service_full_permissions.id) == ['send_emails']
def test_set_as_broadcast_service_revokes_api_keys(
admin_request,
broadcast_organisation,
sample_service,
sample_service_full_permissions,
):
api_key_1 = create_api_key(service=sample_service)
api_key_2 = create_api_key(service=sample_service_full_permissions)
admin_request.post(
'service.set_as_broadcast_service',
service_id=sample_service.id,
_data={
'broadcast_channel': 'government',
'service_mode': 'live',
'provider_restriction': 'all',
}
)
assert api_key_1.expiry_date < datetime.utcnow()
assert api_key_2.expiry_date is None