mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-16 20:48:37 -04: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:
@@ -18,7 +18,7 @@ from app.models import (
|
||||
User,
|
||||
VerifyCode,
|
||||
)
|
||||
from tests import create_authorization_header
|
||||
from tests import create_admin_authorization_header
|
||||
|
||||
|
||||
@freeze_time('2016-01-01T12:00:00')
|
||||
@@ -29,7 +29,7 @@ def test_user_verify_sms_code(client, sample_sms_code):
|
||||
data = json.dumps({
|
||||
'code_type': sample_sms_code.code_type,
|
||||
'code': sample_sms_code.txt_code})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -45,7 +45,7 @@ def test_user_verify_code_missing_code(client,
|
||||
sample_sms_code):
|
||||
assert not VerifyCode.query.first().code_used
|
||||
data = json.dumps({'code_type': sample_sms_code.code_type})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -61,7 +61,7 @@ def test_user_verify_code_bad_code_and_increments_failed_login_count(client,
|
||||
data = json.dumps({
|
||||
'code_type': sample_sms_code.code_type,
|
||||
'code': "blah"})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
@@ -101,7 +101,7 @@ def test_user_verify_password(client, sample_user):
|
||||
yesterday = datetime.utcnow() - timedelta(days=1)
|
||||
sample_user.logged_in_at = yesterday
|
||||
data = json.dumps({'password': 'password'})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=data,
|
||||
@@ -113,7 +113,7 @@ def test_user_verify_password(client, sample_user):
|
||||
def test_user_verify_password_invalid_password(client,
|
||||
sample_user):
|
||||
data = json.dumps({'password': 'bad password'})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
assert sample_user.failed_login_count == 0
|
||||
|
||||
@@ -130,7 +130,7 @@ def test_user_verify_password_invalid_password(client,
|
||||
def test_user_verify_password_valid_password_resets_failed_logins(client,
|
||||
sample_user):
|
||||
data = json.dumps({'password': 'bad password'})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
assert sample_user.failed_login_count == 0
|
||||
|
||||
@@ -145,7 +145,7 @@ def test_user_verify_password_valid_password_resets_failed_logins(client,
|
||||
assert sample_user.failed_login_count == 1
|
||||
|
||||
data = json.dumps({'password': 'password'})
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=data,
|
||||
@@ -157,7 +157,7 @@ def test_user_verify_password_valid_password_resets_failed_logins(client,
|
||||
|
||||
def test_user_verify_password_missing_password(client,
|
||||
sample_user):
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_password', user_id=sample_user.id),
|
||||
data=json.dumps({'bingo': 'bongo'}),
|
||||
@@ -182,7 +182,7 @@ def test_send_user_sms_code(client,
|
||||
notify_service.research_mode = True
|
||||
dao_update_service(notify_service)
|
||||
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
mocked = mocker.patch('app.user.rest.create_secret_code', return_value='11111')
|
||||
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
||||
|
||||
@@ -218,7 +218,7 @@ def test_send_user_code_for_sms_with_optional_to_field(client,
|
||||
to_number = '+447119876757'
|
||||
mocked = mocker.patch('app.user.rest.create_secret_code', return_value='11111')
|
||||
mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
url_for('user.send_user_2fa_code', code_type='sms', user_id=sample_user.id),
|
||||
@@ -237,7 +237,7 @@ def test_send_user_code_for_sms_with_optional_to_field(client,
|
||||
|
||||
def test_send_sms_code_returns_404_for_bad_input_data(client):
|
||||
uuid_ = uuid.uuid4()
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_2fa_code', code_type='sms', user_id=uuid_),
|
||||
data=json.dumps({}),
|
||||
@@ -258,7 +258,7 @@ def test_send_sms_code_returns_204_when_too_many_codes_already_created(client, s
|
||||
db.session.add(verify_code)
|
||||
db.session.commit()
|
||||
assert VerifyCode.query.count() == 10
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_user_2fa_code', code_type='sms', user_id=sample_user.id),
|
||||
data=json.dumps({}),
|
||||
@@ -272,7 +272,7 @@ def test_send_new_user_email_verification(client,
|
||||
mocker,
|
||||
email_verification_template):
|
||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_new_user_email_verification', user_id=str(sample_user.id)),
|
||||
data=json.dumps({}),
|
||||
@@ -291,7 +291,7 @@ def test_send_email_verification_returns_404_for_bad_input_data(client, notify_d
|
||||
"""
|
||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
||||
uuid_ = uuid.uuid4()
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
resp = client.post(
|
||||
url_for('user.send_new_user_email_verification', user_id=uuid_),
|
||||
data=json.dumps({}),
|
||||
@@ -309,7 +309,7 @@ def test_user_verify_user_code_returns_404_when_code_is_right_but_user_account_i
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
headers=[('Content-Type', 'application/json'), create_admin_authorization_header()])
|
||||
assert resp.status_code == 404
|
||||
assert sample_sms_code.user.failed_login_count == 10
|
||||
assert not sample_sms_code.code_used
|
||||
@@ -323,7 +323,7 @@ def test_user_verify_user_code_valid_code_resets_failed_login_count(client, samp
|
||||
resp = client.post(
|
||||
url_for('user.verify_user_code', user_id=sample_sms_code.user.id),
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
headers=[('Content-Type', 'application/json'), create_admin_authorization_header()])
|
||||
assert resp.status_code == 204
|
||||
assert sample_sms_code.user.failed_login_count == 0
|
||||
assert sample_sms_code.code_used
|
||||
@@ -333,7 +333,7 @@ def test_user_reset_failed_login_count_returns_200(client, sample_user):
|
||||
sample_user.failed_login_count = 1
|
||||
resp = client.post(url_for("user.user_reset_failed_login_count", user_id=sample_user.id),
|
||||
data={},
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
headers=[('Content-Type', 'application/json'), create_admin_authorization_header()])
|
||||
assert resp.status_code == 200
|
||||
assert sample_user.failed_login_count == 0
|
||||
|
||||
@@ -341,7 +341,7 @@ def test_user_reset_failed_login_count_returns_200(client, sample_user):
|
||||
def test_reset_failed_login_count_returns_404_when_user_does_not_exist(client):
|
||||
resp = client.post(url_for("user.user_reset_failed_login_count", user_id=uuid.uuid4()),
|
||||
data={},
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header()])
|
||||
headers=[('Content-Type', 'application/json'), create_admin_authorization_header()])
|
||||
assert resp.status_code == 404
|
||||
|
||||
|
||||
@@ -480,7 +480,7 @@ def test_send_user_2fa_code_sends_from_number_for_international_numbers(
|
||||
client, sample_user, mocker, sms_code_template
|
||||
):
|
||||
sample_user.mobile_number = "601117224412"
|
||||
auth_header = create_authorization_header()
|
||||
auth_header = create_admin_authorization_header()
|
||||
mocker.patch('app.user.rest.create_secret_code', return_value='11111')
|
||||
mocker.patch('app.user.rest.send_notification_to_queue')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user