8000 Prevent LDAP group sync from looping forever when batch size is zero by Thufayl · Pull Request #55635 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public int getMaxConditions() {

public int getBatchSizeForSync() {
String pageSizeConfig = config.getFirst(LDAPConstants.BATCH_SIZE_FOR_SYNC);
return pageSizeConfig!=null ? Integer.parseInt(pageSizeConfig) : LDAPConstants.DEFAULT_BATCH_SIZE_FOR_SYNC;
int batchSize = pageSizeConfig != null ? Integer.parseInt(pageSizeConfig) : LDAPConstants.DEFAULT_BATCH_SIZE_FOR_SYNC;
return batchSize > 0 ? batchSize : LDAPConstants.DEFAULT_BATCH_SIZE_FOR_SYNC;
}

public String getUsernameLdapAttribute() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.keycloak.storage.ldap;

import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.models.LDAPConstants;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class LDAPConfigTest {

private static LDAPConfig configWithBatchSize(String value) {
MultivaluedHashMap<String, String> map = new MultivaluedHashMap<>();
if (value != null) {
map.putSingle(LDAPConstants.BATCH_SIZE_FOR_SYNC, value);
}
return new LDAPConfig(map);
}

@Test
public void zeroBatchSizeFallsBackToDefault() {
assertEquals(LDAPConstants.DEFAULT_BATCH_SIZE_FOR_SYNC,
configWithBatchSize("0").getBatchSizeForSync());
}

@Test
public void negativeBatchSizeFallsBackToDefault() {
assertEquals(LDAPConstants.DEFAULT_BATCH_SIZE_FOR_SYNC,
configWithBatchSize("-5").getBatchSizeForSync());
}

@Test
public void unsetBatchSizeUsesDefault() {
assertEquals(LDAPConstants.DEFAULT_BATCH_SIZE_FOR_SYNC,
configWithBatchSize(null).getBatchSizeForSync());
}

@Test
public void positiveBatchSizeIsKept() {
assertEquals(500, configWithBatchSize("500").getBatchSizeForSync());
}
}
0