mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 23:55:58 -05:00
Update api-key/revoke endpoint to expire the key for the service.
Previously we assumed there was only one api key that was valid.
This commit is contained in:
@@ -25,16 +25,16 @@ def test_save_api_key_should_create_new_api_key(notify_api, notify_db, notify_db
|
||||
api_key = ApiKey(**{'service_id': sample_service.id, 'name': sample_service.name})
|
||||
save_model_api_key(api_key)
|
||||
|
||||
all_api_keys = get_model_api_keys()
|
||||
all_api_keys = get_model_api_keys(service_id=sample_service.id)
|
||||
assert len(all_api_keys) == 1
|
||||
assert all_api_keys[0] == api_key
|
||||
|
||||
|
||||
def test_save_api_key_should_update_the_api_key(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
now = datetime.utcnow()
|
||||
saved_api_key = get_model_api_keys(sample_api_key.service_id)
|
||||
saved_api_key = get_model_api_keys(service_id=sample_api_key.service_id, id=sample_api_key.id)
|
||||
save_model_api_key(saved_api_key, update_dict={'id': saved_api_key.id, 'expiry_date': now})
|
||||
all_api_keys = get_model_api_keys()
|
||||
all_api_keys = get_model_api_keys(service_id=sample_api_key.service_id)
|
||||
assert len(all_api_keys) == 1
|
||||
assert all_api_keys[0].expiry_date == now
|
||||
assert all_api_keys[0].secret == saved_api_key.secret
|
||||
@@ -42,22 +42,17 @@ def test_save_api_key_should_update_the_api_key(notify_api, notify_db, notify_db
|
||||
assert all_api_keys[0].service_id == saved_api_key.service_id
|
||||
|
||||
|
||||
def test_get_api_key_should_raise_exception_when_service_does_not_exist(notify_api, notify_db, notify_db_session,
|
||||
def test_get_api_key_should_raise_exception_when_api_key_does_not_exist(notify_api, notify_db, notify_db_session,
|
||||
sample_service):
|
||||
try:
|
||||
get_model_api_keys(sample_service.id)
|
||||
get_model_api_keys(sample_service.id, id=123)
|
||||
fail("Should have thrown a NoResultFound exception")
|
||||
except NoResultFound:
|
||||
pass
|
||||
|
||||
|
||||
def test_get_api_key_should_return_none_when_service_does_not_exist(notify_api, notify_db, notify_db_session,
|
||||
sample_service):
|
||||
assert get_model_api_keys(service_id=sample_service.id, raise_=False) is None
|
||||
|
||||
|
||||
def test_should_return_api_key_for_service(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
api_key = get_model_api_keys(sample_api_key.service_id)
|
||||
api_key = get_model_api_keys(service_id=sample_api_key.service_id, id=sample_api_key.id)
|
||||
assert api_key == sample_api_key
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user