Network: Remove http.enabled setting (#29601)

This commit removes the http.enabled setting. While all real nodes (started with bin/elasticsearch) will always have an http binding, there are many tests that rely on the quickness of not actually needing to bind to 2 ports. For this case, the MockHttpTransport.TestPlugin provides a dummy http transport implementation which is used by default in ESIntegTestCase.

closes #12792
This commit is contained in:
Ryan Ernst 2018-05-02 11:42:05 -07:00 committed by GitHub
parent 6d6da7c661
commit fb0aa562a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
63 changed files with 340 additions and 260 deletions

View File

@ -35,6 +35,9 @@ Machine Learning::
* The `max_running_jobs` node property is removed in this release. Use the
`xpack.ml.max_open_jobs` setting instead. For more information, see <<ml-settings>>.
* <<remove-http-enabled, Removed `http.enabled` setting>> ({pull}29601[#29601])
=== Deprecations
Monitoring::
* The `xpack.monitoring.collection.interval` setting can no longer be set to `-1`
to disable monitoring data collection. Use `xpack.monitoring.collection.enabled`

View File

@ -25,3 +25,10 @@
the system property `es.thread_pool.write.use_bulk_as_display_name` was
available to keep the display output in APIs as `bulk` instead of `write`.
These fallback settings and this system property have been removed.
[[remove-http-enabled]]
==== Http enabled setting removed
The setting `http.enabled` previously allowed disabling binding to HTTP, only allowing
use of the transport client. This setting has been removed, as the transport client
will be removed in the future, thus requiring HTTP to always be enabled.

View File

@ -110,16 +110,3 @@ client HTTP responses, defaults to unbounded.
It also uses the common
<<modules-network,network settings>>.
[float]
=== Disable HTTP
The http module can be completely disabled and not started by setting
`http.enabled` to `false`. Elasticsearch nodes (and Java clients) communicate
internally using the <<modules-transport,transport interface>>, not HTTP. It
might make sense to disable the `http` layer entirely on nodes which are not
meant to serve REST requests directly. For instance, you could disable HTTP on
<<modules-node,data-only nodes>> if you also have
<<modules-node,client nodes>> which are intended to serve all REST requests.
Be aware, however, that you will not be able to send any REST requests (eg to
retrieve node stats) directly to nodes which have HTTP disabled.

View File

@ -75,10 +75,14 @@ public class ReindexFromRemoteWithAuthTests extends ESSingleNodeTestCase {
ReindexPlugin.class);
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings() {
Settings.Builder settings = Settings.builder().put(super.nodeSettings());
settings.put(NetworkModule.HTTP_ENABLED.getKey(), true);
// Whitelist reindexing from the http host we're going to use
settings.put(TransportReindexAction.REMOTE_CLUSTER_WHITELIST.getKey(), "127.0.0.1:*");
settings.put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME);

View File

@ -91,10 +91,13 @@ public class RetryTests extends ESIntegTestCase {
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put(nodeSettings()).build();
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable HTTP so we can test retries on reindex from remote; in this case the "remote" cluster is just this cluster
}
final Settings nodeSettings() {
return Settings.builder()
// enable HTTP so we can test retries on reindex from remote; in this case the "remote" cluster is just this cluster
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
// whitelist reindexing from the HTTP host we're going to use
.put(TransportReindexAction.REMOTE_CLUSTER_WHITELIST.getKey(), "127.0.0.1:*")
.build();

View File

@ -50,11 +50,15 @@ public class Netty4HttpRequestSizeLimitIT extends ESNetty4IntegTestCase {
private static final ByteSizeValue LIMIT = new ByteSizeValue(2, ByteSizeUnit.KB);
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), LIMIT)
.build();
}

View File

@ -38,11 +38,15 @@ import static org.hamcrest.Matchers.hasSize;
@ClusterScope(scope = Scope.TEST, supportsDedicatedMasters = false, numDataNodes = 1)
public class Netty4PipeliningDisabledIT extends ESNetty4IntegTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("http.pipelining", false)
.build();
}

View File

@ -37,11 +37,15 @@ import static org.hamcrest.Matchers.is;
@ClusterScope(scope = Scope.TEST, supportsDedicatedMasters = false, numDataNodes = 1)
public class Netty4PipeliningEnabledIT extends ESNetty4IntegTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("http.pipelining", true)
.build();
}

View File

@ -90,7 +90,6 @@ public class ContextAndHeaderTransportIT extends HttpSmokeTestCase {
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}

View File

@ -49,7 +49,6 @@ public class CorsRegexIT extends HttpSmokeTestCase {
.put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true)
.put(SETTING_CORS_ALLOW_METHODS.getKey(), "get, options, post")
.put(SETTING_CORS_ENABLED.getKey(), true)
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}

View File

@ -57,11 +57,15 @@ import static org.hamcrest.Matchers.hasSize;
*/
public class DeprecationHttpIT extends HttpSmokeTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("force.http.enabled", true)
// change values of deprecated settings so that accessing them is logged
.put(TEST_DEPRECATED_SETTING_TRUE1.getKey(), ! TEST_DEPRECATED_SETTING_TRUE1.getDefault(Settings.EMPTY))
.put(TEST_DEPRECATED_SETTING_TRUE2.getKey(), ! TEST_DEPRECATED_SETTING_TRUE2.getDefault(Settings.EMPTY))

View File

@ -38,12 +38,12 @@ import static org.hamcrest.Matchers.is;
*/
@ClusterScope(scope = Scope.TEST, supportsDedicatedMasters = false, numDataNodes = 1)
public class DetailedErrorsDisabledIT extends HttpSmokeTestCase {
// Build our cluster settings
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED.getKey(), false)
.build();
}

View File

@ -55,13 +55,17 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
}
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.TRANSPORT_TYPE_KEY, nodeTransportTypeKey)
.put(NetworkModule.HTTP_TYPE_KEY, nodeHttpTypeKey)
.put(NetworkModule.HTTP_ENABLED.getKey(), true).build();
.put(NetworkModule.HTTP_TYPE_KEY, nodeHttpTypeKey).build();
}
@Override

View File

