2020package org .elasticsearch .action .admin ;
2121
2222import org .elasticsearch .action .ActionListener ;
23- import org .elasticsearch .action .ActionRequestValidationException ;
2423import org .elasticsearch .action .admin .cluster .node .reload .NodesReloadSecureSettingsResponse ;
2524import org .elasticsearch .common .settings .KeyStoreWrapper ;
2625import org .elasticsearch .common .settings .SecureSettings ;
27- import org .elasticsearch .common .settings .SecureString ;
2826import org .elasticsearch .common .settings .Settings ;
2927import org .elasticsearch .env .Environment ;
3028import org .elasticsearch .plugins .Plugin ;
4442import java .util .concurrent .CountDownLatch ;
4543import java .util .concurrent .atomic .AtomicReference ;
4644
45+ import static org .hamcrest .Matchers .containsString ;
4746import static org .hamcrest .Matchers .equalTo ;
47+ import static org .hamcrest .Matchers .instanceOf ;
4848import static org .hamcrest .Matchers .notNullValue ;
4949import static org .hamcrest .Matchers .nullValue ;
50- import static org .hamcrest .Matchers .instanceOf ;
51- import static org .hamcrest .Matchers .containsString ;
5250
5351public class ReloadSecureSettingsIT extends ESIntegTestCase {
5452
@@ -62,7 +60,7 @@ public void testMissingKeystoreFile() throws Exception {
6260 Files .deleteIfExists (KeyStoreWrapper .keystorePath (environment .configFile ()));
6361 final int initialReloadCount = mockReloadablePlugin .getReloadCount ();
6462 final CountDownLatch latch = new CountDownLatch (1 );
65- client ().admin ().cluster ().prepareReloadSecureSettings ().setSecureStorePassword ( new SecureString ( new char [ 0 ])). execute (
63+ client ().admin ().cluster ().prepareReloadSecureSettings ().execute (
6664 new ActionListener <NodesReloadSecureSettingsResponse >() {
6765 @ Override
6866 public void onResponse (NodesReloadSecureSettingsResponse nodesReloadResponse ) {
@@ -96,44 +94,6 @@ public void onFailure(Exception e) {
9694 assertThat (mockReloadablePlugin .getReloadCount (), equalTo (initialReloadCount ));
9795 }
9896
99- public void testNullKeystorePassword () throws Exception {
100- final PluginsService pluginsService = internalCluster ().getInstance (PluginsService .class );
101- final MockReloadablePlugin mockReloadablePlugin = pluginsService .filterPlugins (MockReloadablePlugin .class )
102- .stream ().findFirst ().get ();
103- final AtomicReference <AssertionError > reloadSettingsError = new AtomicReference <>();
104- final int initialReloadCount = mockReloadablePlugin .getReloadCount ();
105- final CountDownLatch latch = new CountDownLatch (1 );
106- client ().admin ().cluster ().prepareReloadSecureSettings ().execute (
107- new ActionListener <NodesReloadSecureSettingsResponse >() {
108- @ Override
109- public void onResponse (NodesReloadSecureSettingsResponse nodesReloadResponse ) {
110- try {
111- reloadSettingsError .set (new AssertionError ("Null keystore password should fail" ));
112- } finally {
113- latch .countDown ();
114- }
115- }
116-
117- @ Override
118- public void onFailure (Exception e ) {
119- try {
120- assertThat (e , instanceOf (ActionRequestValidationException .class ));
121- assertThat (e .getMessage (), containsString ("secure settings password cannot be null" ));
122- } catch (final AssertionError ae ) {
123- reloadSettingsError .set (ae );
124- } finally {
125- latch .countDown ();
126- }
127- }
128- });
129- latch .await ();
130- if (reloadSettingsError .get () != null ) {
131- throw reloadSettingsError .get ();
132- }
133- // in the null password case no reload should be triggered
134- assertThat (mockReloadablePlugin .getReloadCount (), equalTo (initialReloadCount ));
135- }
136-
13797 public void testInvalidKeystoreFile () throws Exception {
13898 final PluginsService pluginsService = internalCluster ().getInstance (PluginsService .class );
13999 final MockReloadablePlugin mockReloadablePlugin = pluginsService .filterPlugins (MockReloadablePlugin .class )
@@ -149,7 +109,7 @@ public void testInvalidKeystoreFile() throws Exception {
149109 Files .copy (keystore , KeyStoreWrapper .keystorePath (environment .configFile ()), StandardCopyOption .REPLACE_EXISTING );
150110 }
151111 final CountDownLatch latch = new CountDownLatch (1 );
152- client ().admin ().cluster ().prepareReloadSecureSettings ().setSecureStorePassword ( new SecureString ( new char [ 0 ])). execute (
112+ client ().admin ().cluster ().prepareReloadSecureSettings ().execute (
153113 new ActionListener <NodesReloadSecureSettingsResponse >() {
154114 @ Override
155115 public void onResponse (NodesReloadSecureSettingsResponse nodesReloadResponse ) {
@@ -181,52 +141,6 @@ public void onFailure(Exception e) {
181141 assertThat (mockReloadablePlugin .getReloadCount (), equalTo (initialReloadCount ));
182142 }
183143
184- public void testWrongKeystorePassword () throws Exception {
185- final PluginsService pluginsService = internalCluster ().getInstance (PluginsService .class );
186- final MockReloadablePlugin mockReloadablePlugin = pluginsService .filterPlugins (MockReloadablePlugin .class )
187- .stream ().findFirst ().get ();
188- final Environment environment = internalCluster ().getInstance (Environment .class );
189- final AtomicReference <AssertionError > reloadSettingsError = new AtomicReference <>();
190- final int initialReloadCount = mockReloadablePlugin .getReloadCount ();
191- // "some" keystore should be present in this case
192- writeEmptyKeystore (environment , new char [0 ]);
193- final CountDownLatch latch = new CountDownLatch (1 );
194- client ().admin ()
195- .cluster ()
196- .prepareReloadSecureSettings ()
197- .setSecureStorePassword (new SecureString (new char [] { 'W' , 'r' , 'o' , 'n' , 'g' }))
198- .execute (new ActionListener <NodesReloadSecureSettingsResponse >() {
199- @ Override
200- public void onResponse (NodesReloadSecureSettingsResponse nodesReloadResponse ) {
201- try {
202- assertThat (nodesReloadResponse , notNullValue ());
203- final Map <String , NodesReloadSecureSettingsResponse .NodeResponse > nodesMap = nodesReloadResponse .getNodesMap ();
204- assertThat (nodesMap .size (), equalTo (cluster ().size ()));
205- for (final NodesReloadSecureSettingsResponse .NodeResponse nodeResponse : nodesReloadResponse .getNodes ()) {
206- assertThat (nodeResponse .reloadException (), notNullValue ());
207- assertThat (nodeResponse .reloadException (), instanceOf (SecurityException .class ));
208- }
209- } catch (final AssertionError e ) {
210- reloadSettingsError .set (e );
211- } finally {
212- latch .countDown ();
213- }
214- }
215-
216- @ Override
217- public void onFailure (Exception e ) {
218- reloadSettingsError .set (new AssertionError ("Nodes request failed" , e ));
219- latch .countDown ();
220- }
221- });
222- latch .await ();
223- if (reloadSettingsError .get () != null ) {
224- throw reloadSettingsError .get ();
225- }
226- // in the wrong password case no reload should be triggered
227- assertThat (mockReloadablePlugin .getReloadCount (), equalTo (initialReloadCount ));
228- }
229-
230144 public void testMisbehavingPlugin () throws Exception {
231145 final Environment environment = internalCluster ().getInstance (Environment .class );
232146 final PluginsService pluginsService = internalCluster ().getInstance (PluginsService .class );
@@ -247,7 +161,7 @@ public void testMisbehavingPlugin() throws Exception {
247161 .get (Settings .builder ().put (environment .settings ()).setSecureSettings (secureSettings ).build ())
248162 .toString ();
249163 final CountDownLatch latch = new CountDownLatch (1 );
250- client ().admin ().cluster ().prepareReloadSecureSettings ().setSecureStorePassword ( new SecureString ( new char [ 0 ])). execute (
164+ client ().admin ().cluster ().prepareReloadSecureSettings ().execute (
251165 new ActionListener <NodesReloadSecureSettingsResponse >() {
252166 @ Override
253167 public void onResponse (NodesReloadSecureSettingsResponse nodesReloadResponse ) {
@@ -314,7 +228,7 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
314228 private void successfulReloadCall () throws InterruptedException {
315229 final AtomicReference <AssertionError > reloadSettingsError = new AtomicReference <>();
316230 final CountDownLatch latch = new CountDownLatch (1 );
317- client ().admin ().cluster ().prepareReloadSecureSettings ().setSecureStorePassword ( new SecureString ( new char [ 0 ])). execute (
231+ client ().admin ().cluster ().prepareReloadSecureSettings ().execute (
318232 new ActionListener <NodesReloadSecureSettingsResponse >() {
319233 @ Override
320234 public void onResponse (NodesReloadSecureSettingsResponse nodesReloadResponse ) {
0 commit comments