Skip to content

Commit 4301c16

Browse files
authored
Merge pull request #140 from pehala/fix_user_info
Fix user info test
2 parents 755b788 + 275fd4f commit 4301c16

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

testsuite/oidc/rhsso/objects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def create_user(self, username, password, **kwargs):
3333
"""Creates new user"""
3434
kwargs["username"] = username
3535
kwargs["enabled"] = True
36-
kwargs["email"] = f"{username}@anything.invalid"
36+
kwargs.setdefault("email", f"{username}@anything.invalid")
3737
self.admin.create_user(kwargs)
3838
user_id = self.admin.get_user_id(username)
3939
self.admin.set_user_password(user_id, password, temporary=False)

testsuite/tests/kuadrant/authorino/metadata/test_user_info.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,25 @@
44
"""
55
import pytest
66

7+
from testsuite.httpx.auth import HttpxOidcClientAuth
78
from testsuite.openshift.objects.auth_config import Rule
89

910

11+
@pytest.fixture(scope="module")
12+
def user2(rhsso):
13+
"""Second User which has incorrect email"""
14+
return rhsso.realm.create_user("user2", "password", email="[email protected]")
15+
16+
1017
@pytest.fixture(scope="module")
1118
def authorization(authorization, rhsso):
1219
"""
1320
Adds auth metadata OIDC UserInfo which fetches OIDC UserInfo in request-time.
1421
Adds a simple rule that accepts only when fetched UserInfo contains the email address of the default RHSSO user.
1522
"""
16-
user = rhsso.client.admin.get_user(rhsso.user)
1723
authorization.add_user_info_metadata("user-info", "rhsso")
18-
authorization.add_auth_rule("rule", Rule("auth.metadata.user-info.email", "eq", user["email"]))
24+
authorization.add_auth_rule("rule",
25+
Rule("auth.metadata.user-info.email", "eq", rhsso.user.properties["email"]))
1926
return authorization
2027

2128

@@ -25,8 +32,8 @@ def test_correct_auth(client, auth):
2532
assert response.status_code == 200
2633

2734

28-
def test_incorrect_auth(client, auth, rhsso):
35+
def test_incorrect_auth(client, rhsso, user2):
2936
"""Updates RHSSO user email address and tests incorrect auth"""
30-
rhsso.client.admin.update_user(rhsso.user, {"email": "[email protected]"})
37+
auth = HttpxOidcClientAuth(rhsso.get_token(user2.username, user2.password), "authorization")
3138
response = client.get("get", auth=auth)
3239
assert response.status_code == 403

0 commit comments

Comments
 (0)