@ -37,12 +37,10 @@ import static org.hamcrest.Matchers.equalTo;
*/
@ClusterScope(scope = Scope.SUITE, supportsDedicatedMasters = false, numDataNodes = 1)
public class ResponseHeaderPluginIT extends HttpSmokeTestCase {
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("force.http.enabled", true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -71,8 +71,6 @@ public final class NetworkModule {
Property.NodeScope);
public static final Setting<String> HTTP_DEFAULT_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_DEFAULT_KEY, Property.NodeScope);
public static final Setting<String> HTTP_TYPE_SETTING = Setting.simpleString(HTTP_TYPE_KEY, Property.NodeScope);
public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true,
Property.NodeScope, Property.Deprecated);
public static final Setting<String> TRANSPORT_TYPE_SETTING = Setting.simpleString(TRANSPORT_TYPE_KEY, Property.NodeScope);
private final Settings settings;
@ -117,9 +115,9 @@ public final class NetworkModule {
this.settings = settings;
this.transportClient = transportClient;
for (NetworkPlugin plugin : plugins) {
if (transportClient == false && HTTP_ENABLED.get(settings)) {
Map<String, Supplier<HttpServerTransport>> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays,
circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService, dispatcher);
Map<String, Supplier<HttpServerTransport>> httpTransportFactory = plugin.getHttpTransports(settings, threadPool, bigArrays,
circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService, dispatcher);
if (transportClient == false) {
for (Map.Entry<String, Supplier<HttpServerTransport>> entry : httpTransportFactory.entrySet()) {
registerHttpTransport(entry.getKey(), entry.getValue());
}
@ -197,10 +195,6 @@ public final class NetworkModule {
return factory;
}
public boolean isHttpEnabled() {
return transportClient == false && HTTP_ENABLED.get(settings);
}
public Supplier<Transport> getTransportSupplier() {
final String name;
if (TRANSPORT_TYPE_SETTING.exists(settings)) {

View File

@ -219,7 +219,6 @@ public final class ClusterSettings extends AbstractScopedSettings {
GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING,
GatewayService.RECOVER_AFTER_NODES_SETTING,
GatewayService.RECOVER_AFTER_TIME_SETTING,
NetworkModule.HTTP_ENABLED,
NetworkModule.HTTP_DEFAULT_TYPE_SETTING,
NetworkModule.TRANSPORT_DEFAULT_TYPE_SETTING,
NetworkModule.HTTP_TYPE_SETTING,

View File

@ -440,19 +440,7 @@ public class Node implements Closeable {
final ResponseCollectorService responseCollectorService = new ResponseCollectorService(this.settings, clusterService);
final SearchTransportService searchTransportService = new SearchTransportService(settings, transportService,
SearchExecutionStatsCollector.makeWrapper(responseCollectorService));
final Consumer<Binder> httpBind;
final HttpServerTransport httpServerTransport;
if (networkModule.isHttpEnabled()) {
httpServerTransport = networkModule.getHttpServerTransportSupplier().get();
httpBind = b -> {
b.bind(HttpServerTransport.class).toInstance(httpServerTransport);
};
} else {
httpBind = b -> {
b.bind(HttpServerTransport.class).toProvider(Providers.of(null));
};
httpServerTransport = null;
}
final HttpServerTransport httpServerTransport = newHttpTransport(networkModule);
final DiscoveryModule discoveryModule = new DiscoveryModule(this.settings, threadPool, transportService, namedWriteableRegistry,
networkService, clusterService.getMasterService(), clusterService.getClusterApplierService(),
@ -519,7 +507,7 @@ public class Node implements Closeable {
b.bind(PeerRecoveryTargetService.class).toInstance(new PeerRecoveryTargetService(settings, threadPool,
transportService, recoverySettings, clusterService));
}
httpBind.accept(b);
b.bind(HttpServerTransport.class).toInstance(httpServerTransport);
pluginComponents.stream().forEach(p -> b.bind((Class) p.getClass()).toInstance(p));
b.bind(PersistentTasksService.class).toInstance(persistentTasksService);
b.bind(PersistentTasksClusterService.class).toInstance(persistentTasksClusterService);
@ -541,10 +529,8 @@ public class Node implements Closeable {
client.initialize(injector.getInstance(new Key<Map<GenericAction, TransportAction>>() {}),
() -> clusterService.localNode().getId(), transportService.getRemoteClusterService());
if (NetworkModule.HTTP_ENABLED.get(settings)) {
logger.debug("initializing HTTP handlers ...");
actionModule.initRestHandlers(() -> clusterService.state().nodes());
}
logger.debug("initializing HTTP handlers ...");
actionModule.initRestHandlers(() -> clusterService.state().nodes());
logger.info("initialized");
success = true;
@ -704,18 +690,13 @@ public class Node implements Closeable {
}
}
if (NetworkModule.HTTP_ENABLED.get(settings)) {
injector.getInstance(HttpServerTransport.class).start();
}
injector.getInstance(HttpServerTransport.class).start();
if (WRITE_PORTS_FILE_SETTING.get(settings)) {
if (NetworkModule.HTTP_ENABLED.get(settings)) {
HttpServerTransport http = injector.getInstance(HttpServerTransport.class);
writePortsFile("http", http.boundAddress());
}
TransportService transport = injector.getInstance(TransportService.class);
writePortsFile("transport", transport.boundAddress());
HttpServerTransport http = injector.getInstance(HttpServerTransport.class);
writePortsFile("http", http.boundAddress());
}
logger.info("started");
@ -733,9 +714,7 @@ public class Node implements Closeable {
logger.info("stopping ...");
injector.getInstance(ResourceWatcherService.class).stop();
if (NetworkModule.HTTP_ENABLED.get(settings)) {
injector.getInstance(HttpServerTransport.class).stop();
}
injector.getInstance(HttpServerTransport.class).stop();
injector.getInstance(SnapshotsService.class).stop();
injector.getInstance(SnapshotShardsService.class).stop();
@ -781,9 +760,7 @@ public class Node implements Closeable {
toClose.add(() -> stopWatch.start("node_service"));
toClose.add(nodeService);
toClose.add(() -> stopWatch.stop().start("http"));
if (NetworkModule.HTTP_ENABLED.get(settings)) {
toClose.add(injector.getInstance(HttpServerTransport.class));
}
toClose.add(injector.getInstance(HttpServerTransport.class));
toClose.add(() -> stopWatch.stop().start("snapshot_service"));
toClose.add(injector.getInstance(SnapshotsService.class));
toClose.add(injector.getInstance(SnapshotShardsService.class));
@ -963,6 +940,11 @@ public class Node implements Closeable {
return new InternalClusterInfoService(settings, clusterService, threadPool, client, listeners);
}
/** Constructs a {@link org.elasticsearch.http.HttpServerTransport} which may be mocked for tests. */
protected HttpServerTransport newHttpTransport(NetworkModule networkModule) {
return networkModule.getHttpServerTransportSupplier().get();
}
private static class LocalNodeFactory implements Function<BoundTransportAddress, DiscoveryNode> {
private final SetOnce<DiscoveryNode> localNode = new SetOnce<>();
private final String persistentNodeId;

View File

@ -32,6 +32,7 @@ import org.elasticsearch.node.NodeValidationException;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.discovery.TestZenDiscovery;
import org.elasticsearch.transport.MockTransportClient;
import org.elasticsearch.transport.TransportService;
@ -62,10 +63,10 @@ public class TransportClientIT extends ESIntegTestCase {
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put("node.name", "testNodeVersionIsUpdated")
.put("transport.type", getTestTransportType())
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(Node.NODE_DATA_SETTING.getKey(), false)
.put("cluster.name", "foobar")
.build(), Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class)).start()) {
.build(), Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class,
MockHttpTransport.TestPlugin.class)).start()) {
TransportAddress transportAddress = node.injector().getInstance(TransportService.class).boundAddress().publishAddress();
client.addTransportAddress(transportAddress);
// since we force transport clients there has to be one node started that we connect to.

View File

@ -24,7 +24,6 @@ import org.elasticsearch.common.Table;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.ModuleTestCase;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.util.BigArrays;
@ -128,9 +127,7 @@ public class NetworkModuleTests extends ModuleTestCase {
}
public void testRegisterTransport() {
Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom")
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.build();
Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom").build();
Supplier<Transport> custom = () -> null; // content doesn't matter we check reference equality
NetworkPlugin plugin = new NetworkPlugin() {
@Override
@ -144,15 +141,12 @@ public class NetworkModuleTests extends ModuleTestCase {
};
NetworkModule module = newNetworkModule(settings, false, plugin);
assertFalse(module.isTransportClient());
assertFalse(module.isHttpEnabled());
assertSame(custom, module.getTransportSupplier());
// check it works with transport only as well
module = newNetworkModule(settings, true, plugin);
assertSame(custom, module.getTransportSupplier());
assertTrue(module.isTransportClient());
assertFalse(module.isHttpEnabled());
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
public void testRegisterHttpTransport() {
@ -175,15 +169,11 @@ public class NetworkModuleTests extends ModuleTestCase {
});
assertSame(custom, module.getHttpServerTransportSupplier());
assertFalse(module.isTransportClient());
assertTrue(module.isHttpEnabled());
settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
NetworkModule newModule = newNetworkModule(settings, false);
assertFalse(newModule.isTransportClient());
assertFalse(newModule.isHttpEnabled());
expectThrows(IllegalStateException.class, () -> newModule.getHttpServerTransportSupplier());
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
public void testOverrideDefault() {
@ -261,7 +251,6 @@ public class NetworkModuleTests extends ModuleTestCase {
public void testRegisterInterceptor() {
Settings settings = Settings.builder()
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
AtomicInteger called = new AtomicInteger(0);
@ -309,7 +298,6 @@ public class NetworkModuleTests extends ModuleTestCase {
});
});
assertEquals("interceptor must not be null", nullPointerException.getMessage());
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
private NetworkModule newNetworkModule(Settings settings, boolean transportClient, NetworkPlugin... plugins) {

View File

@ -32,6 +32,7 @@ import org.elasticsearch.discovery.zen.UnicastZenPing;
import org.elasticsearch.discovery.zen.ZenPing;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.NodeConfigurationSource;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.threadpool.TestThreadPool;
@ -40,6 +41,7 @@ import org.elasticsearch.transport.TransportService;
import java.io.Closeable;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;
import java.util.concurrent.CompletableFuture;
@ -123,7 +125,6 @@ public class SingleNodeDiscoveryIT extends ESIntegTestCase {
return Settings
.builder()
.put("discovery.type", "single-node")
.put("http.enabled", false)
.put("transport.type", getTestTransportType())
/*
* We align the port ranges of the two as then with zen discovery these two
@ -151,7 +152,7 @@ public class SingleNodeDiscoveryIT extends ESIntegTestCase {
0,
false,
"other",
Collections.singletonList(getTestTransportPlugin()),
Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class),
Function.identity())) {
other.beforeTest(random(), 0);
final ClusterState first = internalCluster().getInstance(ClusterService.class).state();

View File

@ -32,10 +32,13 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockHttpTransport;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@ -55,7 +58,7 @@ public class NodeTests extends ESTestCase {
if (name != null) {
settings.put(Node.NODE_NAME_SETTING.getKey(), name);
}
try (Node node = new MockNode(settings.build(), Collections.singleton(getTestTransportPlugin()))) {
try (Node node = new MockNode(settings.build(), basePlugins())) {
final Settings nodeSettings = randomBoolean() ? node.settings() : node.getEnvironment().settings();
if (name == null) {
assertThat(Node.NODE_NAME_SETTING.get(nodeSettings), equalTo(node.getNodeEnvironment().nodeId().substring(0, 7)));
@ -63,7 +66,6 @@ public class NodeTests extends ESTestCase {
assertThat(Node.NODE_NAME_SETTING.get(nodeSettings), equalTo(name));
}
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
public static class CheckPlugin extends Plugin {
@ -75,6 +77,13 @@ public class NodeTests extends ESTestCase {
}
}
private List<Class<? extends Plugin>> basePlugins() {
List<Class<? extends Plugin>> plugins = new ArrayList<>();
plugins.add(getTestTransportPlugin());
plugins.add(MockHttpTransport.TestPlugin.class);
return plugins;
}
public void testLoadPluginBootstrapChecks() throws IOException {
final String name = randomBoolean() ? randomAlphaOfLength(10) : null;
Settings.Builder settings = baseSettings();
@ -82,7 +91,9 @@ public class NodeTests extends ESTestCase {
settings.put(Node.NODE_NAME_SETTING.getKey(), name);
}
AtomicBoolean executed = new AtomicBoolean(false);
try (Node node = new MockNode(settings.build(), Arrays.asList(getTestTransportPlugin(), CheckPlugin.class)) {
List<Class<? extends Plugin>> plugins = basePlugins();
plugins.add(CheckPlugin.class);
try (Node node = new MockNode(settings.build(), plugins) {
@Override
protected void validateNodeBeforeAcceptingRequests(BootstrapContext context, BoundTransportAddress boundTransportAddress,
List<BootstrapCheck> bootstrapChecks) throws NodeValidationException {
@ -95,7 +106,6 @@ public class NodeTests extends ESTestCase {
expectThrows(NodeValidationException.class, () -> node.start());
assertTrue(executed.get());
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
public void testWarnIfPreRelease() {
@ -125,7 +135,7 @@ public class NodeTests extends ESTestCase {
public void testNodeAttributes() throws IOException {
String attr = randomAlphaOfLength(5);
Settings.Builder settings = baseSettings().put(Node.NODE_ATTRIBUTES.getKey() + "test_attr", attr);
try (Node node = new MockNode(settings.build(), Collections.singleton(getTestTransportPlugin()))) {
try (Node node = new MockNode(settings.build(), basePlugins())) {
final Settings nodeSettings = randomBoolean() ? node.settings() : node.getEnvironment().settings();
assertEquals(attr, Node.NODE_ATTRIBUTES.getAsMap(nodeSettings).get("test_attr"));
}
@ -133,7 +143,7 @@ public class NodeTests extends ESTestCase {
// leading whitespace not allowed
attr = " leading";
settings = baseSettings().put(Node.NODE_ATTRIBUTES.getKey() + "test_attr", attr);
try (Node node = new MockNode(settings.build(), Collections.singleton(getTestTransportPlugin()))) {
try (Node node = new MockNode(settings.build(), basePlugins())) {
fail("should not allow a node attribute with leading whitespace");
} catch (IllegalArgumentException e) {
assertEquals("node.attr.test_attr cannot have leading or trailing whitespace [ leading]", e.getMessage());
@ -142,12 +152,11 @@ public class NodeTests extends ESTestCase {
// trailing whitespace not allowed
attr = "trailing ";
settings = baseSettings().put(Node.NODE_ATTRIBUTES.getKey() + "test_attr", attr);
try (Node node = new MockNode(settings.build(), Collections.singleton(getTestTransportPlugin()))) {
try (Node node = new MockNode(settings.build(), basePlugins())) {
fail("should not allow a node attribute with trailing whitespace");
} catch (IllegalArgumentException e) {
assertEquals("node.attr.test_attr cannot have leading or trailing whitespace [trailing ]", e.getMessage());
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
private static Settings.Builder baseSettings() {
@ -155,7 +164,6 @@ public class NodeTests extends ESTestCase {
return Settings.builder()
.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), InternalTestCluster.clusterName("single-node-cluster", randomLong()))
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType())
.put(Node.NODE_DATA_SETTING.getKey(), true);
}

View File

@ -1,43 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.node.service;
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest;
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESSingleNodeTestCase;
import static org.hamcrest.Matchers.hasSize;
public class NodeServiceTests extends ESSingleNodeTestCase {
@Override
protected Settings nodeSettings() {
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
}
public void testHttpServerDisabled() {
// test for a bug where if HTTP stats were requested but HTTP was disabled, NodeService would hit a NullPointerException
NodesStatsResponse response = client().admin().cluster().nodesStats(new NodesStatsRequest().http(true)).actionGet();
assertThat(response.getNodes(), hasSize(1));
}
}

View File

@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterInfoService;
import org.elasticsearch.cluster.MockInternalClusterInfoService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.BoundTransportAddress;
@ -33,6 +34,7 @@ import org.elasticsearch.common.util.MockBigArrays;
import org.elasticsearch.common.util.MockPageCacheRecycler;
import org.elasticsearch.common.util.PageCacheRecycler;
import org.elasticsearch.env.Environment;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.recovery.RecoverySettings;
@ -41,6 +43,7 @@ import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.MockSearchService;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.transport.MockTransportService;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.Transport;
@ -144,5 +147,14 @@ public class MockNode extends Node {
return new MockInternalClusterInfoService(settings, clusterService, threadPool, client, listener);
}
}
@Override
protected HttpServerTransport newHttpTransport(NetworkModule networkModule) {
if (getPluginsService().filterPlugins(MockHttpTransport.TestPlugin.class).isEmpty()) {
return super.newHttpTransport(networkModule);
} else {
return new MockHttpTransport();
}
}
}

View File

@ -1842,7 +1842,6 @@ public abstract class ESIntegTestCase extends ESTestCase {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(networkSettings.build())
.put(ESIntegTestCase.this.nodeSettings(nodeOrdinal)).build();
}
@ -1892,6 +1891,11 @@ public abstract class ESIntegTestCase extends ESTestCase {
return true;
}
/** Returns {@code true} iff this test cluster should use a dummy http transport */
protected boolean addMockHttpTransport() {
return true;
}
/**
* Returns a function that allows to wrap / filter all clients that are exposed by the test cluster. This is useful
* for debugging or request / response pre and post processing. It also allows to intercept all calls done by the test
@ -1928,10 +1932,12 @@ public abstract class ESIntegTestCase extends ESTestCase {
if (addMockTransportService()) {
mocks.add(getTestTransportPlugin());
}
if (addTestZenDiscovery()) {
mocks.add(TestZenDiscovery.TestPlugin.class);
}
if (addMockHttpTransport()) {
mocks.add(MockHttpTransport.TestPlugin.class);
}
mocks.add(TestSeedPlugin.class);
return Collections.unmodifiableList(mocks);
}

View File

@ -161,6 +161,11 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
return Settings.EMPTY;
}
/** True if a dummy http transport should be used, or false if the real http transport should be used. */
protected boolean addMockHttpTransport() {
return true;
}
private Node newNode() {
final Path tempDir = createTempDir();
Settings settings = Settings.builder()
@ -173,7 +178,6 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
.put("node.name", "node_s_0")
.put(ScriptService.SCRIPT_MAX_COMPILATIONS_RATE.getKey(), "1000/1m")
.put(EsExecutors.PROCESSORS_SETTING.getKey(), 1) // limit the number of threads created
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put("transport.type", getTestTransportType())
.put(Node.NODE_DATA_SETTING.getKey(), true)
.put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong())
@ -192,6 +196,9 @@ public abstract class ESSingleNodeTestCase extends ESTestCase {
plugins = new ArrayList<>(plugins);
plugins.add(TestZenDiscovery.TestPlugin.class);
}
if (addMockHttpTransport()) {
plugins.add(MockHttpTransport.TestPlugin.class);
}
Node build = new MockNode(settings, plugins);
try {
build.start();

View File

@ -0,0 +1,76 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.test;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.BoundTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.http.HttpInfo;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.http.HttpStats;
import org.elasticsearch.plugins.Plugin;
/**
* A dummy http transport used by tests when not wanting to actually bind to a real address.
*/
public class MockHttpTransport extends AbstractLifecycleComponent implements HttpServerTransport {
/**
* Marker plugin used by {@link org.elasticsearch.node.MockNode} to enable {@link MockHttpTransport}.
*/
public static class TestPlugin extends Plugin {}
// dummy address/info that can be read by code expecting objects from the relevant methods,
// but not actually used for a real connection
private static final TransportAddress DUMMY_TRANSPORT_ADDRESS = new TransportAddress(TransportAddress.META_ADDRESS, 0);
private static final BoundTransportAddress DUMMY_BOUND_ADDRESS = new BoundTransportAddress(
new TransportAddress[] { DUMMY_TRANSPORT_ADDRESS }, DUMMY_TRANSPORT_ADDRESS);
private static final HttpInfo DUMMY_HTTP_INFO = new HttpInfo(DUMMY_BOUND_ADDRESS, 0);
private static final HttpStats DUMMY_HTTP_STATS = new HttpStats(0, 0);
public MockHttpTransport() {
super(Settings.EMPTY);
}
@Override
protected void doStart() {}
@Override
protected void doStop() {}
@Override
protected void doClose() {}
@Override
public BoundTransportAddress boundAddress() {
return DUMMY_BOUND_ADDRESS;
}
@Override
public HttpInfo info() {
return DUMMY_HTTP_INFO;
}
@Override
public HttpStats stats() {
return DUMMY_HTTP_STATS;
}
}

View File

@ -137,7 +137,6 @@ public class ClusterDiscoveryConfiguration extends NodeConfigurationSource {
// we need to pin the node port & host so we'd know where to point things
builder.put(TcpTransport.PORT.getKey(), unicastHostPorts[nodeOrdinal]);
builder.put(TcpTransport.HOST.getKey(), IP_ADDR); // only bind on one IF we use v4 here by default
builder.put(NetworkModule.HTTP_ENABLED.getKey(), false);
for (int i = 0; i < unicastHostOrdinals.length; i++) {
unicastHosts[i] = IP_ADDR + ":" + (unicastHostPorts[unicastHostOrdinals[i]]);
}

View File

@ -29,6 +29,7 @@ import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.search.MockSearchService;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.MockHttpTransport;
import java.io.IOException;
import java.util.ArrayList;
@ -43,10 +44,10 @@ public class MockNodeTests extends ESTestCase {
Settings settings = Settings.builder() // All these are required or MockNode will fail to build.
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
.put("transport.type", getTestTransportType())
.put("http.enabled", false)
.build();
List<Class<? extends Plugin>> plugins = new ArrayList<>();
plugins.add(getTestTransportPlugin());
plugins.add(MockHttpTransport.TestPlugin.class);
boolean useMockBigArrays = randomBoolean();
boolean useMockSearchService = randomBoolean();
if (useMockBigArrays) {
@ -69,6 +70,5 @@ public class MockNodeTests extends ESTestCase {
assertSame(searchService.getClass(), SearchService.class);
}
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
}

View File

@ -34,6 +34,7 @@ import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.InternalTestCluster;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.NodeConfigurationSource;
import org.elasticsearch.test.discovery.TestZenDiscovery;
import org.elasticsearch.transport.TcpTransport;
@ -43,6 +44,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@ -72,6 +74,10 @@ import static org.hamcrest.Matchers.not;
@LuceneTestCase.SuppressFileSystems("ExtrasFS") // doesn't work with potential multi data path from test cluster yet
public class InternalTestClusterTests extends ESTestCase {
private static Collection<Class<? extends Plugin>> mockPlugins() {
return Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class, MockHttpTransport.TestPlugin.class);
}
public void testInitializiationIsConsistent() {
long clusterSeed = randomLong();
boolean masterNodes = randomBoolean();
@ -184,7 +190,6 @@ public class InternalTestClusterTests extends ESTestCase {
.put(
NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(),
2 * ((masterNodes ? InternalTestCluster.DEFAULT_HIGH_NUM_MASTER_NODES : 0) + maxNumDataNodes + numClientNodes))
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType());
if (autoManageMinMasterNodes == false) {
assert minNumDataNodes == maxNumDataNodes;
@ -210,17 +215,15 @@ public class InternalTestClusterTests extends ESTestCase {
String nodePrefix = "foobar";
Path baseDir = createTempDir();
final List<Class<? extends Plugin>> mockPlugins = Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class);
InternalTestCluster cluster0 = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
autoManageMinMasterNodes, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes,
enableHttpPipelining, nodePrefix, mockPlugins, Function.identity());
enableHttpPipelining, nodePrefix, mockPlugins(), Function.identity());
InternalTestCluster cluster1 = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
autoManageMinMasterNodes, minNumDataNodes, maxNumDataNodes, clusterName2, nodeConfigurationSource, numClientNodes,
enableHttpPipelining, nodePrefix, mockPlugins, Function.identity());
enableHttpPipelining, nodePrefix, mockPlugins(), Function.identity());
assertClusters(cluster0, cluster1, false);
long seed = randomLong();
boolean shouldAssertSettingsDeprecationsAndWarnings = false;
try {
{
Random random = new Random(seed);
@ -231,10 +234,6 @@ public class InternalTestClusterTests extends ESTestCase {
cluster1.beforeTest(random, random.nextDouble());
}
assertArrayEquals(cluster0.getNodeNames(), cluster1.getNodeNames());
if (cluster0.getNodeNames().length > 0) {
shouldAssertSettingsDeprecationsAndWarnings = true;
assertSettingDeprecationsAndWarnings(new Setting<?>[]{NetworkModule.HTTP_ENABLED});
}
Iterator<Client> iterator1 = cluster1.getClients().iterator();
for (Client client : cluster0.getClients()) {
assertTrue(iterator1.hasNext());
@ -247,9 +246,6 @@ public class InternalTestClusterTests extends ESTestCase {
cluster1.afterTest();
} finally {
IOUtils.close(cluster0, cluster1);
if (shouldAssertSettingsDeprecationsAndWarnings) {
assertSettingDeprecationsAndWarnings(new Setting<?>[]{NetworkModule.HTTP_ENABLED});
}
}
}
@ -265,7 +261,7 @@ public class InternalTestClusterTests extends ESTestCase {
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false)
return Settings.builder()
.put(
NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(),
2 + (masterNodes ? InternalTestCluster.DEFAULT_HIGH_NUM_MASTER_NODES : 0) + maxNumDataNodes + numClientNodes)
@ -289,8 +285,7 @@ public class InternalTestClusterTests extends ESTestCase {
Path baseDir = createTempDir();
InternalTestCluster cluster = new InternalTestCluster(clusterSeed, baseDir, masterNodes,
true, minNumDataNodes, maxNumDataNodes, clusterName1, nodeConfigurationSource, numClientNodes,
enableHttpPipelining, nodePrefix, Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class),
Function.identity());
enableHttpPipelining, nodePrefix, mockPlugins(), Function.identity());
try {
cluster.beforeTest(random(), 0.0);
final int originalMasterCount = cluster.numMasterNodes();
@ -355,7 +350,6 @@ public class InternalTestClusterTests extends ESTestCase {
} finally {
cluster.close();
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
private Path[] getNodePaths(InternalTestCluster cluster, String name) {
@ -378,7 +372,6 @@ public class InternalTestClusterTests extends ESTestCase {
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), numNodes)
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType())
.put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0)
// speedup join timeout as setting initial state timeout to 0 makes split
@ -397,7 +390,7 @@ public class InternalTestClusterTests extends ESTestCase {
return Settings.builder()
.put(NetworkModule.TRANSPORT_TYPE_KEY, transportClient).build();
}
}, 0, randomBoolean(), "", Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class), Function.identity());
}, 0, randomBoolean(), "", mockPlugins(), Function.identity());
cluster.beforeTest(random(), 0.0);
List<DiscoveryNode.Role> roles = new ArrayList<>();
for (int i = 0; i < numNodes; i++) {
@ -456,7 +449,6 @@ public class InternalTestClusterTests extends ESTestCase {
} finally {
cluster.close();
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
public void testTwoNodeCluster() throws Exception {
@ -464,7 +456,7 @@ public class InternalTestClusterTests extends ESTestCase {
NodeConfigurationSource nodeConfigurationSource = new NodeConfigurationSource() {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false)
return Settings.builder()
.put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2)
.put(NetworkModule.TRANSPORT_TYPE_KEY, getTestTransportType())
.build();
@ -486,7 +478,7 @@ public class InternalTestClusterTests extends ESTestCase {
Path baseDir = createTempDir();
InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, false, true, 2, 2,
"test", nodeConfigurationSource, 0, enableHttpPipelining, nodePrefix,
Arrays.asList(getTestTransportPlugin(), TestZenDiscovery.TestPlugin.class), Function.identity());
mockPlugins(), Function.identity());
try {
cluster.beforeTest(random(), 0.0);
assertMMNinNodeSetting(cluster, 2);
@ -516,6 +508,5 @@ public class InternalTestClusterTests extends ESTestCase {
} finally {
cluster.close();
}
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
}

View File

@ -89,8 +89,8 @@ You can set the following token service settings in
`xpack.security.authc.token.enabled`::
Set to `false` to disable the built-in token service. Defaults to `true` unless
`xpack.security.http.ssl.enabled` is `false` and `http.enabled` is `true`.
This prevents sniffing the token from a connection over plain http.
`xpack.security.http.ssl.enabled` is `false`. This prevents sniffing the token
from a connection over plain http.
`xpack.security.authc.token.timeout`::
The length of time that a token is valid for. By default this value is `20m` or

View File

@ -76,7 +76,7 @@ If you use {security} and the built-in token service is enabled, you must
configure your cluster to use SSL/TLS for the HTTP interface. HTTPS is required
in order to use the token service.
In particular, if `xpack.security.authc.token.enabled` and `http.enabled` are
In particular, if `xpack.security.authc.token.enabled` is
set to `true` in the `elasticsearch.yml` file, you must also set
`xpack.security.http.ssl.enabled` to `true`. For more information about these
settings, see <<security-settings>> and <<modules-http>>.

View File

@ -73,13 +73,8 @@ public class XPackSettings {
true, Setting.Property.NodeScope);
/** Setting for enabling or disabling the token service. Defaults to true */
public static final Setting<Boolean> TOKEN_SERVICE_ENABLED_SETTING = Setting.boolSetting("xpack.security.authc.token.enabled", (s) -> {
if (NetworkModule.HTTP_ENABLED.get(s)) {
return XPackSettings.HTTP_SSL_ENABLED.getRaw(s);
} else {
return Boolean.TRUE.toString();
}
}, Setting.Property.NodeScope);
public static final Setting<Boolean> TOKEN_SERVICE_ENABLED_SETTING = Setting.boolSetting("xpack.security.authc.token.enabled",
XPackSettings.HTTP_SSL_ENABLED::getRaw, Setting.Property.NodeScope);
/** Setting for enabling or disabling sql. Defaults to true. */
public static final Setting<Boolean> SQL_ENABLED = Setting.boolSetting("xpack.sql.enabled", true, Setting.Property.NodeScope);

View File

@ -27,12 +27,16 @@ public class LicenseServiceClusterNotRecoveredTests extends AbstractLicensesInte
return nodeSettingsBuilder(nodeOrdinal).build();
}
@Override
protected boolean addMockHttpTransport() {
return false;
}
private Settings.Builder nodeSettingsBuilder(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("node.data", true)
.put("resource.reload.interval.high", "500ms") // for license mode file watcher
.put(NetworkModule.HTTP_ENABLED.getKey(), true);
.put("resource.reload.interval.high", "500ms"); // for license mode file watcher
}
@Override

View File

@ -34,12 +34,16 @@ public class LicenseServiceClusterTests extends AbstractLicensesIntegrationTestC
return nodeSettingsBuilder(nodeOrdinal).build();
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
private Settings.Builder nodeSettingsBuilder(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("node.data", true)
.put("resource.reload.interval.high", "500ms") // for license mode file watcher
.put(NetworkModule.HTTP_ENABLED.getKey(), true);
.put("resource.reload.interval.high", "500ms"); // for license mode file watcher
}
@Override

View File

@ -28,13 +28,17 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
@ESIntegTestCase.ClusterScope(scope = SUITE)
public class StartBasicLicenseTests extends AbstractLicensesIntegrationTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("node.data", true)
.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic")
.put(NetworkModule.HTTP_ENABLED.getKey(), true).build();
.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic").build();
}
@Override

View File

@ -27,13 +27,17 @@ import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
@ESIntegTestCase.ClusterScope(scope = SUITE)
public class StartTrialLicenseTests extends AbstractLicensesIntegrationTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("node.data", true)
.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic")
.put(NetworkModule.HTTP_ENABLED.getKey(), true).build();
.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "basic").build();
}
@Override

View File

@ -24,6 +24,7 @@ import org.elasticsearch.indices.recovery.RecoveryState;
import org.elasticsearch.license.LicenseService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.discovery.TestZenDiscovery;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.ml.LocalStateMachineLearning;
@ -111,7 +112,7 @@ public abstract class BaseMlIntegTestCase extends ESIntegTestCase {
@Override
protected Collection<Class<? extends Plugin>> getMockPlugins() {
return Arrays.asList(TestZenDiscovery.TestPlugin.class, TestSeedPlugin.class);
return Arrays.asList(TestZenDiscovery.TestPlugin.class, TestSeedPlugin.class, MockHttpTransport.TestPlugin.class);
}
@Before

View File

@ -46,7 +46,6 @@ public abstract class LocalExporterIntegTestCase extends MonitoringIntegTestCase
.put("xpack.monitoring.exporters." + exporterName + ".enabled", false)
.put("xpack.monitoring.exporters." + exporterName + ".cluster_alerts.management.enabled", false)
.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false)
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.build();
}

View File

@ -19,10 +19,9 @@ final class TokenSSLBootstrapCheck implements BootstrapCheck {
@Override
public BootstrapCheckResult check(BootstrapContext context) {
final Boolean httpEnabled = NetworkModule.HTTP_ENABLED.get(context.settings);
final Boolean httpsEnabled = XPackSettings.HTTP_SSL_ENABLED.get(context.settings);
final Boolean tokenServiceEnabled = XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.get(context.settings);
if (httpEnabled && httpsEnabled == false && tokenServiceEnabled) {
if (httpsEnabled == false && tokenServiceEnabled) {
final String message = String.format(
Locale.ROOT,
"HTTPS is required in order to use the token service; "

View File

@ -32,11 +32,15 @@ import static org.hamcrest.Matchers.equalTo;
public class BulkUpdateTests extends SecurityIntegTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(XPackSettings.DLS_FLS_ENABLED.getKey(), randomBoolean())
.build();
}

View File

@ -174,11 +174,8 @@ public class ClearRealmsCacheTests extends SecurityIntegTestCase {
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -68,11 +68,8 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase {
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
public void testModifyingViaApiClearsCache() throws Exception {

View File

@ -56,10 +56,14 @@ public class ClusterPrivilegeTests extends AbstractPrivilegeTestCase {
repositoryLocation = null;
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings() {
return Settings.builder().put(super.nodeSettings())
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("path.repo", repositoryLocation)
.build();
}

View File

@ -120,10 +120,8 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase {
"index_a_role:u13\n";
@Override
protected Settings nodeSettings() {
return Settings.builder().put(super.nodeSettings())
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -104,10 +104,8 @@ public class LicensingTests extends SecurityIntegTestCase {
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -56,11 +56,8 @@ public abstract class NativeRealmIntegTestCase extends SecurityIntegTestCase {
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -25,11 +25,8 @@ import static org.hamcrest.Matchers.is;
public class SecurityPluginTests extends SecurityIntegTestCase {
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("http.enabled", true) //This test requires HTTP
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
public void testThatPluginIsLoaded() throws IOException {

View File

@ -19,11 +19,6 @@ public class TokenSSLBootsrapCheckTests extends ESTestCase {
assertFalse(new TokenSSLBootstrapCheck().check(new BootstrapContext(settings, null)).isFailure());
settings = Settings.builder()
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey(), true).build();
assertFalse(new TokenSSLBootstrapCheck().check(new BootstrapContext(settings, null)).isFailure());
settings = Settings.builder().put(XPackSettings.HTTP_SSL_ENABLED.getKey(), true).build();
assertFalse(new TokenSSLBootstrapCheck().check(new BootstrapContext(settings, null)).isFailure());
@ -35,13 +30,5 @@ public class TokenSSLBootsrapCheckTests extends ESTestCase {
.put(XPackSettings.HTTP_SSL_ENABLED.getKey(), false)
.put(XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey(), true).build();
assertTrue(new TokenSSLBootstrapCheck().check(new BootstrapContext(settings, null)).isFailure());
settings = Settings.builder()
.put(XPackSettings.HTTP_SSL_ENABLED.getKey(), false)
.put(XPackSettings.TOKEN_SERVICE_ENABLED_SETTING.getKey(), true)
.put(NetworkModule.HTTP_ENABLED.getKey(), false).build();
assertFalse(new TokenSSLBootstrapCheck().check(new BootstrapContext(settings, null)).isFailure());
assertSettingDeprecationsAndWarnings(new Setting<?>[] { NetworkModule.HTTP_ENABLED });
}
}

View File

@ -49,11 +49,15 @@ public class AuditTrailTests extends SecurityIntegTestCase {
private static final String ROLE_CAN_RUN_AS = "can_run_as";
private static final String ROLES = ROLE_CAN_RUN_AS + ":\n" + " run_as: [ '" + EXECUTE_USER + "' ]\n";
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("xpack.security.audit.enabled", true)
.put("xpack.security.audit.outputs", "index")
.putList("xpack.security.audit.index.events.include", "access_denied", "authentication_failed", "run_as_denied")

View File

@ -54,11 +54,8 @@ public class RunAsIntegTests extends SecurityIntegTestCase {
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -39,12 +39,16 @@ public class ESNativeMigrateToolTests extends NativeRealmIntegTestCase {
useSSL = randomBoolean();
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
logger.info("--> use SSL? {}", useSSL);
Settings s = Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("xpack.security.http.ssl.enabled", useSSL)
.build();
return s;

View File

@ -51,13 +51,17 @@ import static org.hamcrest.Matchers.is;
*/
public class PkiAuthenticationTests extends SecuritySingleNodeTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings() {
SSLClientAuth sslClientAuth = randomBoolean() ? SSLClientAuth.REQUIRED : SSLClientAuth.OPTIONAL;
Settings.Builder builder = Settings.builder()
.put(super.nodeSettings())
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("xpack.security.http.ssl.enabled", true)
.put("xpack.security.http.ssl.client_authentication", sslClientAuth)
.put("xpack.security.authc.realms.file.type", FileRealmSettings.TYPE)

View File

@ -41,12 +41,15 @@ public class PkiOptionalClientAuthTests extends SecuritySingleNodeTestCase {
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
protected Settings nodeSettings() {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
Settings.Builder builder = Settings.builder()
.put(super.nodeSettings())
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("xpack.security.http.ssl.enabled", true)
.put("xpack.security.http.ssl.client_authentication", SSLClientAuth.OPTIONAL)
.put("xpack.security.authc.realms.file.type", "file")

View File

@ -35,11 +35,14 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
anonymousEnabled = randomBoolean();
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
Settings.Builder builder = Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true);
Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
if (anonymousEnabled) {
builder.put(AnonymousUser.USERNAME_SETTING.getKey(), "anon")

View File

@ -16,6 +16,8 @@ import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.node.MockNode;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeValidationException;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.MockHttpTransport;
import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.test.SecuritySettingsSource;
import org.elasticsearch.test.SecuritySettingsSourceField;
@ -40,6 +42,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CountDownLatch;
import static org.elasticsearch.test.SecuritySettingsSource.addSSLSettingsForStore;
@ -114,12 +117,13 @@ public class ServerTransportFilterIntegrationTests extends SecurityIntegTestCase
.put("xpack.security.audit.enabled", false)
.put(XPackSettings.WATCHER_ENABLED.getKey(), false)
.put("path.home", home)
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(Node.NODE_MASTER_SETTING.getKey(), false)
.put(TestZenDiscovery.USE_MOCK_PINGS.getKey(), false);
//.put("xpack.ml.autodetect_process", false);
Collection<Class<? extends Plugin>> mockPlugins = Arrays.asList(
LocalStateSecurity.class, TestZenDiscovery.TestPlugin.class, MockHttpTransport.TestPlugin.class);
addSSLSettingsForStore(nodeSettings, "/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks", "testnode");
try (Node node = new MockNode(nodeSettings.build(), Arrays.asList(LocalStateSecurity.class, TestZenDiscovery.TestPlugin.class))) {
try (Node node = new MockNode(nodeSettings.build(), mockPlugins)) {
node.start();
ensureStableCluster(cluster().size() + 1);
}
@ -150,14 +154,15 @@ public class ServerTransportFilterIntegrationTests extends SecurityIntegTestCase
.put("xpack.security.enabled", true)
.put("xpack.security.audit.enabled", false)
.put(XPackSettings.WATCHER_ENABLED.getKey(), false)
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put("discovery.initial_state_timeout", "0s")
.put("path.home", home)
.put(Node.NODE_MASTER_SETTING.getKey(), false)
.put(TestZenDiscovery.USE_MOCK_PINGS.getKey(), false);
//.put("xpack.ml.autodetect_process", false);
Collection<Class<? extends Plugin>> mockPlugins = Arrays.asList(
LocalStateSecurity.class, TestZenDiscovery.TestPlugin.class, MockHttpTransport.TestPlugin.class);
addSSLSettingsForStore(nodeSettings, "/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks", "testnode");
try (Node node = new MockNode(nodeSettings.build(), Arrays.asList(LocalStateSecurity.class, TestZenDiscovery.TestPlugin.class))) {
try (Node node = new MockNode(nodeSettings.build(), mockPlugins)) {
node.start();
TransportService instance = node.injector().getInstance(TransportService.class);
try (Transport.Connection connection = instance.openConnection(new DiscoveryNode("theNode", transportAddress, Version.CURRENT),

View File

@ -37,11 +37,15 @@ public class IpFilteringIntegrationTests extends SecurityIntegTestCase {
randomClientPort = randomIntBetween(49000, 65500); // ephemeral port
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("transport.profiles.client.port", randomClientPortRange)
// make sure this is "localhost", no matter if ipv4 or ipv6, but be consistent
.put("transport.profiles.client.bind_host", "localhost")

View File

@ -34,12 +34,16 @@ public class IpFilteringUpdateTests extends SecurityIntegTestCase {
randomClientPort = randomIntBetween(49000, 65500);
}
@Override
protected boolean addMockHttpTransport() {
return httpEnabled == false;
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
String randomClientPortRange = randomClientPort + "-" + (randomClientPort+100);
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), httpEnabled)
.put("xpack.security.transport.filter.deny", "127.0.0.200")
.put("transport.profiles.client.port", randomClientPortRange)
.build();

View File

@ -47,10 +47,15 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
public class SslIntegrationTests extends SecurityIntegTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put("xpack.security.http.ssl.enabled", true).build();
}

View File

@ -22,11 +22,15 @@ import static org.hamcrest.Matchers.nullValue;
public class AnonymousUserIntegTests extends SecurityIntegTestCase {
private boolean authorizationExceptionsEnabled = randomBoolean();
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
public Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(AnonymousUser.ROLES_SETTING.getKey(), "anonymous")
.put(AuthorizationService.ANONYMOUS_AUTHORIZATION_EXCEPTION_SETTING.getKey(), authorizationExceptionsEnabled)
.build();

View File

@ -45,6 +45,12 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
public class SSLClientAuthTests extends SecurityIntegTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
@ -54,7 +60,6 @@ public class SSLClientAuthTests extends SecurityIntegTestCase {
.put("xpack.security.http.ssl.enabled", true)
.put("xpack.security.http.ssl.client_authentication", SSLClientAuth.REQUIRED)
.put("transport.profiles.default.xpack.security.ssl.client_authentication", SSLClientAuth.NONE)
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}

View File

@ -55,12 +55,16 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase {
return plugins;
}
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
// Enable http so we can test JDBC licensing because only exists on the REST layer.
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.put(NetworkModule.HTTP_TYPE_KEY, Netty4Plugin.NETTY_HTTP_TRANSPORT_NAME)
.build();
}

View File

@ -49,8 +49,8 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase
private MockWebServer webServer = new MockWebServer();
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder().put(super.nodeSettings(nodeOrdinal)).put("http.enabled", true).build();
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override

View File

@ -36,11 +36,15 @@ import static org.hamcrest.Matchers.containsString;
public class ChainIntegrationTests extends AbstractWatcherIntegrationTestCase {
@Override
protected boolean addMockHttpTransport() {
return false; // enable http
}
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(NetworkModule.HTTP_ENABLED.getKey(), true)
.build();
}