mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
Change Tokens to ApiKey
Added name to ApiKey model
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from client.authentication import create_jwt_token
|
||||
from flask import json, url_for
|
||||
|
||||
from app.dao.tokens_dao import get_unsigned_token
|
||||
from app.dao.api_key_dao import get_unsigned_secret
|
||||
|
||||
|
||||
def test_should_not_allow_request_with_no_token(notify_api):
|
||||
@@ -33,13 +33,13 @@ def test_should_not_allow_request_with_incorrect_token(notify_api):
|
||||
assert data['error'] == 'Invalid token: signature'
|
||||
|
||||
|
||||
def test_should_not_allow_incorrect_path(notify_api, notify_db, notify_db_session, sample_token):
|
||||
def test_should_not_allow_incorrect_path(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = create_jwt_token(request_method="GET",
|
||||
request_path="/bad",
|
||||
secret=get_unsigned_token(sample_token.service_id),
|
||||
client_id=sample_token.service_id)
|
||||
secret=get_unsigned_secret(sample_api_key.service_id),
|
||||
client_id=sample_api_key.service_id)
|
||||
response = client.get(url_for('status.show_status'),
|
||||
headers={'Authorization': "Bearer {}".format(token)})
|
||||
assert response.status_code == 403
|
||||
@@ -47,10 +47,10 @@ def test_should_not_allow_incorrect_path(notify_api, notify_db, notify_db_sessio
|
||||
assert data['error'] == 'Invalid token: request'
|
||||
|
||||
|
||||
def test_should_not_allow_incorrect_method(notify_api, notify_db, notify_db_session, sample_token):
|
||||
def test_should_not_allow_incorrect_method(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = __create_post_token(sample_token.service_id, {})
|
||||
token = __create_post_token(sample_api_key.service_id, {})
|
||||
response = client.get(url_for('status.show_status'),
|
||||
headers={'Authorization': "Bearer {}".format(token)})
|
||||
assert response.status_code == 403
|
||||
@@ -58,11 +58,11 @@ def test_should_not_allow_incorrect_method(notify_api, notify_db, notify_db_sess
|
||||
assert data['error'] == 'Invalid token: request'
|
||||
|
||||
|
||||
def test_should_not_allow_invalid_secret(notify_api, notify_db, notify_db_session, sample_token):
|
||||
def test_should_not_allow_invalid_secret(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = create_jwt_token(request_method="POST", request_path="/", secret="not-so-secret",
|
||||
client_id=sample_token.service_id)
|
||||
client_id=sample_api_key.service_id)
|
||||
response = client.get(url_for('status.show_status'),
|
||||
headers={'Authorization': "Bearer {}".format(token)})
|
||||
assert response.status_code == 403
|
||||
@@ -70,10 +70,10 @@ def test_should_not_allow_invalid_secret(notify_api, notify_db, notify_db_sessio
|
||||
assert data['error'] == 'Invalid token: signature'
|
||||
|
||||
|
||||
def test_should_allow_valid_token(notify_api, notify_db, notify_db_session, sample_token):
|
||||
def test_should_allow_valid_token(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = __create_get_token(sample_token.service_id)
|
||||
token = __create_get_token(sample_api_key.service_id)
|
||||
response = client.get(url_for('status.show_status'),
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
assert response.status_code == 200
|
||||
@@ -86,20 +86,20 @@ JSON_BODY = json.dumps({
|
||||
})
|
||||
|
||||
|
||||
def test_should_allow_valid_token_with_post_body(notify_api, notify_db, notify_db_session, sample_token):
|
||||
def test_should_allow_valid_token_with_post_body(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = __create_post_token(sample_token.service_id, JSON_BODY)
|
||||
token = __create_post_token(sample_api_key.service_id, JSON_BODY)
|
||||
response = client.post(url_for('status.show_status'),
|
||||
data=JSON_BODY,
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_not_allow_valid_token_with_invalid_post_body(notify_api, notify_db, notify_db_session, sample_token):
|
||||
def test_should_not_allow_valid_token_with_invalid_post_body(notify_api, notify_db, notify_db_session, sample_api_key):
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
token = __create_post_token(sample_token.service_id, JSON_BODY)
|
||||
token = __create_post_token(sample_api_key.service_id, JSON_BODY)
|
||||
response = client.post(url_for('status.show_status'),
|
||||
data="spurious",
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
@@ -111,7 +111,7 @@ def test_should_not_allow_valid_token_with_invalid_post_body(notify_api, notify_
|
||||
def __create_get_token(service_id):
|
||||
return create_jwt_token(request_method="GET",
|
||||
request_path=url_for('status.show_status'),
|
||||
secret=get_unsigned_token(service_id),
|
||||
secret=get_unsigned_secret(service_id),
|
||||
client_id=service_id)
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ def __create_post_token(service_id, request_body):
|
||||
return create_jwt_token(
|
||||
request_method="POST",
|
||||
request_path=url_for('status.show_status'),
|
||||
secret=get_unsigned_token(service_id),
|
||||
secret=get_unsigned_secret(service_id),
|
||||
client_id=service_id,
|
||||
request_body=request_body
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user