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:
Ben Thorner
2021-08-04 15:12:09 +01:00
parent 5a1636e41f
commit 0312e2a528
33 changed files with 526 additions and 512 deletions

View File

@@ -7,7 +7,7 @@ from freezegun import freeze_time
from notifications_utils.url_safe_token import generate_token
from app.models import EMAIL_AUTH_TYPE, SMS_AUTH_TYPE, Notification
from tests import create_authorization_header
from tests import create_admin_authorization_header
from tests.app.db import create_invited_user
@@ -163,7 +163,7 @@ def test_create_invited_user_invalid_email(client, sample_service, mocker, fake_
data = json.dumps(data)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.post(
'/service/{}/invite'.format(sample_service.id),
@@ -187,7 +187,7 @@ def test_get_all_invited_users_by_service(client, notify_db, notify_db_session,
url = '/service/{}/invite'.format(sample_service.id)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.get(
url,
@@ -208,7 +208,7 @@ def test_get_all_invited_users_by_service(client, notify_db, notify_db_session,
def test_get_invited_users_by_service_with_no_invites(client, notify_db, notify_db_session, sample_service):
url = '/service/{}/invite'.format(sample_service.id)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.get(
url,
@@ -245,7 +245,7 @@ def test_get_invited_user_by_service_when_user_does_not_belong_to_the_service(
def test_update_invited_user_set_status_to_cancelled(client, sample_invited_user):
data = {'status': 'cancelled'}
url = '/service/{0}/invite/{1}'.format(sample_invited_user.service_id, sample_invited_user.id)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.post(url,
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
@@ -258,7 +258,7 @@ def test_update_invited_user_set_status_to_cancelled(client, sample_invited_user
def test_update_invited_user_for_wrong_service_returns_404(client, sample_invited_user, fake_uuid):
data = {'status': 'cancelled'}
url = '/service/{0}/invite/{1}'.format(fake_uuid, sample_invited_user.id)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.post(url, data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 404
@@ -269,7 +269,7 @@ def test_update_invited_user_for_wrong_service_returns_404(client, sample_invite
def test_update_invited_user_for_invalid_data_returns_400(client, sample_invited_user):
data = {'status': 'garbage'}
url = '/service/{0}/invite/{1}'.format(sample_invited_user.service_id, sample_invited_user.id)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.post(url, data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400
@@ -283,7 +283,7 @@ def test_validate_invitation_token_returns_200_when_token_valid(client, sample_i
token = generate_token(str(sample_invited_user.id), current_app.config['SECRET_KEY'],
current_app.config['DANGEROUS_SALT'])
url = endpoint_format_str.format(token)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.get(url, headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
@@ -302,7 +302,7 @@ def test_validate_invitation_token_for_expired_token_returns_400(client):
token = generate_token(str(uuid.uuid4()), current_app.config['SECRET_KEY'],
current_app.config['DANGEROUS_SALT'])
url = '/invite/service/{}'.format(token)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.get(url, headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400
@@ -317,7 +317,7 @@ def test_validate_invitation_token_returns_400_when_invited_user_does_not_exist(
token = generate_token(str(uuid.uuid4()), current_app.config['SECRET_KEY'],
current_app.config['DANGEROUS_SALT'])
url = '/invite/service/{}'.format(token)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.get(url, headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 404
@@ -334,7 +334,7 @@ def test_validate_invitation_token_returns_400_when_token_is_malformed(client):
)[:-2]
url = '/invite/service/{}'.format(token)
auth_header = create_authorization_header()
auth_header = create_admin_authorization_header()
response = client.get(url, headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400