[TESTS] Test resolving ldap groups with preloaded attributes (elastic/elasticsearch#4530)

Add a test for the `UserAttributeGroupsResolver` when using attributes provided as a parameter.

(ported from commit elastic/x-pack@ebc62b7, elastic/elasticsearch#4522)

Original commit: elastic/x-pack-elasticsearch@6502fdb801
This commit is contained in:
Tim Vernum 2017-01-05 17:42:28 +11:00 committed by GitHub
parent 3c68e6dd23
commit ca3bbc7da0
1 changed files with 20 additions and 1 deletions

View File

@ -5,11 +5,16 @@
*/ */
package org.elasticsearch.xpack.security.authc.ldap; package org.elasticsearch.xpack.security.authc.ldap;
import com.unboundid.ldap.sdk.Attribute;
import com.unboundid.ldap.sdk.SearchRequest;
import com.unboundid.ldap.sdk.SearchScope;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.security.authc.ldap.support.LdapUtils;
import org.elasticsearch.xpack.security.support.NoOpLogger; import org.elasticsearch.xpack.security.support.NoOpLogger;
import org.elasticsearch.test.junit.annotations.Network; import org.elasticsearch.test.junit.annotations.Network;
import java.util.Collection;
import java.util.List; import java.util.List;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
@ -34,6 +39,20 @@ public class UserAttributeGroupsResolverTests extends GroupsResolverTestCase {
containsString("Philanthropists"))); containsString("Philanthropists")));
} }
public void testResolveFromPreloadedAttributes() throws Exception {
SearchRequest preSearch = new SearchRequest(BRUCE_BANNER_DN, SearchScope.BASE, LdapUtils.OBJECT_CLASS_PRESENCE_FILTER, "memberOf");
final Collection<Attribute> attributes = ldapConnection.searchForEntry(preSearch).getAttributes();
UserAttributeGroupsResolver resolver = new UserAttributeGroupsResolver(Settings.EMPTY);
List<String> groups =
resolveBlocking(resolver, ldapConnection, BRUCE_BANNER_DN, TimeValue.timeValueSeconds(20), NoOpLogger.INSTANCE, attributes);
assertThat(groups, containsInAnyOrder(
containsString("Avengers"),
containsString("SHIELD"),
containsString("Geniuses"),
containsString("Philanthropists")));
}
public void testResolveCustomGroupAttribute() throws Exception { public void testResolveCustomGroupAttribute() throws Exception {
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put("user_group_attribute", "seeAlso") .put("user_group_attribute", "seeAlso")