[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
@@ -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<RealmConfig> 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
