From 73720730f6245b8619d4790018393dc4663f1b50 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Fri, 16 Dec 2022 14:23:12 -0500 Subject: [PATCH] CXF-8809: Migrate LDAP systest cases from ApacheDS to UnboundID LDAP --- parent/pom.xml | 4 +- systests/ldap/pom.xml | 36 ++--------- .../systest/ldap/jaxrs/JAXRSLDAPUserTest.java | 59 ++++++------------- .../cxf/systest/ldap/sts/LDAPClaimsTest.java | 54 +++++------------ .../ldap/xkms/LDAPCertificateRepoTest.java | 55 +++++------------ systests/ldap/src/test/resources/ldap.xml | 2 +- 6 files changed, 56 insertions(+), 154 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index 5e4a282a025..5b9b5a7fbdb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -60,7 +60,6 @@ 2.26.0 2.12.3 - 2.0.0.AM26 1.7.0.Alpha13 3.0.0.Final 1.9.1 @@ -147,6 +146,7 @@ 4.13.2 5.9.1 2.0.2 + 6.0.7 1.1.2 1.4.5 9.4.2 @@ -2171,7 +2171,7 @@ - -ea --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.security.x509=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED --add-opens java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED + -ea --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/sun.net.www.protocol.https=ALL-UNNAMED diff --git a/systests/ldap/pom.xml b/systests/ldap/pom.xml index 593bb6cb61b..2b80a87139f 100644 --- a/systests/ldap/pom.xml +++ b/systests/ldap/pom.xml @@ -197,40 +197,16 @@ test - org.apache.directory.server - apacheds-core-annotations - ${cxf.apacheds.version} + com.unboundid + unboundid-ldapsdk + ${cxf.ldapsdk.version} test - - - bouncycastle - bcprov-jdk15 - - - org.apache.directory.server - apacheds-core-integ - ${cxf.apacheds.version} + org.zapodot + embedded-ldap-junit + 0.9.0 test - - - bouncycastle - bcprov-jdk15 - - - - - org.apache.directory.server - apacheds-protocol-shared - ${cxf.apacheds.version} - test - - - bouncycastle - bcprov-jdk15 - - org.springframework.ldap diff --git a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/jaxrs/JAXRSLDAPUserTest.java b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/jaxrs/JAXRSLDAPUserTest.java index 47ae4294592..5197c914d6b 100644 --- a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/jaxrs/JAXRSLDAPUserTest.java +++ b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/jaxrs/JAXRSLDAPUserTest.java @@ -28,56 +28,33 @@ import jakarta.ws.rs.InternalServerErrorException; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.testutil.common.AbstractClientServerTestBase; -import org.apache.directory.server.annotations.CreateLdapServer; -import org.apache.directory.server.annotations.CreateTransport; -import org.apache.directory.server.core.annotations.ApplyLdifFiles; -import org.apache.directory.server.core.annotations.CreateDS; -import org.apache.directory.server.core.annotations.CreateIndex; -import org.apache.directory.server.core.annotations.CreatePartition; -import org.apache.directory.server.core.integ.AbstractLdapTestUnit; -import org.apache.directory.server.core.integ.FrameworkRunner; +import org.zapodot.junit.ldap.EmbeddedLdapRule; +import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(FrameworkRunner.class) - -//Define the DirectoryService -@CreateDS(name = "JAXRSLDAPUserTest-class", - enableAccessControl = false, - allowAnonAccess = false, - enableChangeLog = true, - partitions = { - @CreatePartition( - name = "example", - suffix = "dc=example,dc=com", - indexes = { - @CreateIndex(attribute = "objectClass"), - @CreateIndex(attribute = "dc"), - @CreateIndex(attribute = "ou") - } - ) - } -) - -@CreateLdapServer( - transports = { - @CreateTransport(protocol = "LDAP", address = "localhost") - } -) - -//Inject an file containing entries -@ApplyLdifFiles("ldap.ldif") /** * Add a test for JAX-RS search using the LdapQueryVisitor. */ -public class JAXRSLDAPUserTest extends AbstractLdapTestUnit { +public class JAXRSLDAPUserTest { public static final String PORT = UserLDAPServer.PORT; public static final String PORT2 = UserLDAPServer.PORT2; + + @ClassRule + public static EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder + .newInstance() + .bindingToAddress("localhost") + .usingBindCredentials("ldap_su") + .usingBindDSN("UID=admin,DC=example,DC=com") + .usingDomainDsn("dc=example,dc=com") + .importingLdifs("ldap.ldif") + .build(); + private static boolean portUpdated; @BeforeClass @@ -103,7 +80,7 @@ public void updatePort() throws Exception { // Read in ldap.xml and substitute in the correct port Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/ldap-jaxrs.xml"); String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); - content = content.replaceAll("portno", Integer.toString(super.getLdapServer().getPort())); + content = content.replaceAll("portno", Integer.toString(embeddedLdapRule.embeddedServerPort())); Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/ldap-jaxrsport.xml"); Files.write(path2, content.getBytes()); @@ -113,7 +90,7 @@ public void updatePort() throws Exception { } - @org.junit.AfterClass + @AfterClass public static void cleanup() throws Exception { AbstractClientServerTestBase.stopAllServers(); } diff --git a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java index 5a96136c5c7..d259a0d700b 100644 --- a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java +++ b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/sts/LDAPClaimsTest.java @@ -45,55 +45,29 @@ import org.apache.cxf.sts.claims.ProcessedClaim; import org.apache.cxf.sts.claims.ProcessedClaimCollection; import org.apache.cxf.ws.security.sts.provider.STSException; -import org.apache.directory.server.annotations.CreateLdapServer; -import org.apache.directory.server.annotations.CreateTransport; -import org.apache.directory.server.core.annotations.ApplyLdifFiles; -import org.apache.directory.server.core.annotations.CreateDS; -import org.apache.directory.server.core.annotations.CreateIndex; -import org.apache.directory.server.core.annotations.CreatePartition; -import org.apache.directory.server.core.integ.AbstractLdapTestUnit; -import org.apache.directory.server.core.integ.FrameworkRunner; import org.apache.wss4j.common.principal.CustomTokenPrincipal; import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.zapodot.junit.ldap.EmbeddedLdapRule; +import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.runner.RunWith; - -@RunWith(FrameworkRunner.class) - -//Define the DirectoryService -@CreateDS(name = "LDAPClaimsTest-class", - enableAccessControl = false, - allowAnonAccess = false, - enableChangeLog = true, - partitions = { - @CreatePartition( - name = "example", - suffix = "dc=example,dc=com", - indexes = { - @CreateIndex(attribute = "objectClass"), - @CreateIndex(attribute = "dc"), - @CreateIndex(attribute = "ou") - } - ) - } -) - -@CreateLdapServer( - transports = { - @CreateTransport(protocol = "LDAP", address = "localhost") - } -) - -//Inject an file containing entries -@ApplyLdifFiles("ldap.ldif") +import org.junit.ClassRule; /** * Test the LdapClaimsHandler that ships with the STS */ -public class LDAPClaimsTest extends AbstractLdapTestUnit { +public class LDAPClaimsTest { + @ClassRule + public static EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder + .newInstance() + .bindingToAddress("localhost") + .usingBindCredentials("ldap_su") + .usingBindDSN("UID=admin,DC=example,DC=com") + .usingDomainDsn("dc=example,dc=com") + .importingLdifs("ldap.ldif") + .build(); private static Properties props; private static boolean portUpdated; @@ -122,7 +96,7 @@ public void updatePort() throws Exception { // Read in ldap.xml and substitute in the correct port Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/ldap.xml"); String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); - content = content.replaceAll("portno", Integer.toString(super.getLdapServer().getPort())); + content = content.replaceAll("portno", Integer.toString(embeddedLdapRule.embeddedServerPort())); Path path2 = FileSystems.getDefault().getPath(basedir, "/target/test-classes/ldapport.xml"); Files.write(path2, content.getBytes()); diff --git a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/xkms/LDAPCertificateRepoTest.java b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/xkms/LDAPCertificateRepoTest.java index b1e8fb711b0..9b0d0d381de 100644 --- a/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/xkms/LDAPCertificateRepoTest.java +++ b/systests/ldap/src/test/java/org/apache/cxf/systest/ldap/xkms/LDAPCertificateRepoTest.java @@ -34,54 +34,29 @@ import org.apache.cxf.xkms.x509.repo.ldap.LdapCertificateRepo; import org.apache.cxf.xkms.x509.repo.ldap.LdapSchemaConfig; import org.apache.cxf.xkms.x509.repo.ldap.LdapSearch; -import org.apache.directory.server.annotations.CreateLdapServer; -import org.apache.directory.server.annotations.CreateTransport; -import org.apache.directory.server.core.annotations.ApplyLdifFiles; -import org.apache.directory.server.core.annotations.CreateDS; -import org.apache.directory.server.core.annotations.CreateIndex; -import org.apache.directory.server.core.annotations.CreatePartition; -import org.apache.directory.server.core.integ.AbstractLdapTestUnit; -import org.apache.directory.server.core.integ.FrameworkRunner; +import org.zapodot.junit.ldap.EmbeddedLdapRule; +import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder; +import org.junit.ClassRule; import org.junit.Test; -import org.junit.runner.RunWith; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -@RunWith(FrameworkRunner.class) - -//Define the DirectoryService -@CreateDS(name = "LDAPCertificateRepoTest-class", - enableAccessControl = false, - allowAnonAccess = false, - enableChangeLog = true, - partitions = { - @CreatePartition( - name = "example", - suffix = "dc=example,dc=com", - indexes = { - @CreateIndex(attribute = "objectClass"), - @CreateIndex(attribute = "dc"), - @CreateIndex(attribute = "ou") - } - ) - } -) - -@CreateLdapServer( - transports = { - @CreateTransport(protocol = "LDAP", address = "localhost") - } -) - -//Inject an file containing entries -@ApplyLdifFiles("ldap.ldif") - /** * Add a test for the XKMS LDAP CertificateRepo */ -public class LDAPCertificateRepoTest extends AbstractLdapTestUnit { +public class LDAPCertificateRepoTest { + @ClassRule + public static EmbeddedLdapRule embeddedLdapRule = EmbeddedLdapRuleBuilder + .newInstance() + .bindingToAddress("localhost") + .usingBindCredentials("ldap_su") + .usingBindDSN("UID=admin,DC=example,DC=com") + .usingDomainDsn("dc=example,dc=com") + .importingLdifs("ldap.ldif") + .build(); + private static final String EXPECTED_SUBJECT_DN = "cn=dave,ou=users"; private static final String ROOT_DN = "dc=example,dc=com"; private static final String EXPECTED_SUBJECT_DN2 = "cn=newuser,ou=users"; @@ -160,7 +135,7 @@ public void testSaveServiceCert() throws Exception { } private CertificateRepo createLdapCertificateRepo() throws CertificateException { - LdapSearch ldapSearch = new LdapSearch("ldap://localhost:" + super.getLdapServer().getPort(), + LdapSearch ldapSearch = new LdapSearch("ldap://localhost:" + embeddedLdapRule.embeddedServerPort(), "UID=admin,DC=example,DC=com", "ldap_su", 2); LdapSchemaConfig ldapSchemaConfig = new LdapSchemaConfig(); diff --git a/systests/ldap/src/test/resources/ldap.xml b/systests/ldap/src/test/resources/ldap.xml index 4703f8ccd00..a3ba45a2e3f 100644 --- a/systests/ldap/src/test/resources/ldap.xml +++ b/systests/ldap/src/test/resources/ldap.xml @@ -36,7 +36,7 @@ - +