[java-idp-integration-tests] 07/10: Cleanup - reorder AbstractOPTest methods

Tom Zeller tzeller at dragonacea.biz
Wed Aug 28 22:38:35 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=54c7f0696a6d3cc4ee7afe16e3be46b9f0b6a492

commit 54c7f0696a6d3cc4ee7afe16e3be46b9f0b6a492
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Tue Aug 27 23:50:31 2024 -0500

    Cleanup - reorder AbstractOPTest methods
---
 .../idp/integration/tests/oidc/AbstractOPTest.java | 315 +++++++++++----------
 .../idp/integration/tests/oidc/OPTest.java         |   2 +
 2 files changed, 167 insertions(+), 150 deletions(-)

diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java
index 0d4f957..8afe77e 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/AbstractOPTest.java
@@ -55,51 +55,21 @@ public class AbstractOPTest extends BaseIntegrationTest {
     protected final List<RPContainer> rps = new ArrayList<>();
 
     /**
-     * Enable OIDC credentials.
-     * 
-     * @throws IOException
-     *             if an error occurs
-     */
-    protected void enableOIDCCredentials() throws IOException {
-
-        final Path pathToCredentialsXML = pathToIdPHome.resolve(Paths.get("conf", "credentials.xml"));
-
-        assert pathToCredentialsXML.toAbsolutePath().toFile().exists() : "Path to credentials.xml not found";
-
-        final String oldText = "</beans>";
-
-        final StringBuilder newText = new StringBuilder();
-
-        newText.append("<!-- OIDC extension default credential definitions -->\n");
-
-        newText.append("<import resource=\"oidc-credentials.xml\" />\n");
-
-        newText.append(oldText + "\n");
-
-        replaceFile(pathToCredentialsXML, oldText, newText.toString());
-    }
-
-    /**
-     * Enable OIDC attributes / claim rules.
+     * Register client by copying metadata/oidc-client.json.
      * 
      * @throws IOException
      *             if an error occurs
      */
-    protected void enableOIDCAttributes() throws IOException {
-
-        final Path pathToDefaultRulesXML = pathToIdPHome.resolve(Paths.get("conf", "attributes", "default-rules.xml"));
-
-        assert pathToDefaultRulesXML.toAbsolutePath().toFile().exists() : "Path to default-rules.xml not found";
-
-        final String oldText = "</beans>";
+    protected void copyStaticClientRegistrations() throws IOException {
 
-        final StringBuilder newText = new StringBuilder();
+        final Path pathToOIDCClientJSON = Paths.get("src", "test", "oidc", "shibboleth-idp", "metadata",
+                "oidc-client.json");
 
-        newText.append(" <import resource=\"oidc-claim-rules.xml\" />\n");
+        assert pathToOIDCClientJSON.toFile().exists() : "Path to oidc-client.json not found";
 
-        newText.append(oldText + "\n");
+        final Path destPath = pathToIdPHome.resolve(Paths.get("metadata", "oidc-client.json"));
 
-        replaceFile(pathToDefaultRulesXML, oldText, newText.toString());
+        Files.copy(pathToOIDCClientJSON, destPath, StandardCopyOption.REPLACE_EXISTING);
     }
 
     /**
@@ -199,83 +169,51 @@ public class AbstractOPTest extends BaseIntegrationTest {
     }
 
     /**
-     * Add OIDC.Keyset and OIDC.Configuration to unverified relying party.
-     * 
-     * Add default OIDC profiles to default relying party.
+     * Enable OIDC attributes / claim rules.
      * 
      * @throws IOException
      *             if an error occurs
      */
-    protected void enableOIDCProfiles() throws IOException {
-
-        final Path pathToRelyingPartyXML = pathToIdPHome.resolve(Paths.get("conf", "relying-party.xml"));
-
-        assert pathToRelyingPartyXML.toAbsolutePath().toFile().exists() : "Path to relying-party.xml not found";
-
-        // Add <ref bean="OIDC.Keyset" /> to shibboleth.UnverifiedRelyingParty
-        // Add <ref bean="OIDC.Configuration" /> to shibboleth.UnverifiedRelyingParty
+    protected void enableOIDCAttributes() throws IOException {
 
-        final String unverifiedRPText = "<!-- <bean parent=\"SAML2.SSO\" p:encryptAssertions=\"false\" /> -->";
+        final Path pathToDefaultRulesXML = pathToIdPHome.resolve(Paths.get("conf", "attributes", "default-rules.xml"));
 
-        final StringBuilder addToUnverified = new StringBuilder();
-        addToUnverified.append("<ref bean=\"OIDC.Keyset\" />\n");
-        addToUnverified.append("<ref bean=\"OIDC.Configuration\" />\n");
+        assert pathToDefaultRulesXML.toAbsolutePath().toFile().exists() : "Path to default-rules.xml not found";
 
-        replaceFile(pathToRelyingPartyXML, unverifiedRPText, unverifiedRPText + "\n" + addToUnverified.toString());
+        final String oldText = "</beans>";
 
-        // Add default OIDC profiles to default relying party
+        final StringBuilder newText = new StringBuilder();
 
-        final String defaultRPText = "<ref bean=\"SAML2.ArtifactResolution\" />";
+        newText.append(" <import resource=\"oidc-claim-rules.xml\" />\n");
 
-        final StringBuilder addToDefault = new StringBuilder();
-        addToDefault.append("<ref bean=\"OIDC.SSO\" />\n");
-        addToDefault.append("<ref bean=\"OIDC.UserInfo\" />\n");
-        addToDefault.append("<ref bean=\"OAUTH2.Token\" />\n");
-        addToDefault.append("<ref bean=\"OAUTH2.Revocation\" />\n");
-        addToDefault.append("<ref bean=\"OAUTH2.Introspection\" />\n");
+        newText.append(oldText + "\n");
 
-        replaceFile(pathToRelyingPartyXML, defaultRPText, defaultRPText + "\n" + addToDefault.toString());
+        replaceFile(pathToDefaultRulesXML, oldText, newText.toString());
     }
 
     /**
-     * Enable client registration.
+     * Enable OIDC credentials.
      * 
      * @throws IOException
      *             if an error occurs
      */
-    protected void enableStaticClientRegistration() throws IOException {
-
-        final Path pathToOIDCClientInfoResolversXML = pathToIdPHome
-                .resolve(Paths.get("conf", "oidc-clientinfo-resolvers.xml"));
-
-        assert pathToOIDCClientInfoResolversXML.toFile().exists() : "Path to oidc-clientinfo-resolvers.xml not found";
+    protected void enableOIDCCredentials() throws IOException {
 
-        // Uncomment ExampleFileResolver
-        final String toUncomment = "<bean id=\"ExampleFileResolver\" parent=\"shibboleth.oidc.FilesystemClientInformationResolver\"\\\n"
-                + "        c:metadata=\"%\\{idp.home\\}/metadata/oidc-client.json\" />";
+        final Path pathToCredentialsXML = pathToIdPHome.resolve(Paths.get("conf", "credentials.xml"));
 
-        uncommentFile(pathToOIDCClientInfoResolversXML, toUncomment);
+        assert pathToCredentialsXML.toAbsolutePath().toFile().exists() : "Path to credentials.xml not found";
 
-        // Uncomment <ref bean="ExampleFileResolver" />
-        uncommentFile(pathToOIDCClientInfoResolversXML, "<ref bean=\"ExampleFileResolver\" />");
-    }
+        final String oldText = "</beans>";
 
-    /**
-     * Register client by copying metadata/oidc-client.json.
-     * 
-     * @throws IOException
-     *             if an error occurs
-     */
-    protected void copyStaticClientRegistrations() throws IOException {
+        final StringBuilder newText = new StringBuilder();
 
-        final Path pathToOIDCClientJSON = Paths.get("src", "test", "oidc", "shibboleth-idp", "metadata",
-                "oidc-client.json");
+        newText.append("<!-- OIDC extension default credential definitions -->\n");
 
-        assert pathToOIDCClientJSON.toFile().exists() : "Path to oidc-client.json not found";
+        newText.append("<import resource=\"oidc-credentials.xml\" />\n");
 
-        final Path destPath = pathToIdPHome.resolve(Paths.get("metadata", "oidc-client.json"));
+        newText.append(oldText + "\n");
 
-        Files.copy(pathToOIDCClientJSON, destPath, StandardCopyOption.REPLACE_EXISTING);
+        replaceFile(pathToCredentialsXML, oldText, newText.toString());
     }
 
     /**
@@ -302,6 +240,19 @@ public class AbstractOPTest extends BaseIntegrationTest {
 
         // Replace template endpoint "{{ service_name }}" with OP host and port
         replaceFile(pathToOpenIDConfiguration, "\\{\\{ service_name \\}\\}", hostname + ":" + securePort);
+    }
+
+    /**
+     * Set up rewrite for static/openid-configuration.json.
+     * 
+     * For Jetty, set up dynamic publication using the Jetty 'rewrite'.
+     * 
+     * For Tomcat, set up dynamic publication using the rewrite Valve.
+     * 
+     * @throws IOException
+     *             if an error occurs
+     */
+    protected void enableOIDCDiscoveryRewrite() throws IOException {
 
         // Jetty
         if (pathToJettyBase != null) {
@@ -337,6 +288,120 @@ public class AbstractOPTest extends BaseIntegrationTest {
         }
     }
 
+    /**
+     * Add OIDC.Keyset and OIDC.Configuration to unverified relying party.
+     * 
+     * Add default OIDC profiles to default relying party.
+     * 
+     * @throws IOException
+     *             if an error occurs
+     */
+    protected void enableOIDCProfiles() throws IOException {
+
+        final Path pathToRelyingPartyXML = pathToIdPHome.resolve(Paths.get("conf", "relying-party.xml"));
+
+        assert pathToRelyingPartyXML.toAbsolutePath().toFile().exists() : "Path to relying-party.xml not found";
+
+        // Add <ref bean="OIDC.Keyset" /> to shibboleth.UnverifiedRelyingParty
+        // Add <ref bean="OIDC.Configuration" /> to shibboleth.UnverifiedRelyingParty
+
+        final String unverifiedRPText = "<!-- <bean parent=\"SAML2.SSO\" p:encryptAssertions=\"false\" /> -->";
+
+        final StringBuilder addToUnverified = new StringBuilder();
+        addToUnverified.append("<ref bean=\"OIDC.Keyset\" />\n");
+        addToUnverified.append("<ref bean=\"OIDC.Configuration\" />\n");
+
+        replaceFile(pathToRelyingPartyXML, unverifiedRPText, unverifiedRPText + "\n" + addToUnverified.toString());
+
+        // Add default OIDC profiles to default relying party
+
+        final String defaultRPText = "<ref bean=\"SAML2.ArtifactResolution\" />";
+
+        final StringBuilder addToDefault = new StringBuilder();
+        addToDefault.append("<ref bean=\"OIDC.SSO\" />\n");
+        addToDefault.append("<ref bean=\"OIDC.UserInfo\" />\n");
+        addToDefault.append("<ref bean=\"OAUTH2.Token\" />\n");
+        addToDefault.append("<ref bean=\"OAUTH2.Revocation\" />\n");
+        addToDefault.append("<ref bean=\"OAUTH2.Introspection\" />\n");
+
+        replaceFile(pathToRelyingPartyXML, defaultRPText, defaultRPText + "\n" + addToDefault.toString());
+    }
+
+    /**
+     * Enable client registration.
+     * 
+     * @throws IOException
+     *             if an error occurs
+     */
+    protected void enableStaticClientRegistration() throws IOException {
+
+        final Path pathToOIDCClientInfoResolversXML = pathToIdPHome
+                .resolve(Paths.get("conf", "oidc-clientinfo-resolvers.xml"));
+
+        assert pathToOIDCClientInfoResolversXML.toFile().exists() : "Path to oidc-clientinfo-resolvers.xml not found";
+
+        // Uncomment ExampleFileResolver
+        final String toUncomment = "<bean id=\"ExampleFileResolver\" parent=\"shibboleth.oidc.FilesystemClientInformationResolver\"\\\n"
+                + "        c:metadata=\"%\\{idp.home\\}/metadata/oidc-client.json\" />";
+
+        uncommentFile(pathToOIDCClientInfoResolversXML, toUncomment);
+
+        // Uncomment <ref bean="ExampleFileResolver" />
+        uncommentFile(pathToOIDCClientInfoResolversXML, "<ref bean=\"ExampleFileResolver\" />");
+    }
+
+
+
+    /**
+     * Get /.well-known/openid-configuration and verify that the issuer is correct.
+     */
+    protected void getOpenIDConfigurationFromBrowser() {
+
+        final String openidConfigurationURL = getBaseURL(true) + "/.well-known/openid-configuration";
+
+        log.debug("Attempting to get openid-configuration URL '{}' from browser", openidConfigurationURL);
+
+        driver.get(openidConfigurationURL);
+
+        waitForPageURLContains("/.well-known/openid-configuration");
+
+        final String pageSource = getPageSource();
+
+        // TODO why quoted / ?
+        final String expectedIssuer = "\"issuer\":\"https:\\/\\/idp.tests.shibboleth.net\"";
+
+        Assert.assertTrue(pageSource.contains(expectedIssuer), "Expected issuer not found");
+    }
+
+    /**
+     * Get /.well-known/openid-configuration and verify that the issuer is correct.
+     * 
+     * @throws InterruptedException
+     * @throws IOException
+     * @throws UnsupportedOperationException
+     */
+    protected void getOpenIDConfigurationFromContainer(@Nonnull final RPContainer rp)
+            throws UnsupportedOperationException, IOException, InterruptedException {
+
+        final String openidConfigurationURL = getBaseURL(true) + "/.well-known/openid-configuration";
+
+        log.debug("Attempting to get openid-configuration URL '{}' from container", openidConfigurationURL);
+
+        final ExecResult result = rp.container.execInContainer( //
+                "curl", //
+                "-vvv", //
+                openidConfigurationURL);
+
+        final String response = result.getStdout();
+
+        log.debug("Response openid-configuration from container\n{}\n", response);
+
+        // TODO why quoted / ?
+        final String expectedIssuer = "\"issuer\":\"https:\\/\\/idp.tests.shibboleth.net\"";
+
+        Assert.assertTrue(response.contains(expectedIssuer), "Expected issuer not found");
+    }
+
     /**
      * Use example OIDC attribute resolver and filter.
      * 
@@ -424,6 +489,18 @@ public class AbstractOPTest extends BaseIntegrationTest {
         return rp;
     }
 
+    /**
+     * Stop all RPs.
+     */
+    @AfterMethod()
+    protected void stopRPs() {
+        for (final RPContainer rp : rps) {
+            if (rp != null && rp.isRunning()) {
+                rp.stop();
+            }
+        }
+    }
+
     /**
      * Update client metadata.
      * 
@@ -442,66 +519,4 @@ public class AbstractOPTest extends BaseIntegrationTest {
         replaceFile(pathToOIDCClientJSON, oldData, newData);
     }
 
-    /**
-     * Get /.well-known/openid-configuration and verify that the issuer is correct.
-     */
-    protected void getOpenIDConfigurationFromBrowser() {
-
-        final String openidConfigurationURL = getBaseURL(true) + "/.well-known/openid-configuration";
-
-        log.debug("Attempting to get openid-configuration URL '{}' from browser", openidConfigurationURL);
-
-        driver.get(openidConfigurationURL);
-
-        waitForPageURLContains("/.well-known/openid-configuration");
-
-        final String pageSource = getPageSource();
-
-        // TODO why quoted / ?
-        final String expectedIssuer = "\"issuer\":\"https:\\/\\/idp.tests.shibboleth.net\"";
-
-        Assert.assertTrue(pageSource.contains(expectedIssuer), "Expected issuer not found");
-    }
-
-    /**
-     * Get /.well-known/openid-configuration and verify that the issuer is correct.
-     * 
-     * @throws InterruptedException
-     * @throws IOException
-     * @throws UnsupportedOperationException
-     */
-    protected void getOpenIDConfigurationFromContainer(@Nonnull final RPContainer rp)
-            throws UnsupportedOperationException, IOException, InterruptedException {
-
-        final String openidConfigurationURL = getBaseURL(true) + "/.well-known/openid-configuration";
-
-        log.debug("Attempting to get openid-configuration URL '{}' from container", openidConfigurationURL);
-
-        final ExecResult result = rp.container.execInContainer( //
-                "curl", //
-                "-vvv", //
-                openidConfigurationURL);
-
-        final String response = result.getStdout();
-
-        log.debug("Response openid-configuration from container\n{}\n", response);
-
-        // TODO why quoted / ?
-        final String expectedIssuer = "\"issuer\":\"https:\\/\\/idp.tests.shibboleth.net\"";
-
-        Assert.assertTrue(response.contains(expectedIssuer), "Expected issuer not found");
-    }
-
-    /**
-     * Stop all RPs.
-     */
-    @AfterMethod()
-    protected void stopRPs() {
-        for (final RPContainer rp : rps) {
-            if (rp != null && rp.isRunning()) {
-                rp.stop();
-            }
-        }
-    }
-
 }
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java
index e9ac39b..0b8279c 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/oidc/OPTest.java
@@ -82,6 +82,8 @@ public class OPTest extends AbstractOPTest {
 
         enableOIDCDiscovery();
 
+        enableOIDCDiscoveryRewrite();
+
         setUpIdPAttributes();
 
         setUpOPIssuer();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list