|
@@ -20,11 +20,9 @@
|
|
|
package org.elasticsearch.action.admin;
|
|
|
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
-import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
import org.elasticsearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsResponse;
|
|
|
import org.elasticsearch.common.settings.KeyStoreWrapper;
|
|
|
import org.elasticsearch.common.settings.SecureSettings;
|
|
|
-import org.elasticsearch.common.settings.SecureString;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.env.Environment;
|
|
|
import org.elasticsearch.plugins.Plugin;
|
|
@@ -44,11 +42,11 @@ import java.util.Map;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.notNullValue;
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
-import static org.hamcrest.Matchers.instanceOf;
|
|
|
-import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
|
public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
|
|
@@ -62,7 +60,7 @@ public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
Files.deleteIfExists(KeyStoreWrapper.keystorePath(environment.configFile()));
|
|
|
final int initialReloadCount = mockReloadablePlugin.getReloadCount();
|
|
|
final CountDownLatch latch = new CountDownLatch(1);
|
|
|
- client().admin().cluster().prepareReloadSecureSettings().setSecureStorePassword(new SecureString(new char[0])).execute(
|
|
|
+ client().admin().cluster().prepareReloadSecureSettings().execute(
|
|
|
new ActionListener<NodesReloadSecureSettingsResponse>() {
|
|
|
@Override
|
|
|
public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
|
|
@@ -96,44 +94,6 @@ public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
assertThat(mockReloadablePlugin.getReloadCount(), equalTo(initialReloadCount));
|
|
|
}
|
|
|
|
|
|
- public void testNullKeystorePassword() throws Exception {
|
|
|
- final PluginsService pluginsService = internalCluster().getInstance(PluginsService.class);
|
|
|
- final MockReloadablePlugin mockReloadablePlugin = pluginsService.filterPlugins(MockReloadablePlugin.class)
|
|
|
- .stream().findFirst().get();
|
|
|
- final AtomicReference<AssertionError> reloadSettingsError = new AtomicReference<>();
|
|
|
- final int initialReloadCount = mockReloadablePlugin.getReloadCount();
|
|
|
- final CountDownLatch latch = new CountDownLatch(1);
|
|
|
- client().admin().cluster().prepareReloadSecureSettings().execute(
|
|
|
- new ActionListener<NodesReloadSecureSettingsResponse>() {
|
|
|
- @Override
|
|
|
- public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
|
|
|
- try {
|
|
|
- reloadSettingsError.set(new AssertionError("Null keystore password should fail"));
|
|
|
- } finally {
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFailure(Exception e) {
|
|
|
- try {
|
|
|
- assertThat(e, instanceOf(ActionRequestValidationException.class));
|
|
|
- assertThat(e.getMessage(), containsString("secure settings password cannot be null"));
|
|
|
- } catch (final AssertionError ae) {
|
|
|
- reloadSettingsError.set(ae);
|
|
|
- } finally {
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- latch.await();
|
|
|
- if (reloadSettingsError.get() != null) {
|
|
|
- throw reloadSettingsError.get();
|
|
|
- }
|
|
|
- // in the null password case no reload should be triggered
|
|
|
- assertThat(mockReloadablePlugin.getReloadCount(), equalTo(initialReloadCount));
|
|
|
- }
|
|
|
-
|
|
|
public void testInvalidKeystoreFile() throws Exception {
|
|
|
final PluginsService pluginsService = internalCluster().getInstance(PluginsService.class);
|
|
|
final MockReloadablePlugin mockReloadablePlugin = pluginsService.filterPlugins(MockReloadablePlugin.class)
|
|
@@ -149,7 +109,7 @@ public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
Files.copy(keystore, KeyStoreWrapper.keystorePath(environment.configFile()), StandardCopyOption.REPLACE_EXISTING);
|
|
|
}
|
|
|
final CountDownLatch latch = new CountDownLatch(1);
|
|
|
- client().admin().cluster().prepareReloadSecureSettings().setSecureStorePassword(new SecureString(new char[0])).execute(
|
|
|
+ client().admin().cluster().prepareReloadSecureSettings().execute(
|
|
|
new ActionListener<NodesReloadSecureSettingsResponse>() {
|
|
|
@Override
|
|
|
public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
|
|
@@ -181,52 +141,6 @@ public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
assertThat(mockReloadablePlugin.getReloadCount(), equalTo(initialReloadCount));
|
|
|
}
|
|
|
|
|
|
- public void testWrongKeystorePassword() throws Exception {
|
|
|
- final PluginsService pluginsService = internalCluster().getInstance(PluginsService.class);
|
|
|
- final MockReloadablePlugin mockReloadablePlugin = pluginsService.filterPlugins(MockReloadablePlugin.class)
|
|
|
- .stream().findFirst().get();
|
|
|
- final Environment environment = internalCluster().getInstance(Environment.class);
|
|
|
- final AtomicReference<AssertionError> reloadSettingsError = new AtomicReference<>();
|
|
|
- final int initialReloadCount = mockReloadablePlugin.getReloadCount();
|
|
|
- // "some" keystore should be present in this case
|
|
|
- writeEmptyKeystore(environment, new char[0]);
|
|
|
- final CountDownLatch latch = new CountDownLatch(1);
|
|
|
- client().admin()
|
|
|
- .cluster()
|
|
|
- .prepareReloadSecureSettings()
|
|
|
- .setSecureStorePassword(new SecureString(new char[] { 'W', 'r', 'o', 'n', 'g' }))
|
|
|
- .execute(new ActionListener<NodesReloadSecureSettingsResponse>() {
|
|
|
- @Override
|
|
|
- public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
|
|
|
- try {
|
|
|
- assertThat(nodesReloadResponse, notNullValue());
|
|
|
- final Map<String, NodesReloadSecureSettingsResponse.NodeResponse> nodesMap = nodesReloadResponse.getNodesMap();
|
|
|
- assertThat(nodesMap.size(), equalTo(cluster().size()));
|
|
|
- for (final NodesReloadSecureSettingsResponse.NodeResponse nodeResponse : nodesReloadResponse.getNodes()) {
|
|
|
- assertThat(nodeResponse.reloadException(), notNullValue());
|
|
|
- assertThat(nodeResponse.reloadException(), instanceOf(SecurityException.class));
|
|
|
- }
|
|
|
- } catch (final AssertionError e) {
|
|
|
- reloadSettingsError.set(e);
|
|
|
- } finally {
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFailure(Exception e) {
|
|
|
- reloadSettingsError.set(new AssertionError("Nodes request failed", e));
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
- });
|
|
|
- latch.await();
|
|
|
- if (reloadSettingsError.get() != null) {
|
|
|
- throw reloadSettingsError.get();
|
|
|
- }
|
|
|
- // in the wrong password case no reload should be triggered
|
|
|
- assertThat(mockReloadablePlugin.getReloadCount(), equalTo(initialReloadCount));
|
|
|
- }
|
|
|
-
|
|
|
public void testMisbehavingPlugin() throws Exception {
|
|
|
final Environment environment = internalCluster().getInstance(Environment.class);
|
|
|
final PluginsService pluginsService = internalCluster().getInstance(PluginsService.class);
|
|
@@ -247,7 +161,7 @@ public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
.get(Settings.builder().put(environment.settings()).setSecureSettings(secureSettings).build())
|
|
|
.toString();
|
|
|
final CountDownLatch latch = new CountDownLatch(1);
|
|
|
- client().admin().cluster().prepareReloadSecureSettings().setSecureStorePassword(new SecureString(new char[0])).execute(
|
|
|
+ client().admin().cluster().prepareReloadSecureSettings().execute(
|
|
|
new ActionListener<NodesReloadSecureSettingsResponse>() {
|
|
|
@Override
|
|
|
public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
|
|
@@ -314,7 +228,7 @@ public class ReloadSecureSettingsIT extends ESIntegTestCase {
|
|
|
private void successfulReloadCall() throws InterruptedException {
|
|
|
final AtomicReference<AssertionError> reloadSettingsError = new AtomicReference<>();
|
|
|
final CountDownLatch latch = new CountDownLatch(1);
|
|
|
- client().admin().cluster().prepareReloadSecureSettings().setSecureStorePassword(new SecureString(new char[0])).execute(
|
|
|
+ client().admin().cluster().prepareReloadSecureSettings().execute(
|
|
|
new ActionListener<NodesReloadSecureSettingsResponse>() {
|
|
|
@Override
|
|
|
public void onResponse(NodesReloadSecureSettingsResponse nodesReloadResponse) {
|