-
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 #140 from pehala/fix_user_info
Fix user info test
- Loading branch information
Showing
2 changed files
with
12 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,25 @@ | |
""" | ||
import pytest | ||
|
||
from testsuite.httpx.auth import HttpxOidcClientAuth | ||
from testsuite.openshift.objects.auth_config import Rule | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def user2(rhsso): | ||
"""Second User which has incorrect email""" | ||
return rhsso.realm.create_user("user2", "password", email="[email protected]") | ||
|
||
|
||
@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"])) | ||
authorization.add_auth_rule("rule", | ||
Rule("auth.metadata.user-info.email", "eq", rhsso.user.properties["email"])) | ||
return authorization | ||
|
||
|
||
|
@@ -25,8 +32,8 @@ def test_correct_auth(client, auth): | |
assert response.status_code == 200 | ||
|
||
|
||
def test_incorrect_auth(client, auth, rhsso): | ||
def test_incorrect_auth(client, rhsso, user2): | ||
"""Updates RHSSO user email address and tests incorrect auth""" | ||
rhsso.client.admin.update_user(rhsso.user, {"email": "[email protected]"}) | ||
auth = HttpxOidcClientAuth(rhsso.get_token(user2.username, user2.password), "authorization") | ||
response = client.get("get", auth=auth) | ||
assert response.status_code == 403 |