Skip to content

Commit

Permalink
Fix Noisy Warnings in SecurityIntegTestCase (elastic#82103)
Browse files Browse the repository at this point in the history
Adding the mapper extras plugin to avoid endless warnings about a
missing scaled_float mapper in these tests.
Also, removed some unrelated dead code that wasn't really worth a separate PR.
  • Loading branch information
original-brownbear authored and astefan committed Jan 7, 2022
1 parent a85fe51 commit c4e0c5b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.SecuritySingleNodeTestCase;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.core.security.authc.Authentication;
import org.elasticsearch.xpack.core.security.user.User;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -58,13 +54,6 @@ protected String configUsersRoles() {
return super.configUsersRoles() + "rac_role:" + RAC_USER_NAME + "\n";
}

@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
final ArrayList<Class<? extends Plugin>> plugins = new ArrayList<>(super.getPlugins());
plugins.add(MapperExtrasPlugin.class);
return plugins;
}

public void testProfileIndexAutoCreation() {
var indexResponse = client().prepareIndex(randomFrom(INTERNAL_SECURITY_PROFILE_INDEX_8, SECURITY_PROFILE_ALIAS))
.setSource(Map.of("uid", randomAlphaOfLength(22)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.netty.util.ThreadDeathWatcher;
import io.netty.util.concurrent.GlobalEventExecutor;

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
Expand All @@ -22,7 +21,6 @@
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.IndexAbstraction;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.routing.IndexRoutingTable;
Expand All @@ -33,8 +31,6 @@
import org.elasticsearch.index.Index;
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
import org.elasticsearch.xpack.security.LocalStateSecurity;
Expand All @@ -56,11 +52,9 @@

import static org.elasticsearch.test.SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames.SECURITY_MAIN_ALIAS;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;

/**
* Base class to run tests against a cluster with X-Pack installed and security enabled.
Expand Down Expand Up @@ -368,12 +362,6 @@ protected SecureString nodeClientPassword() {
}
}

protected static void assertGreenClusterState(Client client) {
ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().get();
assertNoTimeout(clusterHealthResponse);
assertThat(clusterHealthResponse.getStatus(), is(ClusterHealthStatus.GREEN));
}

/**
* Creates the indices provided as argument, randomly associating them with aliases, indexes one dummy document per index
* and refreshes the new indices
Expand Down Expand Up @@ -430,7 +418,6 @@ public void assertSecurityIndexActive(TestCluster testCluster) throws Exception
assertBusy(() -> {
ClusterState clusterState = client.admin().cluster().prepareState().setLocal(true).get().getState();
assertFalse(clusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK));
XContentBuilder builder = JsonXContent.contentBuilder().prettyPrint().startObject();
Index securityIndex = resolveSecurityIndex(clusterState.metadata());
if (securityIndex != null) {
IndexRoutingTable indexRoutingTable = clusterState.routingTable().index(securityIndex);
Expand Down Expand Up @@ -471,10 +458,6 @@ private static Index resolveSecurityIndex(Metadata metadata) {
return null;
}

protected boolean isTransportSSLEnabled() {
return customSecuritySettingsSource.isSslEnabled();
}

public static Hasher getFastStoredHashAlgoForTests() {
return inFipsJvm()
? Hasher.resolve(randomFrom("pbkdf2", "pbkdf2_1000", "pbkdf2_stretch_1000", "pbkdf2_stretch"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.mapper.extras.MapperExtrasPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.reindex.ReindexPlugin;
import org.elasticsearch.test.ESIntegTestCase.Scope;
Expand Down Expand Up @@ -178,20 +179,15 @@ public Path nodeConfigPath(int nodeOrdinal) {
return nodePath(nodeOrdinal).resolve("config");
}

protected void addDefaultSecurityTransportType(Settings.Builder builder, Settings settings) {
if (NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings) == false) {
builder.put(NetworkModule.TRANSPORT_TYPE_SETTING.getKey(), SecurityField.NAME4);
}
}

@Override
public Collection<Class<? extends Plugin>> nodePlugins() {
return Arrays.asList(
LocalStateSecurity.class,
Netty4Plugin.class,
ReindexPlugin.class,
CommonAnalysisPlugin.class,
InternalSettingsPlugin.class
InternalSettingsPlugin.class,
MapperExtrasPlugin.class
);
}

Expand Down Expand Up @@ -262,43 +258,6 @@ private void addNodeSSLSettings(Settings.Builder builder) {
}
}

public void addClientSSLSettings(Settings.Builder builder, String prefix) {
builder.put("xpack.security.transport.ssl.enabled", sslEnabled);
if (usePEM) {
addSSLSettingsForPEMFiles(
builder,
prefix,
"/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.pem",
"testclient",
"/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.crt",
Arrays.asList(
"/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.crt",
"/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode_ec.crt",
"/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.crt"
),
hostnameVerificationEnabled
);
} else {
addSSLSettingsForStore(
builder,
prefix,
"/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testclient.jks",
"testclient",
hostnameVerificationEnabled
);
}
}

/**
* Returns the configuration settings given the location of a certificate and its password
*
* @param resourcePathToStore the location of the keystore or truststore
* @param password the password
*/
public static void addSSLSettingsForStore(Settings.Builder builder, String resourcePathToStore, String password, String prefix) {
addSSLSettingsForStore(builder, prefix, resourcePathToStore, password, true);
}

private static void addSSLSettingsForStore(
Settings.Builder builder,
String prefix,
Expand Down

0 comments on commit c4e0c5b

Please sign in to comment.