mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 10:21:14 -05:00
Improve text for error messages
This commit is contained in:
@@ -12,7 +12,7 @@ from notifications_python_client.authentication import create_jwt_token
|
||||
from app import api_user
|
||||
from app.dao.api_key_dao import get_unsigned_secrets, save_model_api_key, get_unsigned_secret, expire_api_key
|
||||
from app.models import ApiKey, KEY_TYPE_NORMAL
|
||||
from app.authentication.auth import AuthError, requires_admin_auth, requires_auth
|
||||
from app.authentication.auth import AuthError, requires_admin_auth, requires_auth, GENERAL_TOKEN_ERROR_MESSAGE
|
||||
|
||||
from tests.conftest import set_config
|
||||
|
||||
@@ -22,7 +22,7 @@ def test_should_not_allow_request_with_no_token(client, auth_fn):
|
||||
request.headers = {}
|
||||
with pytest.raises(AuthError) as exc:
|
||||
auth_fn()
|
||||
assert exc.value.short_message == 'Unauthorized, authentication token must be provided'
|
||||
assert exc.value.short_message == 'Unauthorized: authentication token must be provided'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('auth_fn', [requires_auth, requires_admin_auth])
|
||||
@@ -30,7 +30,7 @@ def test_should_not_allow_request_with_incorrect_header(client, auth_fn):
|
||||
request.headers = {'Authorization': 'Basic 1234'}
|
||||
with pytest.raises(AuthError) as exc:
|
||||
auth_fn()
|
||||
assert exc.value.short_message == 'Unauthorized, authentication bearer scheme must be used'
|
||||
assert exc.value.short_message == 'Unauthorized: authentication bearer scheme must be used'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('auth_fn', [requires_auth, requires_admin_auth])
|
||||
@@ -38,7 +38,7 @@ def test_should_not_allow_request_with_incorrect_token(client, auth_fn):
|
||||
request.headers = {'Authorization': 'Bearer 1234'}
|
||||
with pytest.raises(AuthError) as exc:
|
||||
auth_fn()
|
||||
assert exc.value.short_message == 'Invalid token: signature, api token is not valid'
|
||||
assert exc.value.short_message == GENERAL_TOKEN_ERROR_MESSAGE
|
||||
|
||||
|
||||
@pytest.mark.parametrize('auth_fn', [requires_auth, requires_admin_auth])
|
||||
@@ -80,7 +80,7 @@ def test_auth_should_not_allow_request_with_no_iat(client, sample_api_key):
|
||||
request.headers = {'Authorization': 'Bearer {}'.format(token)}
|
||||
with pytest.raises(AuthError) as exc:
|
||||
requires_auth()
|
||||
assert exc.value.short_message == 'Invalid token: signature, api token not found'
|
||||
assert exc.value.short_message == 'Invalid token: API key not found'
|
||||
|
||||
|
||||
def test_auth_should_not_allow_request_with_non_hs256_algorithm(client, sample_api_key):
|
||||
@@ -123,7 +123,7 @@ def test_admin_auth_should_not_allow_request_with_no_iat(client, sample_api_key)
|
||||
request.headers = {'Authorization': 'Bearer {}'.format(token)}
|
||||
with pytest.raises(AuthError) as exc:
|
||||
requires_admin_auth()
|
||||
assert exc.value.short_message == 'Invalid token: signature, api token is not valid'
|
||||
assert exc.value.short_message == "Invalid token: could not decode your API token"
|
||||
|
||||
|
||||
def test_auth_should_not_allow_request_with_extra_claims(client, sample_api_key):
|
||||
@@ -146,7 +146,7 @@ def test_auth_should_not_allow_request_with_extra_claims(client, sample_api_key)
|
||||
request.headers = {'Authorization': 'Bearer {}'.format(token)}
|
||||
with pytest.raises(AuthError) as exc:
|
||||
requires_auth()
|
||||
assert exc.value.short_message == 'Invalid token: signature, api token is not valid'
|
||||
assert exc.value.short_message == GENERAL_TOKEN_ERROR_MESSAGE
|
||||
|
||||
|
||||
def test_should_not_allow_invalid_secret(client, sample_api_key):
|
||||
@@ -159,7 +159,7 @@ def test_should_not_allow_invalid_secret(client, sample_api_key):
|
||||
)
|
||||
assert response.status_code == 403
|
||||
data = json.loads(response.get_data())
|
||||
assert data['message'] == {"token": ['Invalid token: signature, api token not found']}
|
||||
assert data['message'] == {"token": ['Invalid token: API key not found']}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('scheme', ['bearer', 'Bearer'])
|
||||
@@ -276,7 +276,7 @@ def test_authentication_returns_error_when_admin_client_has_no_secrets(client):
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
assert response.status_code == 403
|
||||
error_message = json.loads(response.get_data())
|
||||
assert error_message['message'] == {"token": ["Invalid token: signature, api token is not valid"]}
|
||||
assert error_message['message'] == {"token": ["Invalid token: could not decode your API token"]}
|
||||
|
||||
|
||||
def test_authentication_returns_error_when_admin_client_secret_is_invalid(client):
|
||||
@@ -291,7 +291,7 @@ def test_authentication_returns_error_when_admin_client_secret_is_invalid(client
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
assert response.status_code == 403
|
||||
error_message = json.loads(response.get_data())
|
||||
assert error_message['message'] == {"token": ["Invalid token: signature, api token is not valid"]}
|
||||
assert error_message['message'] == {"token": ["Invalid token: could not decode your API token"]}
|
||||
current_app.config['ADMIN_CLIENT_SECRET'] = api_secret
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user