[java-idp-integration-tests] 03/04: Optionally update DNS records

Tom Zeller tzeller at dragonacea.biz
Wed Jan 31 22:32:01 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=e36c861149aedcc2aa07694ceff3050a1866a134

commit e36c861149aedcc2aa07694ceff3050a1866a134
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Wed Jan 31 16:08:20 2024 -0600

    Optionally update DNS records
    
    Set up and tear down DNS records before and after TestNG suite
    
    Use hostname-based URLs for Safari
    
    https://shibboleth.atlassian.net/browse/IDP-2228
---
 .../idp/integration/tests/BaseIntegrationTest.java | 91 +++++++++++++++++++---
 .../saml1/SAML1UnsolicitedSSOIntegrationTest.java  |  4 -
 .../saml2/SAML2UnsolicitedSSOIntegrationTest.java  |  4 -
 3 files changed, 82 insertions(+), 17 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 4b1ab7d..cb35888 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -96,8 +96,10 @@ import org.testng.Assert;
 import org.testng.ITestResult;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeSuite;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Listeners;
 
@@ -414,6 +416,9 @@ public abstract class BaseIntegrationTest {
     /** Reload service CLI, either reload-service.sh or reload-service.bat. **/
     @NonnullAfterInit protected String reloadServiceCLI;
 
+    /** Route 53 helper to create and delete DNS records. */
+    @Nullable private Route53Helper route53;
+
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(BaseIntegrationTest.class);
 
@@ -805,19 +810,43 @@ public abstract class BaseIntegrationTest {
 
     /**
      * Set up endpoint URLs using the {@link #address} and {@link #secureAddress}.
+     * 
+     * Use DNS name from Route 53 if 'DNS' system property is true.
      */
     @BeforeClass(dependsOnMethods = {"setUpAddresses", "setUpAvailablePorts"})
     public void setUpBaseURLs() {
+        
+        // Set up Route 53 helper if necessary
+        if (route53 == null) {
+            route53 = new Route53Helper();
+            try {
+                route53.initialize();
+            } catch (ComponentInitializationException e) {
+                log.error("Unable to initialize Route 53 helper");
+                throw new RuntimeException(e);
+            }
+        }
+        
+        // Non secure URL
         final URLBuilder urlBuilder = new URLBuilder();
         urlBuilder.setScheme("http");
-        urlBuilder.setHost(address);
+        if (Boolean.getBoolean("DNS")) {
+            urlBuilder.setHost(route53.name);
+        } else {
+            urlBuilder.setHost(address);
+        }
         urlBuilder.setPort(port);
         baseURL = urlBuilder.buildURL();
         log.debug("URL '{}' is the base URL which clients should connect to.", baseURL);
 
+        // Secure URL
         final URLBuilder secureUrlBuilder = new URLBuilder();
         secureUrlBuilder.setScheme("https");
-        secureUrlBuilder.setHost(secureAddress);
+        if (Boolean.getBoolean("DNS")) {
+            secureUrlBuilder.setHost(route53.name);
+        } else {
+            secureUrlBuilder.setHost(secureAddress);
+        }
         secureUrlBuilder.setPort(securePort);
         secureBaseURL = secureUrlBuilder.buildURL();
         log.debug("URL '{}' is the secure base URL which clients should connect to.", secureBaseURL);
@@ -1426,6 +1455,19 @@ public abstract class BaseIntegrationTest {
         addresses.add(secureAddress);
         addresses.add(privateAddress);
         addresses.add(privateSecureAddress);
+        if (Boolean.getBoolean("DNS")) {
+            // Set up Route 53 helper if necessary
+            if (route53 == null) {
+                route53 = new Route53Helper();
+                try {
+                    route53.initialize();
+                } catch (ComponentInitializationException e) {
+                    log.error("Unable to initialize Route 53 helper");
+                    throw new RuntimeException(e);
+                }
+            }
+            addresses.add(route53.name);
+        }
         for (final String addr : addresses) {
             if (addr == "localhost") {
                 continue;
@@ -1657,13 +1699,7 @@ public abstract class BaseIntegrationTest {
         if (browserData != null && (browserData.getBrowser().equalsIgnoreCase("safari")
                 || browserData.getBrowser().equalsIgnoreCase("ipad")
                 || browserData.getBrowser().equalsIgnoreCase("iphone"))) {
-            log.warn("Safari does not support accepting insecure certs");
-            try {
-                setUpNonSecurePort();
-            } catch (IOException e) {
-                log.error("Unable to set up non-secure port {}", e);
-                throw new RuntimeException(e);
-            }
+            log.debug("Safari does not support accepting insecure certs");
         } else {
             desiredCapabilities.setAcceptInsecureCerts(true);
         }
@@ -2741,4 +2777,41 @@ public abstract class BaseIntegrationTest {
         logProcess(process, "reload-service :");
     }
 
+    @BeforeSuite
+    /**
+     * Set up DNS record if system property 'DNS' is true.
+     * 
+     * @throws ComponentInitializationException
+     *             if Route 53 helper is unable to be initialized
+     */
+    public void setUpDNS() throws ComponentInitializationException {
+        if (!Boolean.getBoolean("DNS")) {
+            return;
+        }
+        log.debug("Setting up DNS");
+        if (route53 == null) {
+            route53 = new Route53Helper();
+            route53.initialize();
+        }
+        route53.create();
+        log.debug("Finished setting up DNS");
+    }
+
+    @AfterSuite
+    /**
+     * Tear down DNS record if system property 'DNS' is true.
+     * 
+     * @throws ComponentInitializationException
+     *             if Route 53 helper is unable to be initialized
+     */
+    public void tearDownDNS() {
+        if (!Boolean.getBoolean("DNS")) {
+            return;
+        }
+        log.debug("Tearing down DNS");
+        Assert.assertNotNull(route53, "Route 53 helper should not be null");
+        route53.delete();
+        log.debug("Finished tearing down DNS");
+    }
+
 }
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/saml1/SAML1UnsolicitedSSOIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/saml1/SAML1UnsolicitedSSOIntegrationTest.java
index 2a5d982..d9dea27 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/saml1/SAML1UnsolicitedSSOIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/saml1/SAML1UnsolicitedSSOIntegrationTest.java
@@ -50,10 +50,6 @@ public class SAML1UnsolicitedSSOIntegrationTest extends AbstractSAML1Integration
      */
     public void setUpURLs(@Nullable final BrowserData browserData) {
 
-        if (isSafari(browserData)) {
-            useSecureBaseURL = false;
-        }
-
         final String shire = getBaseURL() + shirePath;
 
         startFlowURLPath = idpEndpointPath + "?providerId=" + providerID + "&shire=" + shire + "&target=" + target;
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/saml2/SAML2UnsolicitedSSOIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/saml2/SAML2UnsolicitedSSOIntegrationTest.java
index 156266e..e950551 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/saml2/SAML2UnsolicitedSSOIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/saml2/SAML2UnsolicitedSSOIntegrationTest.java
@@ -48,10 +48,6 @@ public class SAML2UnsolicitedSSOIntegrationTest extends AbstractSAML2Integration
      */
     public void setUpURLs(@Nullable final BrowserData browserData) throws Exception {
 
-        if (isSafari(browserData)) {
-            useSecureBaseURL = false;
-        }
-
         final String shire = getBaseURL() + shirePath;
 
         startFlowURLPath = idpEndpointPath + "?providerId=" + providerID + "&shire=" + shire + "&target=" + target;

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


More information about the commits mailing list