Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_auth_credentials.py #246

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Test for RHSSO auth credentials"""
import pytest

from testsuite.openshift.objects.auth_config import AuthConfig
from testsuite.objects import Credentials


Expand All @@ -12,33 +11,45 @@ def credentials(request):


@pytest.fixture(scope="module")
def authorization(rhsso, openshift, blame, route, module_label, credentials):
"""Add RHSSO identity to AuthConfig"""
authorization = AuthConfig.create_instance(openshift, blame("ac"), route, labels={"testRun": module_label})
def authorization(authorization, rhsso, credentials):
"""Add RHSSO identity to Authorization"""
authorization.identity.clear_all()
pehala marked this conversation as resolved.
Show resolved Hide resolved
authorization.identity.add_oidc("rhsso", rhsso.well_known["issuer"], credentials=Credentials(credentials, "Token"))
return authorization


def test_custom_selector(client, auth, credentials):
"""Test if auth credentials are stored in right place"""
response = client.get("/get", headers={"authorization": "Token " + auth.token.access_token})
assert response.status_code == 200 if credentials == "authorization_header" else 401
averevki marked this conversation as resolved.
Show resolved Hide resolved
if credentials == "authorization_header":
assert response.status_code == 200
else:
assert response.status_code == 401


def test_custom_header(client, auth, credentials):
"""Test if auth credentials are stored in right place"""
response = client.get("/get", headers={"Token": auth.token.access_token})
assert response.status_code == 200 if credentials == "custom_header" else 401
if credentials == "custom_header":
assert response.status_code == 200
else:
assert response.status_code == 401


def test_query(client, auth, credentials):
"""Test if auth credentials are stored in right place"""
response = client.get("/get", params={"Token": auth.token.access_token})
assert response.status_code == 200 if credentials == "query" else 401
if credentials == "query":
assert response.status_code == 200
else:
assert response.status_code == 401


def test_cookie(route, auth, credentials):
"""Test if auth credentials are stored in right place"""
with route.client(cookies={"Token": auth.token.access_token}) as client:
response = client.get("/get")
assert response.status_code == 200 if credentials == "cookie" else 401
if credentials == "cookie":
assert response.status_code == 200
else:
assert response.status_code == 401