-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add ldap module #9987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add ldap module #9987
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ body: | |
| - K3S | ||
| - K6 | ||
| - Kafka | ||
| - LDAP | ||
| - LocalStack | ||
| - MariaDB | ||
| - Milvus | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ body: | |
| - K3S | ||
| - K6 | ||
| - Kafka | ||
| - LDAP | ||
| - LocalStack | ||
| - MariaDB | ||
| - Milvus | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ body: | |
| - K3S | ||
| - K6 | ||
| - Kafka | ||
| - LDAP | ||
| - LocalStack | ||
| - MariaDB | ||
| - Milvus | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # LDAP | ||
|
|
||
| Testcontainers module for [LLDAP](https://hub.docker.com/r/lldap/lldap). | ||
|
|
||
| ## LLdapContainer's usage examples | ||
|
|
||
| You can start a LLDAP container instance from any Java application by using: | ||
|
|
||
| <!--codeinclude--> | ||
| [LLDAP container](../../modules/ldap/src/test/java/org/testcontainers/ldap/LLdapContainerTest.java) inside_block:container | ||
| <!--/codeinclude--> | ||
|
|
||
| ## Adding this module to your project dependencies | ||
|
|
||
| Add the following dependency to your `pom.xml`/`build.gradle` file: | ||
|
|
||
| === "Gradle" | ||
| ```groovy | ||
| testImplementation "org.testcontainers:ldap:{{latest_version}}" | ||
| ``` | ||
|
|
||
| === "Maven" | ||
| ```xml | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>ldap</artifactId> | ||
| <version>{{latest_version}}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| description = "Testcontainers :: LDAP" | ||
|
|
||
| dependencies { | ||
| api project(':testcontainers') | ||
|
|
||
| testImplementation 'org.assertj:assertj-core:3.26.3' | ||
| testImplementation 'com.unboundid:unboundid-ldapsdk:7.0.2' | ||
| } |
51 changes: 51 additions & 0 deletions
51
modules/ldap/src/main/java/org/testcontainers/ldap/LLdapContainer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package org.testcontainers.ldap; | ||
|
|
||
| import com.github.dockerjava.api.command.InspectContainerResponse; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.testcontainers.containers.GenericContainer; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
| import org.testcontainers.utility.DockerImageName; | ||
|
|
||
| /** | ||
| * Testcontainers implementation for LLDAP. | ||
| * <p> | ||
| * Supported image: {@code lldap/lldap} | ||
| * <p> | ||
| * Exposed ports: | ||
| * <ul> | ||
| * <li>LDAP: 3890</li> | ||
| * <li>UI: 17170</li> | ||
| * </ul> | ||
| */ | ||
| @Slf4j | ||
| public class LLdapContainer extends GenericContainer<LLdapContainer> { | ||
|
|
||
| private static final String IMAGE_VERSION = "lldap/lldap"; | ||
|
|
||
| private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE_VERSION); | ||
|
|
||
| private static final int LDAP_PORT = 3890; | ||
|
|
||
| private static final int UI_PORT = 17170; | ||
|
|
||
| public LLdapContainer(String image) { | ||
| this(DockerImageName.parse(image)); | ||
| } | ||
|
|
||
| public LLdapContainer(DockerImageName image) { | ||
| super(image); | ||
| image.assertCompatibleWith(DEFAULT_IMAGE_NAME); | ||
| addExposedPorts(LDAP_PORT, UI_PORT); | ||
|
|
||
| waitingFor(Wait.forHttp("/health").forPort(UI_PORT).forStatusCode(200)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void containerIsStarted(InspectContainerResponse containerInfo) { | ||
| log.info("LLDAP container is ready! UI available at http://{}:{}", getHost(), getMappedPort(UI_PORT)); | ||
| } | ||
|
|
||
| public int getLdapPort() { | ||
| return getMappedPort(LDAP_PORT); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
modules/ldap/src/test/java/org/testcontainers/ldap/LLdapContainerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.testcontainers.ldap; | ||
|
|
||
| import com.unboundid.ldap.sdk.BindResult; | ||
| import com.unboundid.ldap.sdk.LDAPConnection; | ||
| import com.unboundid.ldap.sdk.LDAPException; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class LLdapContainerTest { | ||
|
|
||
| @Test | ||
| public void test() throws LDAPException { | ||
| try ( // container { | ||
| LLdapContainer lldap = new LLdapContainer("lldap/lldap:v0.6.1-alpine") | ||
| // } | ||
| ) { | ||
| lldap.start(); | ||
| LDAPConnection connection = new LDAPConnection(lldap.getHost(), lldap.getLdapPort()); | ||
| BindResult result = connection.bind("cn=admin,ou=people,dc=example,dc=com", "password"); | ||
| assertThat(result).isNotNull(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <configuration> | ||
|
|
||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <!-- encoders are assigned the type | ||
| ch.qos.logback.classic.encoder.PatternLayoutEncoder by default --> | ||
| <encoder> | ||
| <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <root level="INFO"> | ||
| <appender-ref ref="STDOUT"/> | ||
| </root> | ||
|
|
||
| <logger name="org.testcontainers" level="INFO"/> | ||
| </configuration> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think of adding an abstract
LdapContainerclass as adapter (similar toorg.testcontainers.containers.JdbcDatabaseContainer).By doing so, we could (later) add support for other containers like 'bitnami/openldap' or 'docker-openldap' at a later time
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is different. I don't see much shared between ldap as you can see in the implementation. It only took exposed ports and specific wait strategy.
We still can add other implementations later with the proper setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello,
I believe introducing an abstract class for the LDAP container could be beneficial once a second LDAP container is added to Testcontainers. For Spring Boot, this would allow the creation of a single
ContainerConnectionDetailsFactory, similar to theJdbcContainerConnectionDetailsFactory.@eddumelendez: Do you think it would be valuable to add another LDAP container for the bitnami/openldap image in the near future? If so, please let me know if you would welcome an OSS contribution on this.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand that. I think this in general could be something to revisit in a major version.
bitnami has really great images with easy configuration for some scenarios. I wish there is a bitnami module with support for their images. But, the suggestion was declined, see bitnami/containers#74973. And for us, it is getting a bit complex to handle many modules.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eddumelendez ,
I understand your point of delaying this abstraction.
Still, I think that such introduction "now" would have made the in the integration in "spring-boot" testcontainers easier and "future" proven.
By "future" proven, I mean there are a few ldap Information any ldap container should share: