Skip to content

Commit

Permalink
Partial migration to Apache DS 2
Browse files Browse the repository at this point in the history
To make this work requires migration to the LDAP Client API v2 which is probably out of scope.
  • Loading branch information
chadlwilson committed Oct 27, 2023
1 parent 0daf0b2 commit 1251490
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 34 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ dependencies {
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine'
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher'

integrationTestImplementation group: 'com.github.stefanbirkner', name: 'system-rules', version: '1.19.0'
integrationTestImplementation 'uk.org.webcompere:system-stubs-jupiter:2.1.3'
integrationTestImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.5'
integrationTestImplementation project.deps.apacheDs
integrationTestImplementation group: 'org.apache.directory.server', name: 'apacheds-core-annotations', version: project.versions.apacheDs
integrationTestImplementation group: 'org.apache.directory.server', name: 'apacheds-core-integ', version: '2.0.0-M24'
integrationTestImplementation group: 'org.apache.directory.server', name: 'apacheds-core-integ', version: project.versions.apacheDs
integrationTestImplementation group: 'org.apache.directory.server', name: 'apacheds-core-jndi', version: project.versions.apacheDs
integrationTestImplementation group: 'org.apache.directory.server', name: 'apacheds-core-constants', version: project.versions.apacheDs
integrationTestRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine'
integrationTestRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine'
integrationTestRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher'
}

test {
Expand Down
27 changes: 22 additions & 5 deletions src/integration/cd/go/apacheds/LdapIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,38 @@
import cd.go.authentication.ldap.model.LdapConfiguration;
import cd.go.authentication.ldap.model.User;
import org.apache.directory.ldap.client.template.exception.LdapRuntimeException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ProvideSystemProperty;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.properties.SystemProperties;

import java.util.List;

import static cd.go.authentication.ldap.PluginSystemProperty.USE_JNDI_LDAP_CLIENT;
import static java.text.MessageFormat.format;
import static org.assertj.core.api.Assertions.*;

@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
@ExtendWith(SystemStubsExtension.class)
public class LdapIntegrationTest extends BaseIntegrationTest {
@Rule
public final ProvideSystemProperty systemProperty = new ProvideSystemProperty(USE_JNDI_LDAP_CLIENT, "false");

@SystemStub
private SystemProperties systemProperties;
private ApacheDsLdapClient ldap;

@BeforeEach
public void setUp() {
systemProperties.set(USE_JNDI_LDAP_CLIENT, "true");
}

@Test
public void authenticate_shouldAuthenticateUser() {
LdapConfiguration ldapConfiguration = ldapConfiguration(new String[]{"ou=system"});
Expand Down
15 changes: 4 additions & 11 deletions src/integration/cd/go/authentication/ldap/BaseIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@

import cd.go.authentication.ldap.model.LdapConfiguration;
import com.google.gson.Gson;
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.integ.AbstractLdapTestUnit;
import org.apache.directory.server.core.integ.FrameworkRunner;
import org.junit.runner.RunWith;
import org.apache.directory.server.core.integ.ApacheDSTestExtension;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.HashMap;
import java.util.Map;

@RunWith(FrameworkRunner.class)
@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
@ExtendWith(ApacheDSTestExtension.class)
public abstract class BaseIntegrationTest extends AbstractLdapTestUnit {
protected LdapConfiguration ldapConfiguration(String[] searchBases) {
Map<String, String> configuration = configAsMap("uid=admin,ou=system", "secret", "(uid={0})", searchBases
Expand All @@ -59,7 +52,7 @@ protected LdapConfiguration ldapConfiguration(String username, String password,

private Map<String, String> configAsMap(String managerDN, String password, String userLoginFilter, String[] searchBases) {
Map<String, String> configuration = new HashMap<>();
configuration.put("Url", String.format("ldap://localhost:%s", ldapServer.getPort()));
configuration.put("Url", String.format("ldap://localhost:%s", classLdapServer.getPort()));
configuration.put("SearchBases", String.join("\n", searchBases));
configuration.put("ManagerDN", managerDN);
configuration.put("Password", password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
package cd.go.authentication.ldap;

import cd.go.authentication.ldap.model.*;
import org.junit.Test;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;

import static org.assertj.core.api.Assertions.assertThat;

@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
public class LdapAuthenticatorIntegrationTest extends BaseIntegrationTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import com.thoughtworks.go.plugin.api.request.DefaultGoPluginApiRequest;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import org.apache.commons.codec.binary.Base64;
import org.junit.Before;
import org.junit.Test;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static cd.go.authentication.ldap.executor.RequestFromServer.*;
import static cd.go.plugin.base.ResourceReader.readResource;
Expand All @@ -32,10 +35,14 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;

@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
public class LdapPluginIntegrationTest extends BaseIntegrationTest {
private LdapPlugin ldapPlugin;

@Before
@BeforeEach
public void setUp() {
ldapPlugin = new LdapPlugin();
ldapPlugin.initializeGoApplicationAccessor(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,26 @@
import cd.go.authentication.ldap.model.IsValidUserRequest;
import cd.go.authentication.ldap.model.LdapConfiguration;
import com.google.gson.Gson;
import org.junit.Before;
import org.junit.Test;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
public class IsValidUserExecutorIntegrationTest extends BaseIntegrationTest {
private LdapFactory ldapFactory;

@Before
@BeforeEach
public void setUp() {
ldapFactory = spy(new LdapFactory());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,27 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.thoughtworks.go.plugin.api.response.GoPluginApiResponse;
import org.junit.Before;
import org.junit.Test;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.*;

import static cd.go.authentication.ldap.utils.Util.GSON;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
public class SearchUserExecutorIntegrationTest extends BaseIntegrationTest {
private LdapFactory ldapFactory;
private SearchUserExecutor searchUserExecutor;

@Before
@BeforeEach
public void setUp() {
ldapFactory = spy(new LdapFactory());
searchUserExecutor = new SearchUserExecutor(ldapFactory);
Expand Down
27 changes: 22 additions & 5 deletions src/integration/cd/go/framework/ldap/LdapIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
import cd.go.authentication.ldap.mapper.UsernameResolver;
import cd.go.authentication.ldap.model.LdapConfiguration;
import cd.go.authentication.ldap.model.User;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.ProvideSystemProperty;
import org.apache.directory.server.annotations.CreateLdapServer;
import org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import uk.org.webcompere.systemstubs.jupiter.SystemStub;
import uk.org.webcompere.systemstubs.jupiter.SystemStubsExtension;
import uk.org.webcompere.systemstubs.properties.SystemProperties;

import javax.naming.directory.DirContext;
import java.util.List;
Expand All @@ -35,11 +41,22 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

@ApplyLdifFiles(value = "users.ldif", clazz = BaseIntegrationTest.class)
@CreateLdapServer(transports = {
@CreateTransport(protocol = "LDAP")
})
@ExtendWith(SystemStubsExtension.class)
public class LdapIntegrationTest extends BaseIntegrationTest {
@Rule
public final ProvideSystemProperty systemProperty = new ProvideSystemProperty(USE_JNDI_LDAP_CLIENT, "true");

@SystemStub
private SystemProperties systemProperties;
private JNDILdapClient jndiLdapClient;

@BeforeEach
public void setUp() {
systemProperties.set(USE_JNDI_LDAP_CLIENT, "true");
}

@Test
public void authenticate_shouldAuthenticateUser() {
LdapConfiguration ldapConfiguration = ldapConfiguration(new String[]{"ou=system"});
Expand Down

0 comments on commit 1251490

Please sign in to comment.