Skip to content

Commit

Permalink
Add method to return LDAP URL to LLdapContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez committed Feb 19, 2025
1 parent 2ac4ed6 commit 85697fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ protected void containerIsStarted(InspectContainerResponse containerInfo) {
public int getLdapPort() {
return getMappedPort(LDAP_PORT);
}

public String getLdapUrl() {
return String.format("ldap://%s:%d", getHost(), getLdapPort());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.LDAPURL;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -21,4 +22,19 @@ public void test() throws LDAPException {
assertThat(result).isNotNull();
}
}

@Test
public void testUsingLdapUrl() throws LDAPException {
try ( // container {
LLdapContainer lldap = new LLdapContainer("lldap/lldap:v0.6.1-alpine")
// }
) {
lldap.start();

LDAPURL ldapUrl = new LDAPURL(lldap.getLdapUrl());
LDAPConnection connection = new LDAPConnection(ldapUrl.getHost(), ldapUrl.getPort());
BindResult result = connection.bind("cn=admin,ou=people,dc=example,dc=com", "password");
assertThat(result).isNotNull();
}
}
}

0 comments on commit 85697fd

Please sign in to comment.