[java-idp-integration-tests] 03/03: Add server hostname idp.tests.shibboleth.net and use it for OIDC tests
Tom Zeller
tzeller at dragonacea.biz
Tue Jul 16 22:39:05 UTC 2024
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=015f086e693cbbfb611a3e708bb808d4510aef32
commit 015f086e693cbbfb611a3e708bb808d4510aef32
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Tue Jul 16 17:38:45 2024 -0500
Add server hostname idp.tests.shibboleth.net and use it for OIDC tests
Support testing OIDC using Sauce Labs browsers
---
.../idp/integration/tests/BaseIntegrationTest.java | 26 ++++++++-
.../idp/integration/tests/oidc/OIDCTest.java | 64 +++++++++++-----------
.../idp/integration/tests/oidc/RPContainer.java | 49 +++++++++++++----
3 files changed, 94 insertions(+), 45 deletions(-)
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index 8bdfd31..af6afb9 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -26,6 +26,8 @@ import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@@ -289,6 +291,9 @@ public abstract class BaseIntegrationTest {
/** Secure address that clients should connect to. Defaults to "localhost". */
@Nonnull protected String secureAddress = "localhost";
+ /** Hostname that clients should connect to. Defaults to "idp.tests.shibboleth.net". */
+ @Nonnull protected String hostname = "idp.tests.shibboleth.net";
+
/** Non-secure web server base URL. Defaults to http://localhost:8080. */
@NonnullAfterInit protected String baseURL;
@@ -823,7 +828,7 @@ public abstract class BaseIntegrationTest {
if (Boolean.getBoolean("DNS")) {
urlBuilder.setHost(route53.name);
} else {
- urlBuilder.setHost(address);
+ urlBuilder.setHost(hostname);
}
urlBuilder.setPort(port);
baseURL = urlBuilder.buildURL();
@@ -835,7 +840,7 @@ public abstract class BaseIntegrationTest {
if (Boolean.getBoolean("DNS")) {
secureUrlBuilder.setHost(route53.name);
} else {
- secureUrlBuilder.setHost(secureAddress);
+ secureUrlBuilder.setHost(hostname);
}
secureUrlBuilder.setPort(securePort);
secureBaseURL = secureUrlBuilder.buildURL();
@@ -2779,7 +2784,7 @@ public abstract class BaseIntegrationTest {
installerCommands.add(pathToIdPHome.toAbsolutePath().toString());
// hostName
installerCommands.add("--hostName");
- installerCommands.add("idp");
+ installerCommands.add(hostname);
// scope
installerCommands.add("--scope");
installerCommands.add("example.org");
@@ -3227,4 +3232,19 @@ public abstract class BaseIntegrationTest {
return Boolean.getBoolean("tomcat");
}
+ /**
+ * Set up host name from secure base URL.
+ */
+ @BeforeClass(dependsOnMethods = { "setUpBaseURLs" })
+ public void setUpHostname() {
+ try {
+ final URI baseURI = new URI(getBaseURL(true));
+ hostname = baseURI.getHost();
+ log.debug("Will use host name '{}'", hostname);
+ } catch (URISyntaxException e) {
+ log.error("Unable to determine host name", e);
+ throw new RuntimeException(e);
+ }
+ }
+
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OIDCTest.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OIDCTest.java
index 51caf4c..ff469fd 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OIDCTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OIDCTest.java
@@ -305,16 +305,14 @@ public class OIDCTest extends BaseIntegrationTest {
assert pathToOpenIDConfiguration.toFile().exists() : "Path to openid-configuration.json not found";
- // Replace service_name with IdP's FQDN and port
- final String serviceName = "idp.tests.shibboleth.net:" + securePort;
-
- replaceFile(pathToOpenIDConfiguration, "\\{\\{ service_name \\}\\}", serviceName);
-
- // Remove port from issuer URL
+ // Replace template issuer "{{ service_name }}" with static value "https://idp.tests.shibboleth.net"
replaceFile(pathToOpenIDConfiguration, //
- "\"issuer\":\"https://idp.tests.shibboleth.net:" + securePort + "\"", //
+ "\"issuer\":\"https://\\{\\{ service_name \\}\\}\"", //
"\"issuer\":\"https://idp.tests.shibboleth.net\"");
+ // Replace template endpoint "{{ service_name }}" with OP host and port
+ replaceFile(pathToOpenIDConfiguration, "\\{\\{ service_name \\}\\}", hostname + ":" + securePort);
+
// Jetty
if (pathToJettyBase != null) {
@@ -402,27 +400,31 @@ public class OIDCTest extends BaseIntegrationTest {
/**
* Start RP.
*
- * @param hostname
- * the hostname
+ * @param id
+ * the id for logging
* @param clientID
* the client ID
* @return
* @throws ComponentInitializationException
* if an error occurs
*/
- protected RPContainer startRP(@Nonnull final String hostname, @Nonnull final String clientID)
+ protected RPContainer startRP(@Nonnull final String id, @Nonnull final String clientID)
throws ComponentInitializationException {
final RPContainer rp = new RPContainer();
rps.add(rp);
- rp.setId(hostname);
+ rp.setId(id);
rp.setClientID(clientID);
+ rp.setOPHost(hostname);
+
rp.setOPPort(securePort.toString());
+ rp.setRPHost(hostname);
+
setUpRPKeyStore(rp);
rp.initialize();
@@ -433,21 +435,21 @@ public class OIDCTest extends BaseIntegrationTest {
}
/**
- * Update client port in their metadata.
+ * Update client metadata.
*
- * @param oldPort
- * the old client port
- * @param newPort
- * the new client port
+ * @param oldData
+ * the old client data
+ * @param newData
+ * the new client data
* @throws IOException
* if an error occurs
*/
- protected void updateClientPort(@Nonnull final String oldPort, @Nonnull final String newPort) throws IOException {
+ protected void updateClientMetadata(@Nonnull final String oldData, @Nonnull final String newData) throws IOException {
final Path pathToOIDCClientJSON = pathToIdPHome.resolve(Paths.get("metadata", "oidc-client.json"));
assert pathToOIDCClientJSON.toFile().exists() : "Path to oidc-client.json not found";
- replaceFile(pathToOIDCClientJSON, oldPort, newPort);
+ replaceFile(pathToOIDCClientJSON, oldData, newData);
}
/**
@@ -455,9 +457,7 @@ public class OIDCTest extends BaseIntegrationTest {
*/
protected void getOpenIDConfigurationFromBrowser() {
- final String baseURL = "https://idp.tests.shibboleth.net:" + securePort;
-
- final String openidConfigurationURL = baseURL + "/.well-known/openid-configuration";
+ final String openidConfigurationURL = getBaseURL(true) + "/.well-known/openid-configuration";
log.debug("Attempting to get openid-configuration URL '{}' from browser", openidConfigurationURL);
@@ -483,9 +483,7 @@ public class OIDCTest extends BaseIntegrationTest {
protected void getOpenIDConfigurationFromContainer(@Nonnull final RPContainer rp)
throws UnsupportedOperationException, IOException, InterruptedException {
- final String baseURL = "https://idp.tests.shibboleth.net:" + securePort;
-
- final String openidConfigurationURL = baseURL + "/.well-known/openid-configuration";
+ final String openidConfigurationURL = getBaseURL(true) + "/.well-known/openid-configuration";
log.debug("Attempting to get openid-configuration URL '{}' from container", openidConfigurationURL);
@@ -553,15 +551,19 @@ public class OIDCTest extends BaseIntegrationTest {
// Start rp.tests.shibboleth.net
- final RPContainer rp = startRP("rp.tests.shibboleth.net", "test_oidc_rp");
+ final RPContainer rp = startRP("rp", "test_oidc_rp");
- updateClientPort("40443", rp.httpsPort.toString());
+ updateClientMetadata("40443", rp.httpsPort.toString());
+
+ updateClientMetadata("rp.tests.shibboleth.net", rp.rpHost);
// Start rp1.tests.shibboleth.net
- final RPContainer rp1 = startRP("rp1.tests.shibboleth.net", "test_oidc_rp_1");
+ final RPContainer rp1 = startRP("rp1", "test_oidc_rp_1");
- updateClientPort("41443", rp1.httpsPort.toString());
+ updateClientMetadata("41443", rp1.httpsPort.toString());
+
+ updateClientMetadata("rp1.tests.shibboleth.net", rp1.rpHost);
// Start IdP
@@ -569,8 +571,6 @@ public class OIDCTest extends BaseIntegrationTest {
assertPluginsAreOnStatusPage(plugins);
- secureBaseURL = "https://idp.tests.shibboleth.net:" + securePort;
-
startSeleniumClient(browserData);
getOpenIDConfigurationFromBrowser();
@@ -591,7 +591,7 @@ public class OIDCTest extends BaseIntegrationTest {
Assert.assertTrue(getPageSource().contains("OIDC_CLAIM_sub=\"jdoe at example.org\""));
- Assert.assertTrue(getPageSource().contains("SERVER_NAME=\"rp.tests.shibboleth.net\""));
+ Assert.assertTrue(getPageSource().contains("SERVER_NAME=\"" + rp.rpHost + "\""));
// SSO to rp1.tests.shibboleth.net
@@ -603,7 +603,7 @@ public class OIDCTest extends BaseIntegrationTest {
Assert.assertTrue(getPageSource().contains("OIDC_CLAIM_sub=\"jdoe at example.org\""));
- Assert.assertTrue(getPageSource().contains("SERVER_NAME=\"rp1.tests.shibboleth.net\""));
+ Assert.assertTrue(getPageSource().contains("SERVER_NAME=\"" + rp1.rpHost + "\""));
// TODO more asserts
}
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/RPContainer.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/RPContainer.java
index 4b5bd8f..34ce567 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/RPContainer.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/RPContainer.java
@@ -94,10 +94,18 @@ public class RPContainer extends AbstractIdentifiableInitializableComponent impl
@NonnullAfterInit
private Path pathToRP;
+ /** OP hostname or FQDN, defaults to "idp.tests.shibboleth.net" */
+ @Nonnull
+ private String opHost = "idp.tests.shibboleth.net";
+
/** Port used by the OP. */
@Nonnull
private String opPort = "443";
+ /** RP hostname or FQDN, defaults to "rp.tests.shibboleth.net" */
+ @Nonnull
+ public String rpHost = "rp.tests.shibboleth.net";
+
/** RP client ID, default 'test_oidc_rp'. */
@Nonnull
private String clientID = "test_oidc_rp";
@@ -229,16 +237,16 @@ public class RPContainer extends AbstractIdentifiableInitializableComponent impl
container.withAccessToHost(true);
// Add DNS resolution for the IdP / OP
- container.withExtraHost("idp.tests.shibboleth.net", "host-gateway");
+ container.withExtraHost(opHost, "host-gateway");
- // Set container name to the id
+ // Set container name to the RP id
container.withCreateContainerCmdModifier(cmd -> cmd.withName(getId()));
- // Set container hostname to the id
- container.withCreateContainerCmdModifier(cmd -> cmd.withHostName(getId()));
+ // Set container hostname to the RP host name
+ container.withCreateContainerCmdModifier(cmd -> cmd.withHostName(rpHost));
- // Set 'ServerName' environment variable to the id
- container.withEnv("ServerName", getId());
+ // Set 'ServerName' environment variable to the RP host name
+ container.withEnv("ServerName", rpHost);
// Set 'OIDCClientID' environment variable
container.withEnv("OIDCClientID", getClientID());
@@ -247,8 +255,7 @@ public class RPContainer extends AbstractIdentifiableInitializableComponent impl
container.withEnv("OIDCRedirectURI", getRedirectURI());
// set OIDCProviderMetadataURL
- final String OIDCProviderMetadataURL = //
- "https://idp.tests.shibboleth.net:" + opPort + "/.well-known/openid-configuration";
+ final String OIDCProviderMetadataURL = "https://" + opHost + ":" + opPort + "/.well-known/openid-configuration";
container.withEnv("OIDCProviderMetadataURL", OIDCProviderMetadataURL);
// Expose ports 80 and 443
@@ -263,12 +270,12 @@ public class RPContainer extends AbstractIdentifiableInitializableComponent impl
*
* For example : "https://rp.tests.shibboleth.net:<port>"
*
- * The host name / FQDN is set via {@link #setId(String)}.
+ * The host name / FQDN is set via {@link #setRPHost(String)}.
*
* @return base URL
*/
public String getBaseURL() {
- return "https://" + getId() + ":" + httpsPort.toString();
+ return "https://" + rpHost + ":" + httpsPort.toString();
}
/**
@@ -299,6 +306,17 @@ public class RPContainer extends AbstractIdentifiableInitializableComponent impl
super.setId(componentId);
}
+ /**
+ * Set the hostname or FQDN of the OP.
+ *
+ * @param port
+ * OP port
+ */
+ public void setOPHost(@Nonnull final String host) {
+ Constraint.isNotNull(host, "OP host cannot be null");
+ opHost = host;
+ }
+
/**
* Set the OP port used to construct the OIDCProviderMetadataURL.
*
@@ -310,6 +328,17 @@ public class RPContainer extends AbstractIdentifiableInitializableComponent impl
opPort = port;
}
+ /**
+ * Set the hostname or FQDN of the RP.
+ *
+ * @param port
+ * OP port
+ */
+ public void setRPHost(@Nonnull final String host) {
+ Constraint.isNotNull(host, "RP host cannot be null");
+ rpHost = host;
+ }
+
/**
* Set the path to the TLS keystore.
*
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list