[java-idp-integration-tests COMMIT] /trunk/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java

noreply at shibboleth.net noreply at shibboleth.net
Mon Nov 17 21:31:53 EST 2014


Author: tzeller
Date: Mon Nov 17 21:31:53 2014
New Revision: 34

URL: http://svn.shibboleth.net/view/java-idp-integration-tests?rev=34&view=rev
Log:
Disable STARTTLS in ldap.properties for integration tests via property replacement.

Modified:
    trunk/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java

Modified: trunk/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java
URL: http://svn.shibboleth.net/view/java-idp-integration-tests/trunk/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java?rev=34&r1=33&r2=34&view=diff
==============================================================================
--- trunk/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java (original)
+++ trunk/src/test/java/net/shibboleth/idp/test/BaseIntegrationTest.java Mon Nov 17 21:31:53 2014
@@ -73,6 +73,9 @@
     /** Path to conf/idp.properties. */
     @NonnullAfterInit protected Path pathToIdPProperties;
 
+    /** Path to conf/ldap.properties. */
+    @NonnullAfterInit protected Path pathToLDAPProperties;
+
     /** Path to jetty.base. */
     @NonnullAfterInit protected Path pathToJettyBase;
 
@@ -147,6 +150,10 @@
         // Path to conf/idp.properties
         pathToIdPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "idp.properties");
         Assert.assertTrue(pathToIdPProperties.toFile().exists(), "Path to conf/idp.properties not found");
+        
+        // Path to conf/ldap.properties
+        pathToLDAPProperties = Paths.get(pathToIdPHome.toAbsolutePath().toString(), "conf", "ldap.properties");
+        Assert.assertTrue(pathToLDAPProperties.toFile().exists(), "Path to conf/ldap.properties not found");
     }
 
     /**
@@ -165,6 +172,28 @@
         if (idpXMLSecurityManager != null) {
             System.setProperty(IDP_XML_SECURITY_MANAGER_PROP_NAME, idpXMLSecurityManager);
         }
+    }
+
+    /**
+     * Do not use STARTTLS for LDAP connection to test in-memory directory server.
+     *
+     * @throws Exception
+     */
+    @BeforeClass(dependsOnMethods = {"setupPaths"}) public void disableLDAPSTARTTLS() throws Exception {
+        replaceLDAPProperty("idp.authn.LDAP.useStartTLS", "false");
+    }
+
+    /**
+     * Restore conf/ldap.properties from dist/conf/ldap.properties.dist.
+     * 
+     * @throws IOException if an I/O error occurs
+     */
+    @AfterClass(alwaysRun = true) public void restoreLDAPProperties() throws IOException {
+        final Path pathToLDAPPropertiesDist =
+                Paths.get(pathToIdPHome.toAbsolutePath().toString(), "dist", "conf", "ldap.properties.dist");
+        Assert.assertTrue(pathToLDAPPropertiesDist.toFile().exists());
+
+        Files.copy(pathToLDAPPropertiesDist, pathToLDAPProperties, StandardCopyOption.REPLACE_EXISTING);
     }
 
     /**
@@ -196,18 +225,44 @@
      */
     public void replaceIdPProperty(@Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value)
             throws IOException {
+        replaceProperty(pathToIdPProperties, key, value);
+    }
+    
+    /**
+     * Replace a property in conf/ldap.properties.
+     * 
+     * @param key property key
+     * @param value property value
+     * @throws IOException if an I/O error occurs
+     */
+    public void replaceLDAPProperty(@Nonnull @NotEmpty final String key, @Nonnull @NotEmpty final String value)
+            throws IOException {
+        replaceProperty(pathToLDAPProperties, key, value);
+    }
+    
+    /**
+     * Replace a property in a properties file.
+     * 
+     * @param pathToPropertyFile path to the property file
+     * @param key property key
+     * @param value property value 
+     * @throws IOException if an I/O error occurs
+     */
+    public void replaceProperty(@Nonnull final Path pathToPropertyFile, @Nonnull @NotEmpty final String key,
+            @Nonnull @NotEmpty final String value) throws IOException {
+        Constraint.isNotNull(pathToPropertyFile, "Path to property file cannot be null nor empty");
         Constraint.isNotNull(StringSupport.trimOrNull(key), "Replacement property key cannot be null nor empty");
         Constraint.isNotNull(StringSupport.trimOrNull(value), "Replacement property value cannot be null nor empty");
 
-        log.debug("Replacing idp property '{}' with '{}'", key, value);
-
-        final FileSystemResource idpPropertiesResource =
-                new FileSystemResource(pathToIdPProperties.toAbsolutePath().toString());
+        log.debug("Replacing property '{}' with '{}' in file '{}'", key, value, pathToPropertyFile);
+
+        final FileSystemResource propertyResource =
+                new FileSystemResource(pathToPropertyFile.toAbsolutePath().toString());
 
         final PropertiesWithComments pwc = new PropertiesWithComments();
-        pwc.load(idpPropertiesResource.getInputStream());
+        pwc.load(propertyResource.getInputStream());
         pwc.replaceProperty(key, value);
-        pwc.store(idpPropertiesResource.getOutputStream());
+        pwc.store(propertyResource.getOutputStream());
     }
 
     /**



More information about the commits mailing list