Skip to content

Commit bafb76b

Browse files
committed
Merge pkce test into oidc test file
1 parent a20c49e commit bafb76b

File tree

2 files changed

+27
-227
lines changed

2 files changed

+27
-227
lines changed

tests/suite/test_oidc.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
create_secret_from_yaml,
1515
delete_common_app,
1616
delete_secret,
17+
delete_service,
1718
replace_configmap_from_yaml,
1819
wait_before_test,
1920
wait_until_all_pods_are_ready,
@@ -30,6 +31,7 @@
3031
keycloak_vs_src = f"{TEST_DATA}/oidc/virtual-server-idp.yaml"
3132
oidc_secret_src = f"{TEST_DATA}/oidc/client-secret.yaml"
3233
oidc_pol_src = f"{TEST_DATA}/oidc/oidc.yaml"
34+
pkce_pol_src = f"{TEST_DATA}/oidc/pkce.yaml"
3335
oidc_vs_src = f"{TEST_DATA}/oidc/virtual-server.yaml"
3436
orig_vs_src = f"{TEST_DATA}/virtual-server-tls/standard/virtual-server.yaml"
3537
cm_src = f"{TEST_DATA}/oidc/nginx-config.yaml"
@@ -81,6 +83,23 @@ def keycloak_setup(request, kube_apis, test_namespace, ingress_controller_endpoi
8183
}
8284
response = requests.post(create_user_url, headers=headers, json=user_payload, verify=False)
8385

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+
84103
# Create client "nginx-plus" and get secret
85104
create_client_url = f"https://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.port_ssl}/realms/master/clients-registrations/default"
86105
client_payload = {
@@ -128,6 +147,7 @@ def fin():
128147
)
129148
class TestOIDC:
130149
@pytest.mark.parametrize("configmap", [cm_src, cm_zs_src])
150+
@pytest.mark.parametrize("oidcYaml", [oidc_pol_src, pkce_pol_src])
131151
def test_oidc(
132152
self,
133153
request,
@@ -139,6 +159,7 @@ def test_oidc(
139159
virtual_server_setup,
140160
keycloak_setup,
141161
configmap,
162+
oidcYaml,
142163
):
143164
print(f"Create oidc secret")
144165
with open(oidc_secret_src) as f:
@@ -147,7 +168,7 @@ def test_oidc(
147168
secret_name = create_secret(kube_apis.v1, test_namespace, secret_data)
148169

149170
print(f"Create oidc policy")
150-
with open(oidc_pol_src) as f:
171+
with open(oidcYaml) as f:
151172
doc = yaml.safe_load(f)
152173
pol = doc["metadata"]["name"]
153174
doc["spec"]["oidc"]["tokenEndpoint"] = doc["spec"]["oidc"]["tokenEndpoint"].replace("default", test_namespace)
@@ -188,6 +209,11 @@ def test_oidc(
188209
patch_virtual_server_from_yaml(
189210
kube_apis.custom_objects, virtual_server_setup.vs_name, orig_vs_src, test_namespace
190211
)
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)
191217

192218

193219
def run_oidc(browser_type, ip_address, port):
@@ -199,11 +225,6 @@ def run_oidc(browser_type, ip_address, port):
199225
page = context.new_page()
200226

201227
page.goto("https://virtual-server-tls.example.com")
202-
203-
print("\n\n\n")
204-
print(page.content())
205-
print("\n\n\n")
206-
207228
page.wait_for_selector('input[name="username"]')
208229
page.fill('input[name="username"]', username)
209230
page.wait_for_selector('input[name="password"]', timeout=5000)

tests/suite/test_pkce.py

Lines changed: 0 additions & 221 deletions
This file was deleted.

0 commit comments

Comments
 (0)