From ce6c12ec7f6ad76a9e61a21645451211e005144a Mon Sep 17 00:00:00 2001 From: Francisco Javier Fernandez Gonzalez Date: Fri, 20 Sep 2024 11:32:27 +0200 Subject: [PATCH 1/3] Adapt the OicAuthPluginTest to the changes in the describables --- .../jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java | 6 +++--- src/test/java/plugins/OicAuthPluginTest.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java index 091c1ab7d..01ff225e4 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java @@ -15,9 +15,9 @@ public void configureClient(String clientId, String clientSecret) { control("clientSecret").set(clientSecret); } - public void setAutomaticConfiguration(String wellKnownEndpoint) { - control(by.radioButton("Automatic configuration")).click(); - control("wellKnownOpenIDConfigurationUrl").set(wellKnownEndpoint); + public void setWellKnownEndpoint(String wellKnownEndpoint) { + control("").select("Discovery via well-known endpoint"); // Select doesn't have the relative path, directly path=/securityRealm/ + control("serverConfiguration/wellKnownOpenIDConfigurationUrl").set(wellKnownEndpoint); } public void setLogoutFromOpenidProvider(boolean logout) { diff --git a/src/test/java/plugins/OicAuthPluginTest.java b/src/test/java/plugins/OicAuthPluginTest.java index 6b1a0eced..38f1efc62 100644 --- a/src/test/java/plugins/OicAuthPluginTest.java +++ b/src/test/java/plugins/OicAuthPluginTest.java @@ -206,7 +206,7 @@ private void configureRealm() { sc.open(); OicAuthSecurityRealm securityRealm = sc.useRealm(OicAuthSecurityRealm.class); securityRealm.configureClient(CLIENT, CLIENT); - securityRealm.setAutomaticConfiguration( + securityRealm.setWellKnownEndpoint( String.format("%s/realms/%s/.well-known/openid-configuration", keycloakUrl, REALM)); securityRealm.setLogoutFromOpenidProvider(true); securityRealm.setPostLogoutUrl(jenkins.url("OicLogout").toExternalForm()); From 1d8a510f771b9d82c111acb8a862738a4de9ba57 Mon Sep 17 00:00:00 2001 From: Francisco Javier Fernandez Gonzalez Date: Fri, 20 Sep 2024 14:28:17 +0200 Subject: [PATCH 2/3] Use a PageArea for the Describable part --- .../po/OicAuthConfigurationMode.java | 25 +++++++++++++++++++ .../acceptance/po/OicAuthSecurityRealm.java | 9 ++++--- src/test/java/plugins/OicAuthPluginTest.java | 6 +++-- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java new file mode 100644 index 000000000..a03b0128d --- /dev/null +++ b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java @@ -0,0 +1,25 @@ +package org.jenkinsci.test.acceptance.po; + +/** + * Class representing the entry controls for the configuration mode when using the oic-auth plugin + */ +public abstract class OicAuthConfigurationMode extends PageAreaImpl { + + protected OicAuthConfigurationMode(OicAuthSecurityRealm realm) { + super(realm, "serverConfiguration"); + } + + /** + * Class representing the entry controls for well-known endpoint when using the oic-auth plugin + */ + @Describable("Discovery via well-known endpoint") + public static class WellKnownEndpoint extends OicAuthConfigurationMode { + + public final Control wellKnownEndpoint = control("wellKnownOpenIDConfigurationUrl"); + + public WellKnownEndpoint(OicAuthSecurityRealm realm) { + super(realm); + } + } + +} diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java index 01ff225e4..8c2042c8a 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthSecurityRealm.java @@ -1,5 +1,7 @@ package org.jenkinsci.test.acceptance.po; +import org.openqa.selenium.WebElement; + /** * Security Realm provided by oic-auth plugin */ @@ -15,9 +17,10 @@ public void configureClient(String clientId, String clientSecret) { control("clientSecret").set(clientSecret); } - public void setWellKnownEndpoint(String wellKnownEndpoint) { - control("").select("Discovery via well-known endpoint"); // Select doesn't have the relative path, directly path=/securityRealm/ - control("serverConfiguration/wellKnownOpenIDConfigurationUrl").set(wellKnownEndpoint); + public T useConfigurationMode(Class type) { + WebElement option = findCaption(type, caption -> getElement(by.option(caption))); + option.click(); + return newInstance(type, this); } public void setLogoutFromOpenidProvider(boolean logout) { diff --git a/src/test/java/plugins/OicAuthPluginTest.java b/src/test/java/plugins/OicAuthPluginTest.java index 38f1efc62..f6ec1743e 100644 --- a/src/test/java/plugins/OicAuthPluginTest.java +++ b/src/test/java/plugins/OicAuthPluginTest.java @@ -18,6 +18,7 @@ import org.jenkinsci.test.acceptance.junit.WithPlugins; import org.jenkinsci.test.acceptance.po.GlobalSecurityConfig; import org.jenkinsci.test.acceptance.po.LoggedInAuthorizationStrategy; +import org.jenkinsci.test.acceptance.po.OicAuthConfigurationMode; import org.jenkinsci.test.acceptance.po.OicAuthSecurityRealm; import org.jenkinsci.test.acceptance.po.WhoAmI; import org.jenkinsci.test.acceptance.utils.keycloack.KeycloakUtils; @@ -206,8 +207,9 @@ private void configureRealm() { sc.open(); OicAuthSecurityRealm securityRealm = sc.useRealm(OicAuthSecurityRealm.class); securityRealm.configureClient(CLIENT, CLIENT); - securityRealm.setWellKnownEndpoint( - String.format("%s/realms/%s/.well-known/openid-configuration", keycloakUrl, REALM)); + // Configuration mode + OicAuthConfigurationMode.WellKnownEndpoint configurationMode = securityRealm.useConfigurationMode(OicAuthConfigurationMode.WellKnownEndpoint.class); + configurationMode.wellKnownEndpoint.set(String.format("%s/realms/%s/.well-known/openid-configuration", keycloakUrl, REALM)); securityRealm.setLogoutFromOpenidProvider(true); securityRealm.setPostLogoutUrl(jenkins.url("OicLogout").toExternalForm()); securityRealm.setUserFields(null, null, null, "groups"); From 599d980d0809be0775abb2ec4f93a0283a67b557 Mon Sep 17 00:00:00 2001 From: Francisco Javier Fernandez Gonzalez Date: Fri, 20 Sep 2024 15:08:15 +0200 Subject: [PATCH 3/3] Apply spotless --- .../test/acceptance/po/OicAuthConfigurationMode.java | 1 - src/test/java/plugins/OicAuthPluginTest.java | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java index a03b0128d..e42c95f7a 100644 --- a/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java +++ b/src/main/java/org/jenkinsci/test/acceptance/po/OicAuthConfigurationMode.java @@ -21,5 +21,4 @@ public WellKnownEndpoint(OicAuthSecurityRealm realm) { super(realm); } } - } diff --git a/src/test/java/plugins/OicAuthPluginTest.java b/src/test/java/plugins/OicAuthPluginTest.java index f6ec1743e..aa1f87269 100644 --- a/src/test/java/plugins/OicAuthPluginTest.java +++ b/src/test/java/plugins/OicAuthPluginTest.java @@ -208,8 +208,10 @@ private void configureRealm() { OicAuthSecurityRealm securityRealm = sc.useRealm(OicAuthSecurityRealm.class); securityRealm.configureClient(CLIENT, CLIENT); // Configuration mode - OicAuthConfigurationMode.WellKnownEndpoint configurationMode = securityRealm.useConfigurationMode(OicAuthConfigurationMode.WellKnownEndpoint.class); - configurationMode.wellKnownEndpoint.set(String.format("%s/realms/%s/.well-known/openid-configuration", keycloakUrl, REALM)); + OicAuthConfigurationMode.WellKnownEndpoint configurationMode = + securityRealm.useConfigurationMode(OicAuthConfigurationMode.WellKnownEndpoint.class); + configurationMode.wellKnownEndpoint.set( + String.format("%s/realms/%s/.well-known/openid-configuration", keycloakUrl, REALM)); securityRealm.setLogoutFromOpenidProvider(true); securityRealm.setPostLogoutUrl(jenkins.url("OicLogout").toExternalForm()); securityRealm.setUserFields(null, null, null, "groups");