Skip to content

Commit 85697fd

Browse files
committed
Add method to return LDAP URL to LLdapContainer
1 parent 2ac4ed6 commit 85697fd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

modules/ldap/src/main/java/org/testcontainers/ldap/LLdapContainer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
4848
public int getLdapPort() {
4949
return getMappedPort(LDAP_PORT);
5050
}
51+
52+
public String getLdapUrl() {
53+
return String.format("ldap://%s:%d", getHost(), getLdapPort());
54+
}
5155
}

modules/ldap/src/test/java/org/testcontainers/ldap/LLdapContainerTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.unboundid.ldap.sdk.BindResult;
44
import com.unboundid.ldap.sdk.LDAPConnection;
55
import com.unboundid.ldap.sdk.LDAPException;
6+
import com.unboundid.ldap.sdk.LDAPURL;
67
import org.junit.Test;
78

89
import static org.assertj.core.api.Assertions.assertThat;
@@ -21,4 +22,19 @@ public void test() throws LDAPException {
2122
assertThat(result).isNotNull();
2223
}
2324
}
25+
26+
@Test
27+
public void testUsingLdapUrl() throws LDAPException {
28+
try ( // container {
29+
LLdapContainer lldap = new LLdapContainer("lldap/lldap:v0.6.1-alpine")
30+
// }
31+
) {
32+
lldap.start();
33+
34+
LDAPURL ldapUrl = new LDAPURL(lldap.getLdapUrl());
35+
LDAPConnection connection = new LDAPConnection(ldapUrl.getHost(), ldapUrl.getPort());
36+
BindResult result = connection.bind("cn=admin,ou=people,dc=example,dc=com", "password");
37+
assertThat(result).isNotNull();
38+
}
39+
}
2440
}

0 commit comments

Comments
 (0)