Skip to content

Commit

Permalink
use docker container for perform tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelGaro committed Jan 23, 2024
1 parent f96b488 commit 5b2b12e
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 328 deletions.
190 changes: 47 additions & 143 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@
<properties>
<connid.version>1.5.2.0</connid.version>

<opendj.version>2.6.2</opendj.version>
<opendj.setup.dir>${project.build.directory}/opendj-setup</opendj.setup.dir>
<opendj.backup.dir>${project.build.directory}/opendj-backup</opendj.backup.dir>
<opendj.version>4.6.2</opendj.version>
<opendj.host>localhost</opendj.host>
<opendj.port>2389</opendj.port>
<opendj.sslport>2636</opendj.sslport>
<opendj.port>1389</opendj.port>
<opendj.sslport>1636</opendj.sslport>
<opendj.principal>cn=Directory Manager</opendj.principal>
<opendj.credentials>password</opendj.credentials>
<opendj.baseDN>dc=example,dc=com</opendj.baseDN>
Expand Down Expand Up @@ -212,147 +210,53 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<inherited>true</inherited>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.43.4</version>
<configuration>
<images>
<image>
<alias>ldap</alias>
<name>openidentityplatform/opendj:${opendj.version}</name>
<build>
<contextDir>${project.basedir}/src/test/resources/opendj</contextDir>
</build>
<run>
<ports>
<port>1389:1389</port>
<port>1636:1636</port>
</ports>
<wait>
<log>OpenDJ is started</log>
<time>200000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>prepareOpenDJ</id>
<phase>process-test-classes</phase>
<configuration>
<target>
<mkdir dir="${settings.localRepository}/openrock/opendj" />
<get src="https://github.com/OpenRock/OpenDJ/releases/download/${opendj.version}/opendj-server-${opendj.version}.zip" dest="${settings.localRepository}/openrock/opendj" skipexisting="true" />
<delete dir="${opendj.setup.dir}" />
<unzip dest="${project.build.directory}" src="${settings.localRepository}/openrock/opendj/opendj-server-${opendj.version}.zip" />
<move file="${project.build.directory}/opendj" tofile="${opendj.setup.dir}" />

<condition property="tool.setup" value="setup.bat" else="setup">
<os family="windows" />
</condition>
<condition property="tool.backup" value="bat/backup.bat" else="bin/backup">
<os family="windows" />
</condition>
<condition property="tool.restore" value="bat/restore.bat" else="bin/restore">
<os family="windows" />
</condition>
<condition property="tool.import-ldif" value="bat/import-ldif.bat" else="bin/import-ldif">
<os family="windows" />
</condition>
<condition property="tool.ldapmodify" value="bat/ldapmodify.bat" else="bin/ldapmodify">
<os family="windows" />
</condition>
<condition property="tool.make-ldif" value="bat/make-ldif.bat" else="bin/make-ldif">
<os family="windows" />
</condition>
<condition property="tool.rebuild-index" value="bat/rebuild-index.bat" else="bin/rebuild-index">
<os family="windows" />
</condition>
<condition property="tool.start-ds" value="bat/start-ds.bat" else="bin/start-ds">
<os family="windows" />
</condition>
<condition property="tool.stop-ds" value="bat/stop-ds.bat" else="bin/stop-ds">
<os family="windows" />
</condition>
<chmod perm="+x">
<fileset dir="${opendj.setup.dir}">
<include name="${tool.setup}" />
<include name="${tool.backup}" />
<include name="${tool.restore}" />
<include name="${tool.import-ldif}" />
<include name="${tool.ldapmodify}" />
<include name="${tool.make-ldif}" />
<include name="${tool.rebuild-index}" />
<include name="${tool.start-ds}" />
<include name="${tool.stop-ds}" />
<include name="lib/_script-util.sh" />
<include name="lib/_client-script.sh" />
<include name="lib/_mixed-script.sh" />
<include name="lib/_server-script.sh" />
</fileset>
</chmod>

<concat destfile="${opendj.setup.dir}/template/config/config.ldif" append="true">
<filelist dir="${project.build.directory}/test-classes/opendj" files="config-additions.ldif" />
</concat>

