From 8633fd1f070867f0c3d5f09adfa41e2a528836aa Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Thu, 4 May 2017 18:05:26 +1000 Subject: [PATCH] [TESTS] Fix problem with AD integration test In some cases (based on the randomisation) the primary-realm would have no mappings, but the secondary-realm would. If this occurred we wouldn't write out any mappings and the secondary-realm would not authorize the access being tested Original commit: elastic/x-pack-elasticsearch@8e81ec9dd77a4486322b98d979aaee7eb8a9cfbb --- .../integration/ldap/MultipleAdRealmTests.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 4934b07799b..dc4eb9b09e5 100644 --- a/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java +++ b/plugin/src/test/java/org/elasticsearch/integration/ldap/MultipleAdRealmTests.java @@ -7,6 +7,7 @@ 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; @@ -28,10 +29,6 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase { @BeforeClass public static void setupSecondaryRealm() { - // 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 = realmConfig.selectRoleMappings(() -> true); - // Pick a secondary realm that has the inverse value for 'loginWithCommonName' compare with the primary realm final List configs = Arrays.stream(RealmConfig.values()) .filter(config -> config.loginWithCommonName != AbstractAdLdapRealmTestCase.realmConfig.loginWithCommonName) @@ -40,6 +37,11 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase { ESLoggerFactory.getLogger("test") .info("running test with secondary realm configuration [{}], with direct group to role mapping [{}]. Settings [{}]", secondaryRealmConfig, secondaryRealmConfig.mapGroupsAsRoles, secondaryRealmConfig.settings.getAsMap()); + + // 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 = new ArrayList<>(realmConfig.selectRoleMappings(() -> true)); + AbstractAdLdapRealmTestCase.roleMappings.addAll(secondaryRealmConfig.selectRoleMappings(() -> true)); } @Override