mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Split generating authorization headers by type
In response to [1]. [1]: https://github.com/alphagov/notifications-api/pull/3300#discussion_r681653248
This commit is contained in:
@@ -4,7 +4,7 @@ from flask import url_for
|
||||
|
||||
from app.dao.api_key_dao import expire_api_key
|
||||
from app.models import KEY_TYPE_NORMAL, ApiKey
|
||||
from tests import create_authorization_header
|
||||
from tests import create_admin_authorization_header
|
||||
from tests.app.db import create_api_key, create_service, create_user
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_api_key_should_create_new_api_key_for_service(notify_api, sample_servic
|
||||
'created_by': str(sample_service.created_by.id),
|
||||
'key_type': KEY_TYPE_NORMAL
|
||||
}
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.post(url_for('service.create_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -32,7 +32,7 @@ def test_api_key_should_return_error_when_service_does_not_exist(notify_api, sam
|
||||
with notify_api.test_client() as client:
|
||||
import uuid
|
||||
missing_service_id = uuid.uuid4()
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.post(url_for('service.create_api_key', service_id=missing_service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 404
|
||||
@@ -44,7 +44,7 @@ def test_create_api_key_without_key_type_rejects(notify_api, sample_service):
|
||||
'name': 'some secret name',
|
||||
'created_by': str(sample_service.created_by.id)
|
||||
}
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.post(url_for('service.create_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -58,7 +58,7 @@ def test_revoke_should_expire_api_key_for_service(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
assert ApiKey.query.count() == 1
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.post(url_for('service.revoke_api_key',
|
||||
service_id=sample_api_key.service_id,
|
||||
api_key_id=sample_api_key.id),
|
||||
@@ -77,7 +77,7 @@ def test_api_key_should_create_multiple_new_api_key_for_service(notify_api, samp
|
||||
'created_by': str(sample_service.created_by.id),
|
||||
'key_type': KEY_TYPE_NORMAL
|
||||
}
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.post(url_for('service.create_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -85,7 +85,7 @@ def test_api_key_should_create_multiple_new_api_key_for_service(notify_api, samp
|
||||
assert ApiKey.query.count() == 1
|
||||
|
||||
data['name'] = 'another secret name'
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response2 = client.post(url_for('service.create_api_key', service_id=sample_service.id),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -110,7 +110,7 @@ def test_get_api_keys_should_return_all_keys_for_service(notify_api, sample_api_
|
||||
|
||||
assert ApiKey.query.count() == 4
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.get(url_for('service.get_api_keys',
|
||||
service_id=sample_api_key.service_id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -122,7 +122,7 @@ def test_get_api_keys_should_return_all_keys_for_service(notify_api, sample_api_
|
||||
def test_get_api_keys_should_return_one_key_for_service(notify_api, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
response = client.get(url_for('service.get_api_keys',
|
||||
service_id=sample_api_key.service_id,
|
||||
key_id=sample_api_key.id),
|
||||
|
||||
Reference in New Issue
Block a user