<exec executable="${opendj.setup.dir}/${tool.setup}" dir="${opendj.setup.dir}">
<arg value="--cli" />
<arg value="-n" />
<arg value="-O" />
<arg value="--baseDN" />
<arg value="dc=example,dc=com" />
<arg value="-D" />
<arg value="${opendj.principal}" />
<arg value="-w" />
<arg value="${opendj.credentials}" />
<arg value="--generateSelfSignedCertificate" />
<arg value="-h" />
<arg value="${opendj.host}" />
<arg value="-p" />
<arg value="${opendj.port}" />
<arg value="-Z" />
<arg value="${opendj.sslport}" />
<arg value="--adminConnectorPort" />
<arg value="4444" />
<arg value="--acceptLicense" />
</exec>

<!-- Generate and import data. -->
<exec executable="${opendj.setup.dir}/${tool.make-ldif}" dir="${opendj.setup.dir}">
<arg value="-t" />
<arg value="${project.build.directory}/test-classes/opendj/bigcompany.template" />
<arg value="-o" />
<arg value="${opendj.setup.dir}/bigcompany.ldif" />
</exec>
<exec executable="${opendj.setup.dir}/${tool.import-ldif}" dir="${opendj.setup.dir}">
<arg value="--clearBackend" />
<arg value="--ldifFile" />
<arg value="${project.build.directory}/test-classes/opendj/data.ldif" />
<arg value="--backendID" />
<arg value="userRoot" />
</exec>
<exec executable="${opendj.setup.dir}/${tool.import-ldif}" dir="${opendj.setup.dir}">
<arg value="--append" />
<arg value="--ldifFile" />
<arg value="${opendj.setup.dir}/bigcompany.ldif" />
<arg value="--backendID" />
<arg value="userRoot" />
</exec>
<exec executable="${opendj.setup.dir}/${tool.rebuild-index}" dir="${opendj.setup.dir}">
<arg value="--baseDN" />
<arg value="dc=example,dc=com" />
<arg value="--index" />
<arg value="vlv.index-uid" />
</exec>

<!-- Set up an admin user. -->
<exec executable="${opendj.setup.dir}/${tool.start-ds}" dir="${opendj.setup.dir}" />
<exec executable="${opendj.setup.dir}/${tool.ldapmodify}" dir="${opendj.setup.dir}">
<arg value="-h" />
<arg value="${opendj.host}" />
<arg value="-p" />
<arg value="${opendj.port}" />
<arg value="-D" />
<arg value="${opendj.principal}" />
<arg value="-w" />
<arg value="${opendj.credentials}" />
<arg value="-f" />
<arg value="${project.build.directory}/test-classes/opendj/admin.ldif" />
</exec>
<exec executable="${opendj.setup.dir}/${tool.stop-ds}" dir="${opendj.setup.dir}" />

