-
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
7 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
Empty file.
25 changes: 25 additions & 0 deletions
25
testsuite/tests/kuadrant/authorino/identity/anonymous/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,25 @@ | ||
"""Test for anonymous identity context""" | ||
import json | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization): | ||
"""Setup AuthConfig for test""" | ||
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 |
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
testsuite/tests/kuadrant/authorino/identity/api_key/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,27 @@ | ||
"""Test for API key identity context""" | ||
import json | ||
|
||
import pytest | ||
|
||
|
||
@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 |
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
42 changes: 42 additions & 0 deletions
42
testsuite/tests/kuadrant/authorino/identity/rhsso/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,42 @@ | ||
"""Test for RHSSO identity context""" | ||
import json | ||
import time | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization): | ||
"""Setup AuthConfig for test""" | ||
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, realm_role): | ||
"""Add realm role to rhsso user""" | ||
rhsso.realm.assign_realm_role(realm_role, rhsso.user) | ||
return realm_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"] |
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