4
4
"""
5
5
import pytest
6
6
7
+ from testsuite .httpx .auth import HttpxOidcClientAuth
7
8
from testsuite .openshift .objects .auth_config import Rule
8
9
9
10
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
+
10
17
@pytest .fixture (scope = "module" )
11
18
def authorization (authorization , rhsso ):
12
19
"""
13
20
Adds auth metadata OIDC UserInfo which fetches OIDC UserInfo in request-time.
14
21
Adds a simple rule that accepts only when fetched UserInfo contains the email address of the default RHSSO user.
15
22
"""
16
- user = rhsso .client .admin .get_user (rhsso .user )
17
23
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" ]))
19
26
return authorization
20
27
21
28
@@ -25,8 +32,8 @@ def test_correct_auth(client, auth):
25
32
assert response .status_code == 200
26
33
27
34
28
- def test_incorrect_auth (client , auth , rhsso ):
35
+ def test_incorrect_auth (client , rhsso , user2 ):
29
36
"""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" )
31
38
response = client .get ("get" , auth = auth )
32
39
assert response .status_code == 403
0 commit comments