mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 01:41:05 -05:00
attach api_key to app
we previously attached the service id and the key's secret also more refactoring of auth.py
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
from datetime import datetime
|
||||
from notifications_python_client.authentication import create_jwt_token
|
||||
|
||||
import pytest
|
||||
from flask import json, current_app
|
||||
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, KEY_TYPE_TEAM
|
||||
|
||||
@@ -164,7 +168,7 @@ def test_authentication_returns_token_expired_when_service_uses_expired_key_and_
|
||||
headers={'Authorization': 'Bearer {}'.format(token)})
|
||||
assert response.status_code == 403
|
||||
data = json.loads(response.get_data())
|
||||
assert data['message'] == {"token": ['Invalid token: signature']}
|
||||
assert data['message'] == {"token": ['Invalid token: revoked']}
|
||||
|
||||
|
||||
def test_authentication_returns_error_when_api_client_has_no_secrets(notify_api,
|
||||
@@ -220,3 +224,17 @@ def __create_post_token(service_id, request_body):
|
||||
secret=get_unsigned_secrets(service_id)[0],
|
||||
client_id=str(service_id)
|
||||
)
|
||||
|
||||
|
||||
def test_should_attach_the_current_api_key_to_current_app(notify_api, sample_service, sample_api_key):
|
||||
with notify_api.test_request_context() as context, notify_api.test_client() as client:
|
||||
with pytest.raises(AttributeError):
|
||||
print(api_user)
|
||||
|
||||
token = __create_get_token(sample_api_key.service_id)
|
||||
response = client.get(
|
||||
'/service/{}'.format(str(sample_api_key.service_id)),
|
||||
headers={'Authorization': 'Bearer {}'.format(token)}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert api_user == sample_api_key
|
||||
|
||||
Reference in New Issue
Block a user