Skip to content

Commit

Permalink
Merge pull request #282 from averevki/fix-credentials-tests
Browse files Browse the repository at this point in the history
Fix tests with credentials
  • Loading branch information
pehala authored Nov 15, 2023
2 parents 09b32a5 + b58f236 commit 399d266
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
@pytest.fixture(scope="module", params=["authorizationHeader", "customHeader", "queryString", "cookie"])
def credentials(request):
"""Location where are auth credentials passed"""
return Credentials(request.param, "APIKEY")
return request.param


@pytest.fixture(scope="module")
def authorization(authorization, api_key, credentials):
"""Add API key identity to AuthConfig"""
authorization.identity.clear_all()
authorization.identity.add_api_key("api_key", credentials=credentials, selector=api_key.selector)
authorization.identity.add_api_key(
"api_key", credentials=Credentials(credentials, "APIKEY"), selector=api_key.selector
)
return authorization


def test_custom_selector(client, auth, credentials):
"""Test if auth credentials are stored in right place"""
response = client.get("/get", headers={"authorization": "API_KEY " + auth.api_key})
response = client.get("/get", headers={"authorization": "APIKEY " + auth.api_key})
if credentials == "authorizationHeader":
assert response.status_code == 200
else:
Expand All @@ -29,7 +31,7 @@ def test_custom_selector(client, auth, credentials):

def test_custom_header(client, auth, credentials):
"""Test if auth credentials are stored in right place"""
response = client.get("/get", headers={"API_KEY": auth.api_key})
response = client.get("/get", headers={"APIKEY": auth.api_key})
if credentials == "customHeader":
assert response.status_code == 200
else:
Expand All @@ -38,7 +40,7 @@ def test_custom_header(client, auth, credentials):

def test_query(client, auth, credentials):
"""Test if auth credentials are stored in right place"""
response = client.get("/get", params={"API_KEY": auth.api_key})
response = client.get("/get", params={"APIKEY": auth.api_key})
if credentials == "queryString":
assert response.status_code == 200
else:
Expand All @@ -47,7 +49,7 @@ def test_query(client, auth, credentials):

def test_cookie(route, auth, credentials):
"""Test if auth credentials are stored in right place"""
with route.client(cookies={"API_KEY": auth.api_key}) as client:
with route.client(cookies={"APIKEY": auth.api_key}) as client:
response = client.get("/get")
if credentials == "cookie":
assert response.status_code == 200
Expand Down

0 comments on commit 399d266

Please sign in to comment.