Skip to content

Commit

Permalink
Adapt the OicAuthPluginTest to the changes in the describables (#1724)
Browse files Browse the repository at this point in the history
* Adapt the OicAuthPluginTest to the changes in the describables

* Use a PageArea for the Describable part

* Apply spotless
  • Loading branch information
fcojfernandez authored Sep 23, 2024
1 parent ef57fb3 commit a23ad46
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jenkinsci.test.acceptance.po;

import org.openqa.selenium.WebElement;

/**
* Security Realm provided by oic-auth plugin
*/
Expand All @@ -15,9 +17,10 @@ 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 <T extends OicAuthConfigurationMode> T useConfigurationMode(Class<T> type) {
WebElement option = findCaption(type, caption -> getElement(by.option(caption)));
option.click();
return newInstance(type, this);
}

public void setLogoutFromOpenidProvider(boolean logout) {
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/plugins/OicAuthPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -206,7 +207,10 @@ private void configureRealm() {
sc.open();
OicAuthSecurityRealm securityRealm = sc.useRealm(OicAuthSecurityRealm.class);
securityRealm.configureClient(CLIENT, CLIENT);
securityRealm.setAutomaticConfiguration(
// 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());
Expand Down

0 comments on commit a23ad46

Please sign in to comment.