Skip to content

Commit 9f00baf

Browse files
author
Vladimir Kotal
committed
handle null attributes in getSearchDescription()
fixes #3360
1 parent 70b5b62 commit 9f00baf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

plugins/src/main/java/opengrok/auth/plugin/ldap/LdapFacade.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,18 @@ private <T> LdapSearchResult<T> lookup(String dn, String filter, String[] attrib
307307
return res;
308308
}
309309

310-
private String getSearchDescription(String dn, String filter, String[] attributes) {
311-
return "DN: " + dn + " , filter: " + filter + " , attributes: " + String.join(",", attributes);
310+
// available for testing
311+
static String getSearchDescription(String dn, String filter, String[] attributes) {
312+
StringBuilder builder = new StringBuilder();
313+
builder.append("DN: ");
314+
builder.append(dn);
315+
builder.append(" , filter: ");
316+
builder.append(filter);
317+
if (attributes != null) {
318+
builder.append(" , attributes: ");
319+
builder.append(String.join(",", attributes));
320+
}
321+
return builder.toString();
312322
}
313323

314324
/**

plugins/src/test/java/opengrok/auth/plugin/ldap/LdapFacadeTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,12 @@ public void testPrepareServersNegative() throws UnknownHostException {
131131
facade.prepareServers();
132132
assertFalse(facade.isConfigured());
133133
}
134+
135+
@Test
136+
public void testGetSearchDescription() {
137+
assertEquals("DN: foo , filter: bar , attributes: Bilbo,Frodo",
138+
LdapFacade.getSearchDescription("foo", "bar", new String[]{"Bilbo", "Frodo"}));
139+
assertEquals("DN: foo , filter: bar",
140+
LdapFacade.getSearchDescription("foo", "bar", null));
141+
}
134142
}

0 commit comments

Comments
 (0)