[TEST] Fixes for randomised failures

- role_mapping.native is always present, but contains no entries if the security index is unavailable
- file based role mapping does not allow duplicate keys

Original commit: elastic/x-pack-elasticsearch@734cf7e2c0
This commit is contained in:
Tim Vernum 2017-05-04 20:13:56 +10:00
parent bbb3d008f2
commit b922b37c3f
3 changed files with 29 additions and 3 deletions

View File

@ -323,6 +323,26 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase
}
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final RoleMappingEntry that = (RoleMappingEntry) o;
return Objects.equals(this.fileContent, that.fileContent)
&& Objects.equals(this.nativeContent, that.nativeContent);
}
@Override
public int hashCode() {
int result = Objects.hashCode(fileContent);
result = 31 * result + Objects.hashCode(nativeContent);
return result;
}
}
/**

View File

@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings;
@ -40,8 +41,10 @@ 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 = new ArrayList<>(realmConfig.selectRoleMappings(() -> true));
AbstractAdLdapRealmTestCase.roleMappings.addAll(secondaryRealmConfig.selectRoleMappings(() -> true));
AbstractAdLdapRealmTestCase.roleMappings = Stream.concat(
realmConfig.selectRoleMappings(() -> true).stream(),
secondaryRealmConfig.selectRoleMappings(() -> true).stream()
).distinct().collect(Collectors.toList());
}
@Override

View File

@ -40,6 +40,8 @@ import java.util.Map;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.Is.is;
@ -237,7 +239,8 @@ public class SecurityFeatureSetTests extends ESTestCase {
assertThat(source.getValue("role_mapping.native.size"), is(12));
assertThat(source.getValue("role_mapping.native.enabled"), is(10));
} else {
assertThat(((Map) source.getValue("role_mapping")).isEmpty(), is(true));
final Map<String, Object> roleMapping = source.getValue("role_mapping.native");
assertThat(roleMapping.entrySet(), emptyIterable());
}
// system key