mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
Fixed a bug where when shield is disabled it still replaced the transport
Closes elastic/elasticsearch#430 Original commit: elastic/x-pack-elasticsearch@422ba76d81
This commit is contained in:
parent
02c3601ac5
commit
08b33e8854
@ -28,7 +28,6 @@ public class ShieldModule extends AbstractShieldModule.Spawn {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Module> spawnModules(boolean clientMode) {
|
||||
// spawn needed parts in client mode
|
||||
|
@ -51,7 +51,9 @@ public class ShieldPlugin extends AbstractPlugin {
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends Module>> modules() {
|
||||
return ImmutableList.<Class<? extends Module>>of(ShieldModule.class);
|
||||
return enabled ?
|
||||
ImmutableList.<Class<? extends Module>>of(ShieldModule.class) :
|
||||
ImmutableList.<Class<? extends Module>>of();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.shield;
|
||||
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.shield.transport.SecuredTransportService;
|
||||
import org.elasticsearch.shield.transport.netty.NettySecuredTransport;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||
import org.elasticsearch.test.ShieldIntegrationTest;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.SUITE;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ClusterScope(scope = SUITE)
|
||||
public class ShieldPluginEnabledDisabledTests extends ShieldIntegrationTest {
|
||||
|
||||
private static boolean enabled;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
enabled = randomBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
logger.info("******* shield is " + (enabled ? "enabled" : "disabled"));
|
||||
return ImmutableSettings.settingsBuilder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put("shield.enabled", enabled)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings transportClientSettings() {
|
||||
return ImmutableSettings.settingsBuilder()
|
||||
.put(super.transportClientSettings())
|
||||
.put("shield.enabled", enabled)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test @SuppressWarnings("unchecked")
|
||||
public void testEnabledDisabled() throws Exception {
|
||||
for (TransportService service : internalCluster().getInstances(TransportService.class)) {
|
||||
Matcher matcher = instanceOf(SecuredTransportService.class);
|
||||
if (!enabled) {
|
||||
matcher = not(matcher);
|
||||
}
|
||||
assertThat(service, matcher);
|
||||
}
|
||||
for (Transport transport : internalCluster().getInstances(Transport.class)) {
|
||||
Matcher matcher = instanceOf(NettySecuredTransport.class);
|
||||
if (!enabled) {
|
||||
matcher = not(matcher);
|
||||
}
|
||||
assertThat(transport, matcher);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user