Skip to content

Commit 2ac4ed6

Browse files
authored
Add ldap module (#9987)
Provide LLdapContainer supporting `lldap/lldap` image. Fixes #9960
1 parent aa7ddc0 commit 2ac4ed6

File tree

12 files changed

+145
-0
lines changed

12 files changed

+145
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ body:
3434
- K3S
3535
- K6
3636
- Kafka
37+
- LDAP
3738
- LocalStack
3839
- MariaDB
3940
- Milvus

.github/ISSUE_TEMPLATE/enhancement.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ body:
3434
- K3S
3535
- K6
3636
- Kafka
37+
- LDAP
3738
- LocalStack
3839
- MariaDB
3940
- Milvus

.github/ISSUE_TEMPLATE/feature.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ body:
3434
- K3S
3535
- K6
3636
- Kafka
37+
- LDAP
3738
- LocalStack
3839
- MariaDB
3940
- Milvus

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ updates:
178178
schedule:
179179
interval: "weekly"
180180
open-pull-requests-limit: 10
181+
- package-ecosystem: "gradle"
182+
directory: "/modules/ldap"
183+
schedule:
184+
interval: "weekly"
185+
open-pull-requests-limit: 10
181186
- package-ecosystem: "gradle"
182187
directory: "/modules/localstack"
183188
schedule:

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@
107107
- changed-files:
108108
- any-glob-to-any-file:
109109
- modules/kafka/**/*
110+
"modules/ldap":
111+
- changed-files:
112+
- any-glob-to-any-file:
113+
- modules/ldap/**/*
110114
"modules/localstack":
111115
- changed-files:
112116
- any-glob-to-any-file:

.github/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ labels:
169169
- name: modules/kafka
170170
color: '#006b75'
171171

172+
- name: modules/ldap
173+
color: '#006b75'
174+
172175
- name: modules/localstack
173176
color: '#006b75'
174177

docs/modules/ldap.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# LDAP
2+
3+
Testcontainers module for [LLDAP](https://hub.docker.com/r/lldap/lldap).
4+
5+
## LLdapContainer's usage examples
6+
7+
You can start a LLDAP container instance from any Java application by using:
8+
9+
<!--codeinclude-->
10+
[LLDAP container](../../modules/ldap/src/test/java/org/testcontainers/ldap/LLdapContainerTest.java) inside_block:container
11+
<!--/codeinclude-->
12+
13+
## Adding this module to your project dependencies
14+
15+
Add the following dependency to your `pom.xml`/`build.gradle` file:
16+
17+
=== "Gradle"
18+
```groovy
19+
testImplementation "org.testcontainers:ldap:{{latest_version}}"
20+
```
21+
22+
=== "Maven"
23+
```xml
24+
<dependency>
25+
<groupId>org.testcontainers</groupId>
26+
<artifactId>ldap</artifactId>
27+
<version>{{latest_version}}</version>
28+
<scope>test</scope>
29+
</dependency>
30+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ nav:
8989
- modules/k3s.md
9090
- modules/k6.md
9191
- modules/kafka.md
92+
- modules/ldap.md
9293
- modules/localstack.md
9394
- modules/milvus.md
9495
- modules/minio.md

modules/ldap/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
description = "Testcontainers :: LDAP"
2+
3+
dependencies {
4+
api project(':testcontainers')
5+
6+
testImplementation 'org.assertj:assertj-core:3.26.3'
7+
testImplementation 'com.unboundid:unboundid-ldapsdk:7.0.2'
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.testcontainers.ldap;
2+
3+
import com.github.dockerjava.api.command.InspectContainerResponse;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.testcontainers.containers.GenericContainer;
6+
import org.testcontainers.containers.wait.strategy.Wait;
7+
import org.testcontainers.utility.DockerImageName;
8+
9+
/**
10+
* Testcontainers implementation for LLDAP.
11+
* <p>
12+
* Supported image: {@code lldap/lldap}
13+
* <p>
14+
* Exposed ports:
15+
* <ul>
16+
* <li>LDAP: 3890</li>
17+
* <li>UI: 17170</li>
18+
* </ul>
19+
*/
20+
@Slf4j
21+
public class LLdapContainer extends GenericContainer<LLdapContainer> {
22+
23+
private static final String IMAGE_VERSION = "lldap/lldap";
24+
25+
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE_VERSION);
26+
27+
private static final int LDAP_PORT = 3890;
28+
29+
private static final int UI_PORT = 17170;
30+
31+
public LLdapContainer(String image) {
32+
this(DockerImageName.parse(image));
33+
}
34+
35+
public LLdapContainer(DockerImageName image) {
36+
super(image);
37+
image.assertCompatibleWith(DEFAULT_IMAGE_NAME);
38+
addExposedPorts(LDAP_PORT, UI_PORT);
39+
40+
waitingFor(Wait.forHttp("/health").forPort(UI_PORT).forStatusCode(200));
41+
}
42+
43+
@Override
44+
protected void containerIsStarted(InspectContainerResponse containerInfo) {
45+
log.info("LLDAP container is ready! UI available at http://{}:{}", getHost(), getMappedPort(UI_PORT));
46+
}
47+
48+
public int getLdapPort() {
49+
return getMappedPort(LDAP_PORT);
50+
}
51+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.testcontainers.ldap;
2+
3+
import com.unboundid.ldap.sdk.BindResult;
4+
import com.unboundid.ldap.sdk.LDAPConnection;
5+
import com.unboundid.ldap.sdk.LDAPException;
6+
import org.junit.Test;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class LLdapContainerTest {
11+
12+
@Test
13+
public void test() throws LDAPException {
14+
try ( // container {
15+
LLdapContainer lldap = new LLdapContainer("lldap/lldap:v0.6.1-alpine")
16+
// }
17+
) {
18+
lldap.start();
19+
LDAPConnection connection = new LDAPConnection(lldap.getHost(), lldap.getLdapPort());
20+
BindResult result = connection.bind("cn=admin,ou=people,dc=example,dc=com", "password");
21+
assertThat(result).isNotNull();
22+
}
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<configuration>
2+
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<!-- encoders are assigned the type
5+
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
6+
<encoder>
7+
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
8+
</encoder>
9+
</appender>
10+
11+
<root level="INFO">
12+
<appender-ref ref="STDOUT"/>
13+
</root>
14+
15+
<logger name="org.testcontainers" level="INFO"/>
16+
</configuration>

0 commit comments

Comments
 (0)