14
14
create_secret_from_yaml ,
15
15
delete_common_app ,
16
16
delete_secret ,
17
+ delete_service ,
17
18
replace_configmap_from_yaml ,
18
19
wait_before_test ,
19
20
wait_until_all_pods_are_ready ,
30
31
keycloak_vs_src = f"{ TEST_DATA } /oidc/virtual-server-idp.yaml"
31
32
oidc_secret_src = f"{ TEST_DATA } /oidc/client-secret.yaml"
32
33
oidc_pol_src = f"{ TEST_DATA } /oidc/oidc.yaml"
34
+ pkce_pol_src = f"{ TEST_DATA } /oidc/pkce.yaml"
33
35
oidc_vs_src = f"{ TEST_DATA } /oidc/virtual-server.yaml"
34
36
orig_vs_src = f"{ TEST_DATA } /virtual-server-tls/standard/virtual-server.yaml"
35
37
cm_src = f"{ TEST_DATA } /oidc/nginx-config.yaml"
@@ -81,6 +83,23 @@ def keycloak_setup(request, kube_apis, test_namespace, ingress_controller_endpoi
81
83
}
82
84
response = requests .post (create_user_url , headers = headers , json = user_payload , verify = False )
83
85
86
+ # Create client "nginx-plus-pkce" for the pkce test
87
+ create_pkce_client_url = f"https://{ ingress_controller_endpoint .public_ip } :{ ingress_controller_endpoint .port_ssl } /admin/realms/master/clients"
88
+ pkce_client_payload = {
89
+ "clientId" : "nginx-plus-pkce" ,
90
+ "redirectUris" : ["https://virtual-server-tls.example.com:443/_codexch" ],
91
+ "standardFlowEnabled" : True ,
92
+ "directAccessGrantsEnabled" : False ,
93
+ "publicClient" : True ,
94
+ "attributes" : {
95
+ "post.logout.redirect.uris" : "https://virtual-server-tls.example.com:443/*" ,
96
+ "pkce.code.challenge.method" : "S256" ,
97
+ },
98
+ "protocol" : "openid-connect" ,
99
+ }
100
+ pkce_client_resp = requests .post (create_pkce_client_url , headers = headers , json = pkce_client_payload , verify = False )
101
+ pkce_client_resp .raise_for_status ()
102
+
84
103
# Create client "nginx-plus" and get secret
85
104
create_client_url = f"https://{ ingress_controller_endpoint .public_ip } :{ ingress_controller_endpoint .port_ssl } /realms/master/clients-registrations/default"
86
105
client_payload = {
@@ -128,6 +147,7 @@ def fin():
128
147
)
129
148
class TestOIDC :
130
149
@pytest .mark .parametrize ("configmap" , [cm_src , cm_zs_src ])
150
+ @pytest .mark .parametrize ("oidcYaml" , [oidc_pol_src , pkce_pol_src ])
131
151
def test_oidc (
132
152
self ,
133
153
request ,
@@ -139,6 +159,7 @@ def test_oidc(
139
159
virtual_server_setup ,
140
160
keycloak_setup ,
141
161
configmap ,
162
+ oidcYaml ,
142
163
):
143
164
print (f"Create oidc secret" )
144
165
with open (oidc_secret_src ) as f :
@@ -147,7 +168,7 @@ def test_oidc(
147
168
secret_name = create_secret (kube_apis .v1 , test_namespace , secret_data )
148
169
149
170
print (f"Create oidc policy" )
150
- with open (oidc_pol_src ) as f :
171
+ with open (oidcYaml ) as f :
151
172
doc = yaml .safe_load (f )
152
173
pol = doc ["metadata" ]["name" ]
153
174
doc ["spec" ]["oidc" ]["tokenEndpoint" ] = doc ["spec" ]["oidc" ]["tokenEndpoint" ].replace ("default" , test_namespace )
@@ -188,6 +209,11 @@ def test_oidc(
188
209
patch_virtual_server_from_yaml (
189
210
kube_apis .custom_objects , virtual_server_setup .vs_name , orig_vs_src , test_namespace
190
211
)
212
+ if configmap == cm_src :
213
+ with open (svc_src ) as f :
214
+ headless_svc = yaml .safe_load (f )
215
+ headless_name = headless_svc ["metadata" ]["name" ]
216
+ delete_service (kube_apis .v1 , headless_name , ingress_controller_prerequisites .namespace )
191
217
192
218
193
219
def run_oidc (browser_type , ip_address , port ):
@@ -199,11 +225,6 @@ def run_oidc(browser_type, ip_address, port):
199
225
page = context .new_page ()
200
226
201
227
page .goto ("https://virtual-server-tls.example.com" )
202
-
203
- print ("\n \n \n " )
204
- print (page .content ())
205
- print ("\n \n \n " )
206
-
207
228
page .wait_for_selector ('input[name="username"]' )
208
229
page .fill ('input[name="username"]' , username )
209
230
page .wait_for_selector ('input[name="password"]' , timeout = 5000 )
0 commit comments