<!-- Backup right after OpenDJ setup, for usage with LdapConnectorTestBase -->
<exec executable="${opendj.setup.dir}/${tool.backup}" dir="${opendj.setup.dir}">
<arg value="-a" />
<arg value="-d" />
<arg value="${opendj.backup.dir}" />
</exec>
</target>
<skip>${skipTests}</skip>
</configuration>
<id>build-docker</id>
<phase>initialize</phase>
<goals>
<goal>stop</goal>
<goal>remove</goal>
</goals>
</execution>
<execution>
<id>start-docker</id>
<phase>generate-test-resources</phase>
<goals>
<goal>build</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>remove-containers-post-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>run</goal>
<goal>stop</goal>
<goal>remove</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -61,10 +62,6 @@
public class AdapterCompatibilityTests extends LdapConnectorTestBase {

// TODO test authenticate.
@Override
protected boolean restartServerAfterEachTest() {
return true;
}

@Test
public void accountOperationalAttributes() {
Expand Down Expand Up @@ -144,6 +141,7 @@ public void createGroupOfUniqueNamesWithoutMembers() {

ConnectorObject newGroup = facade.getObject(oclass, uid, null);
assertEquals(name, newGroup.getName());
facade.delete(oclass, uid, null);
}

@Test
Expand Down Expand Up @@ -218,6 +216,7 @@ private void doTestCreateWithGroups(ConnectorFacade facade, Attribute groupsAttr
Uid uid = facade.create(ObjectClass.ACCOUNT, attributes, null);

assertAttributeValue(groupsAttr.getValue(), facade, ObjectClass.ACCOUNT, uid, groupsAttr.getName());
facade.delete(ObjectClass.ACCOUNT, uid, null);
}

@Test
Expand Down Expand Up @@ -247,6 +246,7 @@ private void doTestAddGroups(final ConnectorFacade facade, final Attribute group

oldGroups.addAll(groupsAttr.getValue());
assertAttributeValue(oldGroups, facade, ObjectClass.ACCOUNT, uid, groupsAttr.getName());
facade.removeAttributeValues(ObjectClass.ACCOUNT, uid, Collections.singleton(groupsAttr), null);
}

@Test
Expand All @@ -268,10 +268,12 @@ public void updatePosixGroups() {
private void doTestUpdateGroups(ConnectorFacade facade, Attribute groupsAttr) {
ConnectorObject object = searchByAttribute(
facade, ObjectClass.ACCOUNT, new Name(SYLVESTER_DN), groupsAttr.getName());
Attribute oldLGroups = object.getAttributeByName(LdapConstants.LDAP_GROUPS_NAME);

Uid uid = facade.update(ObjectClass.ACCOUNT, object.getUid(), Collections.singleton(groupsAttr), null);

assertAttributeValue(groupsAttr.getValue(), facade, ObjectClass.ACCOUNT, uid, groupsAttr.getName());
facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(oldLGroups), null);
}

@Test
Expand Down Expand Up @@ -300,6 +302,7 @@ private void doTestRemoveGroups(ConnectorFacade facade, Attribute groupsAttr) {

oldGroups.removeAll(groupsAttr.getValue());
assertAttributeValue(oldGroups, facade, ObjectClass.ACCOUNT, uid, groupsAttr.getName());
facade.addAttributeValues(ObjectClass.ACCOUNT, uid, Collections.singleton(groupsAttr), null);
}

@Test
Expand Down Expand Up @@ -341,6 +344,7 @@ public void renameMaintainsGroupMemberships() {
List<String> oldPosixGroups = LdapUtil.checkedListByFilter(
object.getAttributeByName(LdapConstants.POSIX_GROUPS_NAME).getValue(), String.class);

Name oldName = object.getName();
Name newName = new Name("uid=sylvester.the.cat," + ACME_USERS_DN);
Uid uid = facade.update(ObjectClass.ACCOUNT, object.getUid(),
Collections.singleton((Attribute) newName), null);
Expand All @@ -363,6 +367,7 @@ public void renameMaintainsGroupMemberships() {
List<Object> members = object.getAttributeByName("memberUid").getValue();
assertFalse(members.contains(SYLVESTER_UID));
}
facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(oldName), null);
}

@Test
Expand All @@ -374,11 +379,12 @@ public void renameAndUpdateGroupMemberships() {

ConnectorObject object = searchByAttribute(facade, ObjectClass.ACCOUNT, new Name(SYLVESTER_DN),
LdapConstants.LDAP_GROUPS_NAME, LdapConstants.POSIX_GROUPS_NAME);
List<String> oldLdapGroups = LdapUtil.checkedListByFilter(
object.getAttributeByName(LdapConstants.LDAP_GROUPS_NAME).getValue(), String.class);
List<String> oldPosixGroups = LdapUtil.checkedListByFilter(
object.getAttributeByName(LdapConstants.POSIX_GROUPS_NAME).getValue(), String.class);
Attribute oldLGroups = object.getAttributeByName(LdapConstants.LDAP_GROUPS_NAME);
List<String> oldLdapGroups = LdapUtil.checkedListByFilter(oldLGroups.getValue(), String.class);
Attribute oldPGroup = object.getAttributeByName(LdapConstants.POSIX_GROUPS_NAME);
List<String> oldPosixGroups = LdapUtil.checkedListByFilter(oldPGroup.getValue(), String.class);

Name oldName = object.getName();
Name newName = new Name("uid=sylvester.the.cat," + ACME_USERS_DN);
Attribute ldapGroupsAttr = AttributeBuilder.build(
LdapConstants.LDAP_GROUPS_NAME,
Expand All @@ -405,6 +411,7 @@ public void renameAndUpdateGroupMemberships() {
List<Object> members = object.getAttributeByName("memberUid").getValue();
assertFalse(members.contains(SYLVESTER_UID));
}
facade.update(ObjectClass.ACCOUNT, uid, CollectionUtil.newSet(oldName, oldLGroups, oldPGroup), null);
}

@Test
Expand All @@ -414,11 +421,13 @@ public void renameDoesNotMaintainGroupMembershipsUnlessConfigured() {
assertFalse(config.isMaintainPosixGroupMembership());
ConnectorFacade facade = newFacade(config);

ConnectorObject object = searchByAttribute(facade, ObjectClass.ACCOUNT, new Name(SYLVESTER_DN));
Name oldName = new Name(SYLVESTER_DN);
ConnectorObject object = searchByAttribute(facade, ObjectClass.ACCOUNT, oldName);
String newUid = "sylvester.the.cat";
String newEntryDN = "uid=" + newUid + "," + ACME_USERS_DN;
Uid uid = object.getUid();
facade.update(
ObjectClass.ACCOUNT, object.getUid(),
ObjectClass.ACCOUNT, uid,
Collections.singleton((Attribute) new Name(newEntryDN)), null);

object = searchByAttribute(
Expand All @@ -444,6 +453,7 @@ public void renameDoesNotMaintainGroupMembershipsUnlessConfigured() {
members = object.getAttributeByName("memberUid").getValue();
assertTrue(members.contains(SYLVESTER_UID));
assertFalse(members.contains(newUid));
facade.update(ObjectClass.ACCOUNT, uid, Collections.singleton(oldName), null);
}

@Test
Expand All @@ -455,11 +465,12 @@ public void deleteMaintainsGroupMemberships() {

ConnectorObject object = searchByAttribute(facade, ObjectClass.ACCOUNT, new Name(SYLVESTER_DN),
LdapConstants.LDAP_GROUPS_NAME, LdapConstants.POSIX_GROUPS_NAME);
List<String> oldLdapGroups = LdapUtil.checkedListByFilter(
object.getAttributeByName(LdapConstants.LDAP_GROUPS_NAME).getValue(), String.class);
List<String> oldPosixGroups = LdapUtil.checkedListByFilter(
object.getAttributeByName(LdapConstants.POSIX_GROUPS_NAME).getValue(), String.class);
Attribute oldLGroups = object.getAttributeByName(LdapConstants.LDAP_GROUPS_NAME);
List<String> oldLdapGroups = LdapUtil.checkedListByFilter(oldLGroups.getValue(), String.class);
Attribute oldPGroup = object.getAttributeByName(LdapConstants.POSIX_GROUPS_NAME);
List<String> oldPosixGroups = LdapUtil.checkedListByFilter(oldPGroup.getValue(), String.class);

Name oldName = object.getName();
facade.delete(ObjectClass.ACCOUNT, object.getUid(), null);

// Need to test that the old entries were actually removed from the old groups.
Expand All @@ -473,6 +484,7 @@ public void deleteMaintainsGroupMemberships() {
List<Object> members = object.getAttributeByName("memberUid").getValue();
assertFalse(members.contains(SYLVESTER_UID));
}
restoreSylvester(facade, oldName, oldLGroups, oldPGroup);
}

@Test
Expand All @@ -483,6 +495,7 @@ public void deleteDoesNotMaintainGroupMembershipsUnlessConfigured() {
ConnectorFacade facade = newFacade(config);

ConnectorObject object = searchByAttribute(facade, ObjectClass.ACCOUNT, new Name(SYLVESTER_DN));
Name oldName = object.getName();
facade.delete(ObjectClass.ACCOUNT, object.getUid(), null);

object = searchByAttribute(
Expand All @@ -504,6 +517,17 @@ public void deleteDoesNotMaintainGroupMembershipsUnlessConfigured() {
facade, new ObjectClass("posixGroup"), new Name(POSIX_EXTERNAL_PEERS_DN), "memberUid");
members = object.getAttributeByName("memberUid").getValue();
assertTrue(members.contains(SYLVESTER_UID));
restoreSylvester(facade, oldName);
}

private void restoreSylvester(final ConnectorFacade facade, final Name name, final Attribute... groups) {
Set<Attribute> attributes = new HashSet<>();
attributes.add(name);
attributes.add(AttributeBuilder.build("uid", "sylvester"));
attributes.add(AttributeBuilder.build("cn", "sylvester"));
attributes.add(AttributeBuilder.build("sn", "sylvester"));
attributes.addAll(Arrays.asList(groups));
facade.create(ObjectClass.ACCOUNT, attributes, null);
}

@Test
Expand Down Expand Up @@ -554,6 +578,7 @@ private void doTestPasswordHashing(final ConnectorFacade facade, final String al
passwordBytes = (byte[]) object.getAttributeByName("userPassword").getValue().get(0);
assertTrue(new String(passwordBytes, StandardCharsets.UTF_8).startsWith(algorithmLabel));
facade.authenticate(ObjectClass.ACCOUNT, "daffy.duck", password, null);
facade.delete(ObjectClass.ACCOUNT, uid, null);
}

@Test
Expand Down
Loading

0 comments on commit 5b2b12e

Please sign in to comment.