[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@8e81ec9dd7
This commit is contained in:
Tim Vernum 2017-05-04 18:05:26 +10:00
parent 770404200e
commit 8633fd1f07
1 changed files with 6 additions and 4 deletions

View File

@ -7,6 +7,7 @@ package org.elasticsearch.integration.ldap;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -28,10 +29,6 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase {
@BeforeClass @BeforeClass
public static void setupSecondaryRealm() { 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 // Pick a secondary realm that has the inverse value for 'loginWithCommonName' compare with the primary realm
final List<RealmConfig> configs = Arrays.stream(RealmConfig.values()) final List<RealmConfig> configs = Arrays.stream(RealmConfig.values())
.filter(config -> config.loginWithCommonName != AbstractAdLdapRealmTestCase.realmConfig.loginWithCommonName) .filter(config -> config.loginWithCommonName != AbstractAdLdapRealmTestCase.realmConfig.loginWithCommonName)
@ -40,6 +37,11 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase {
ESLoggerFactory.getLogger("test") ESLoggerFactory.getLogger("test")
.info("running test with secondary realm configuration [{}], with direct group to role mapping [{}]. Settings [{}]", .info("running test with secondary realm configuration [{}], with direct group to role mapping [{}]. Settings [{}]",
secondaryRealmConfig, secondaryRealmConfig.mapGroupsAsRoles, secondaryRealmConfig.settings.getAsMap()); 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 @Override