add check for inactive services to auth handler

cleaned up some auth code to marginally improve efficiency of error checking
and hopefully make it easier to read

fixed some incorrect auth headers in the deactivate tests
This commit is contained in:
Leo Hemsted
2016-11-10 11:07:12 +00:00
parent b2149bf02a
commit e8c3a5cdde
4 changed files with 29 additions and 16 deletions

View File

@@ -223,6 +223,17 @@ def test_authentication_returns_error_when_service_doesnt_exit(
assert error_message['message'] == {'token': ['Invalid token: service not found']}
def test_authentication_returns_error_when_service_inactive(client, sample_api_key):
sample_api_key.service.active = False
token = create_jwt_token(secret=str(sample_api_key.id), client_id=str(sample_api_key.service_id))
response = client.get('/service', headers={'Authorization': 'Bearer {}'.format(token)})
assert response.status_code == 403
error_message = json.loads(response.get_data())
assert error_message['message'] == {'token': ['Invalid token: service is archived']}
def test_authentication_returns_error_when_service_has_no_secrets(notify_api,
sample_service,
fake_uuid):