You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by co...@apache.org on 2026/04/15 14:17:00 UTC
(directory-ldap-api) branch coheigea/hardcoded-credentials created (now 3e88a9e14)
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a change to branch coheigea/hardcoded-credentials
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
at 3e88a9e14 Remove hard-coded credentials in LdapNetworkConnection
This branch includes the following new commits:
new 3e88a9e14 Remove hard-coded credentials in LdapNetworkConnection
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(directory-ldap-api) 01/01: Remove hard-coded credentials in LdapNetworkConnection
Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch coheigea/hardcoded-credentials
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
commit 3e88a9e140d3216485cb3a72c816598e27f7501d
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Apr 15 15:16:36 2026 +0100
Remove hard-coded credentials in LdapNetworkConnection
---
.../ldap/client/api/LdapNetworkConnection.java | 4 +-
.../ldap/client/api/LdapNetworkConnectionTest.java | 43 ++++++++++++++++++++++
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
index 707d32e83..b1f9c06c0 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -1872,7 +1872,7 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
{
SaslCramMd5Request request = new SaslCramMd5Request();
request.setUsername( userName );
- request.setCredentials( "secret" );
+ request.setCredentials( credentials );
return bind( request );
}
@@ -1890,7 +1890,7 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
{
SaslDigestMd5Request request = new SaslDigestMd5Request();
request.setUsername( userName );
- request.setCredentials( "secret" );
+ request.setCredentials( credentials );
return bind( request );
}
diff --git a/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java b/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
index 9fe4710b1..cf3358030 100644
--- a/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
+++ b/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/LdapNetworkConnectionTest.java
@@ -20,11 +20,20 @@
package org.apache.directory.ldap.client.api;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.stream.Stream;
+import org.apache.directory.api.ldap.model.message.BindResponse;
+import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -38,6 +47,40 @@ import org.junit.jupiter.params.provider.MethodSource;
public class LdapNetworkConnectionTest
{
+ @Test
+ public void testBindSaslCramMd5ForwardsCredentials() throws Exception
+ {
+ LdapNetworkConnection connection = spy( new LdapNetworkConnection( "localhost", 389 ) );
+ doReturn( null ).when( connection ).bind( any( SaslCramMd5Request.class ) );
+
+ ArgumentCaptor<SaslCramMd5Request> captor = ArgumentCaptor.forClass( SaslCramMd5Request.class );
+
+ connection.bindSaslCramMd5( "uid=alice", "correctPassword" );
+
+ verify( connection ).bind( captor.capture() );
+ assertEquals( "uid=alice", captor.getValue().getUsername() );
+ assertArrayEquals( "correctPassword".getBytes( StandardCharsets.UTF_8 ), captor.getValue().getCredentials(),
+ "bindSaslCramMd5 must forward the credentials parameter, not use a hardcoded value" );
+ }
+
+
+ @Test
+ public void testBindSaslDigestMd5ForwardsCredentials() throws Exception
+ {
+ LdapNetworkConnection connection = spy( new LdapNetworkConnection( "localhost", 389 ) );
+ doReturn( null ).when( connection ).bind( any( SaslDigestMd5Request.class ) );
+
+ ArgumentCaptor<SaslDigestMd5Request> captor = ArgumentCaptor.forClass( SaslDigestMd5Request.class );
+
+ connection.bindSaslDigestMd5( "uid=alice", "correctPassword" );
+
+ verify( connection ).bind( captor.capture() );
+ assertEquals( "uid=alice", captor.getValue().getUsername() );
+ assertArrayEquals( "correctPassword".getBytes( StandardCharsets.UTF_8 ), captor.getValue().getCredentials(),
+ "bindSaslDigestMd5 must forward the credentials parameter, not use a hardcoded value" );
+ }
+
+
private static Stream<Arguments> data()
{
// index 0: connection timout in ms