Skip to content

Commit

Permalink
Fix tests with credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Nov 15, 2023
1 parent 3bcb381 commit 2ec07b6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions testsuite/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def asdict(self):
return {self.in_location: {"prefix": self.keySelector}}
return {self.in_location: {"name": self.keySelector}}

def __eq__(self, other_location):
"""Equality operator for Credentials, compares only with 'in_location' key"""
return self.in_location == other_location


@dataclass
class Rule:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def authorization(authorization, api_key, credentials):

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 +29,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 +38,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 +47,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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
@pytest.fixture(scope="module", params=["authorizationHeader", "customHeader", "queryString", "cookie"])
def credentials(request):
"""Location where are auth credentials passed"""
return request.param
return Credentials(request.param, "Token")


@pytest.fixture(scope="module")
def authorization(authorization, rhsso, credentials):
"""Add RHSSO identity to Authorization"""
authorization.identity.clear_all()
authorization.identity.add_oidc("rhsso", rhsso.well_known["issuer"], credentials=Credentials(credentials, "Token"))
authorization.identity.add_oidc("rhsso", rhsso.well_known["issuer"], credentials=credentials)
return authorization


Expand Down

0 comments on commit 2ec07b6

Please sign in to comment.