-
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.
Merge pull request #130 from jsmolar/metadata
Added generic auth rule method for authconfig
- Loading branch information
Showing
3 changed files
with
91 additions
and
21 deletions.
There are no files selected for viewing
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
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
32 changes: 32 additions & 0 deletions
32
testsuite/tests/kuadrant/authorino/metadata/test_user_info.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,32 @@ | ||
""" | ||
Tests for external auth metadata. Online fetching of (OIDC) UserInfo data, associated with an OIDC identity source: | ||
https://github.com/Kuadrant/authorino/blob/main/docs/features.md#oidc-userinfo-metadatauserinfo | ||
""" | ||
import pytest | ||
|
||
from testsuite.openshift.objects.auth_config import Rule | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def authorization(authorization, rhsso): | ||
""" | ||
Adds auth metadata OIDC UserInfo which fetches OIDC UserInfo in request-time. | ||
Adds a simple rule that accepts only when fetched UserInfo contains the email address of the default RHSSO user. | ||
""" | ||
user = rhsso.client.admin.get_user(rhsso.user) | ||
authorization.add_user_info_metadata("user-info", "rhsso") | ||
authorization.add_auth_rule("rule", Rule("auth.metadata.user-info.email", "eq", user["email"])) | ||
return authorization | ||
|
||
|
||
def test_correct_auth(client, auth): | ||
"""Tests auth when UserInfo email matches the email address""" | ||
response = client.get("get", auth=auth) | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_incorrect_auth(client, auth, rhsso): | ||
"""Updates RHSSO user email address and tests incorrect auth""" | ||
rhsso.client.admin.update_user(rhsso.user, {"email": "[email protected]"}) | ||
response = client.get("get", auth=auth) | ||
assert response.status_code == 403 |