From 0a15b033959cf791807ca6153fe875944079442f Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Mon, 8 May 2017 00:16:35 +1000 Subject: [PATCH] [TESTS] A proper fix to MultipleAdRealmTests Original commit: elastic/x-pack-elasticsearch@f04b3ebb7a9bbe5613e5f2d1df60fe1b80f8d1f1 --- .../ldap/AbstractAdLdapRealmTestCase.java | 16 ++++++++++------ .../integration/ldap/MultipleAdRealmTests.java | 9 +++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java b/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java index 26750684ee3..a3603674f9d 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java +++ b/plugin/src/test/java/org/elasticsearch/integration/ldap/AbstractAdLdapRealmTestCase.java @@ -144,14 +144,14 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase } else { builder.put(super.nodeSettings(nodeOrdinal)); } - builder.put(buildRealmSettings(realm, store)); + builder.put(buildRealmSettings(realm, roleMappings, store)); return builder.build(); } - protected Settings buildRealmSettings(RealmConfig realm, Path store) { + protected Settings buildRealmSettings(RealmConfig realm, List roleMappingEntries, Path store) { Settings.Builder builder = Settings.builder(); builder.put(realm.buildSettings(store, "testnode")); - configureRoleMappings(builder); + configureFileRoleMappings(builder, roleMappingEntries); return builder.build(); } @@ -184,7 +184,11 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase } private List getRoleMappingContent(Function contentFunction) { - return roleMappings.stream() + return getRoleMappingContent(contentFunction, AbstractAdLdapRealmTestCase.roleMappings); + } + + private List getRoleMappingContent(Function contentFunction, List mappings) { + return mappings.stream() .map(contentFunction) .filter(Objects::nonNull) .collect(Collectors.toList()); @@ -208,8 +212,8 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase return useGlobalSSL == false; } - protected final void configureRoleMappings(Settings.Builder builder) { - String content = getRoleMappingContent(RoleMappingEntry::getFileContent).stream().collect(Collectors.joining("\n")); + protected final void configureFileRoleMappings(Settings.Builder builder, List mappings) { + String content = getRoleMappingContent(RoleMappingEntry::getFileContent, mappings).stream().collect(Collectors.joining("\n")); Path nodeFiles = createTempDir(); String file = writeFile(nodeFiles, "role_mapping.yml", content); builder.put(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + ".files.role_mapping", file); diff --git a/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java b/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java index 22edbbdccd1..add92fcf8af 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java +++ b/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.integration.ldap; import java.io.IOException; import java.nio.file.Path; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -42,10 +41,7 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase { // It's easier to test 2 realms when using file based role mapping, and for the purposes of // this test, there's no need to test native mappings. - AbstractAdLdapRealmTestCase.roleMappings = Stream.concat( - realmConfig.selectRoleMappings(() -> true).stream(), - secondaryRealmConfig.selectRoleMappings(() -> true).stream() - ).distinct().collect(Collectors.toList()); + AbstractAdLdapRealmTestCase.roleMappings = realmConfig.selectRoleMappings(() -> true); } @Override @@ -54,7 +50,8 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase { builder.put(super.nodeSettings(nodeOrdinal)); Path store = getDataPath(TESTNODE_KEYSTORE); - final Settings secondarySettings = super.buildRealmSettings(secondaryRealmConfig, store); + final List secondaryRoleMappings = secondaryRealmConfig.selectRoleMappings(() -> true); + final Settings secondarySettings = super.buildRealmSettings(secondaryRealmConfig, secondaryRoleMappings, store); secondarySettings.getAsMap().forEach((name, value) -> { name = name.replace(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL, XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + "2"); builder.put(name, value);