-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
26 changes: 26 additions & 0 deletions
26
testsuite/tests/kuadrant/authorino/identity/context/test_anonymous_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Test for anonymous identity context""" | ||
import json | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, rhsso): | ||
"""Setup AuthConfig for test""" | ||
authorization.add_oidc_identity("rhsso", rhsso.well_known["issuer"]) | ||
authorization.add_anonymous_identity("anonymous") | ||
authorization.add_response({"name": "auth-json", "json": { | ||
"properties": [{"name": "auth", "valueFrom": {"authJSON": "auth"}}, | ||
{"name": "context", "valueFrom": {"authJSON": "context"}}]}}) | ||
return authorization | ||
|
||
|
||
def test_anonymous_context(client): | ||
""" | ||
Test: | ||
- Make request without authentication | ||
- Assert that response has the right information in context | ||
""" | ||
response = client.get("/get") | ||
assert json.loads(response.json()["headers"]["Auth-Json"])["auth"]["identity"]["anonymous"] | ||
assert response.status_code == 200 |
42 changes: 42 additions & 0 deletions
42
testsuite/tests/kuadrant/authorino/identity/context/test_api_key_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Test for API key identity context""" | ||
import json | ||
|
||
import pytest | ||
|
||
from testsuite.httpx.auth import HeaderApiKeyAuth | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def api_key(create_api_key, module_label): | ||
"""Creates API key Secret""" | ||
api_key = "api_key_value" | ||
return create_api_key("api-key", module_label, api_key) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def auth(api_key): | ||
"""Valid API Key Auth""" | ||
return HeaderApiKeyAuth(api_key) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, module_label): | ||
"""Setup AuthConfig for test""" | ||
authorization.add_api_key_identity("api_key", match_label=module_label) | ||
authorization.add_response({"name": "auth-json", "json": { | ||
"properties": [{"name": "auth", "valueFrom": {"authJSON": "auth"}}]}}) | ||
return authorization | ||
|
||
|
||
def tests_api_key_context(client, auth, api_key, module_label, testconfig): | ||
""" | ||
Test: | ||
- Make request with API key authentication | ||
- Assert that response has the right information in context | ||
""" | ||
response = client.get("get", auth=auth) | ||
assert response.status_code == 200 | ||
identity = json.loads(response.json()["headers"]["Auth-Json"])["auth"]["identity"] | ||
assert identity['data']['api_key'] == api_key.model.data.api_key | ||
assert identity["metadata"]["namespace"] == testconfig["openshift"].project | ||
assert identity["metadata"]["labels"]["group"] == module_label |
45 changes: 45 additions & 0 deletions
45
testsuite/tests/kuadrant/authorino/identity/context/test_rhsso_context.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Test for RHSSO identity context""" | ||
import json | ||
import time | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, rhsso): | ||
"""Setup AuthConfig for test""" | ||
authorization.add_oidc_identity("rhsso", rhsso.well_known["issuer"]) | ||
authorization.add_response({"name": "auth-json", "json": { | ||
"properties": [{"name": "auth", "valueFrom": {"authJSON": "auth"}}, | ||
{"name": "context", "valueFrom": {"authJSON": "context"}}]}}) | ||
return authorization | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def realm_role(rhsso, blame): | ||
"""Add realm role to rhsso user""" | ||
role_name = blame("realm_role") | ||
role = rhsso.realm.create_realm_role(role_name) | ||
rhsso.realm.assign_realm_role(role, rhsso.user) | ||
return role | ||
|
||
|
||
def tests_rhsso_context(client, auth, rhsso, realm_role): | ||
""" | ||
Test: | ||
- Make request with RHSSO authentication | ||
- Assert that response has the right information in context | ||
""" | ||
response = client.get("get", auth=auth) | ||
assert response.status_code == 200 | ||
auth_json = json.loads(response.json()["headers"]["Auth-Json"]) | ||
identity = auth_json["auth"]["identity"] | ||
context = auth_json["context"] | ||
now = time.time() | ||
assert rhsso.well_known["issuer"] == identity["iss"] | ||
assert identity["azp"] == rhsso.client_name | ||
assert float(identity["exp"]) > now | ||
assert float(identity["iat"]) <= now | ||
assert context["request"]["http"]["headers"]["authorization"] == f"Bearer {auth.token.access_token}" | ||
assert realm_role["name"] in identity["realm_access"]["roles"] | ||
assert identity['email'] == rhsso.client.admin.get_user(rhsso.user)["email"] |