[TESTS] A proper fix to MultipleAdRealmTests
Original commit: elastic/x-pack-elasticsearch@f04b3ebb7a
This commit is contained in:
parent
f18a7f0f68
commit
0a15b03395
|
@ -144,14 +144,14 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase
|
||||||
} else {
|
} else {
|
||||||
builder.put(super.nodeSettings(nodeOrdinal));
|
builder.put(super.nodeSettings(nodeOrdinal));
|
||||||
}
|
}
|
||||||
builder.put(buildRealmSettings(realm, store));
|
builder.put(buildRealmSettings(realm, roleMappings, store));
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Settings buildRealmSettings(RealmConfig realm, Path store) {
|
protected Settings buildRealmSettings(RealmConfig realm, List<RoleMappingEntry> roleMappingEntries, Path store) {
|
||||||
Settings.Builder builder = Settings.builder();
|
Settings.Builder builder = Settings.builder();
|
||||||
builder.put(realm.buildSettings(store, "testnode"));
|
builder.put(realm.buildSettings(store, "testnode"));
|
||||||
configureRoleMappings(builder);
|
configureFileRoleMappings(builder, roleMappingEntries);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,11 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getRoleMappingContent(Function<RoleMappingEntry, String> contentFunction) {
|
private List<String> getRoleMappingContent(Function<RoleMappingEntry, String> contentFunction) {
|
||||||
return roleMappings.stream()
|
return getRoleMappingContent(contentFunction, AbstractAdLdapRealmTestCase.roleMappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getRoleMappingContent(Function<RoleMappingEntry, String> contentFunction, List<RoleMappingEntry> mappings) {
|
||||||
|
return mappings.stream()
|
||||||
.map(contentFunction)
|
.map(contentFunction)
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
@ -208,8 +212,8 @@ public abstract class AbstractAdLdapRealmTestCase extends SecurityIntegTestCase
|
||||||
return useGlobalSSL == false;
|
return useGlobalSSL == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void configureRoleMappings(Settings.Builder builder) {
|
protected final void configureFileRoleMappings(Settings.Builder builder, List<RoleMappingEntry> mappings) {
|
||||||
String content = getRoleMappingContent(RoleMappingEntry::getFileContent).stream().collect(Collectors.joining("\n"));
|
String content = getRoleMappingContent(RoleMappingEntry::getFileContent, mappings).stream().collect(Collectors.joining("\n"));
|
||||||
Path nodeFiles = createTempDir();
|
Path nodeFiles = createTempDir();
|
||||||
String file = writeFile(nodeFiles, "role_mapping.yml", content);
|
String file = writeFile(nodeFiles, "role_mapping.yml", content);
|
||||||
builder.put(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + ".files.role_mapping", file);
|
builder.put(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + ".files.role_mapping", file);
|
||||||
|
|
|
@ -7,7 +7,6 @@ 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;
|
||||||
|
@ -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
|
// 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.
|
// this test, there's no need to test native mappings.
|
||||||
AbstractAdLdapRealmTestCase.roleMappings = Stream.concat(
|
AbstractAdLdapRealmTestCase.roleMappings = realmConfig.selectRoleMappings(() -> true);
|
||||||
realmConfig.selectRoleMappings(() -> true).stream(),
|
|
||||||
secondaryRealmConfig.selectRoleMappings(() -> true).stream()
|
|
||||||
).distinct().collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +50,8 @@ public class MultipleAdRealmTests extends AbstractAdLdapRealmTestCase {
|
||||||
builder.put(super.nodeSettings(nodeOrdinal));
|
builder.put(super.nodeSettings(nodeOrdinal));
|
||||||
|
|
||||||
Path store = getDataPath(TESTNODE_KEYSTORE);
|
Path store = getDataPath(TESTNODE_KEYSTORE);
|
||||||
final Settings secondarySettings = super.buildRealmSettings(secondaryRealmConfig, store);
|
final List<RoleMappingEntry> secondaryRoleMappings = secondaryRealmConfig.selectRoleMappings(() -> true);
|
||||||
|
final Settings secondarySettings = super.buildRealmSettings(secondaryRealmConfig, secondaryRoleMappings, store);
|
||||||
secondarySettings.getAsMap().forEach((name, value) -> {
|
secondarySettings.getAsMap().forEach((name, value) -> {
|
||||||
name = name.replace(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL, XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + "2");
|
name = name.replace(XPACK_SECURITY_AUTHC_REALMS_EXTERNAL, XPACK_SECURITY_AUTHC_REALMS_EXTERNAL + "2");
|
||||||
builder.put(name, value);
|
builder.put(name, value);
|
||||||
|
|
Loading…
Reference in New Issue