@@ -195,4 +195,88 @@ public void testConnector() throws Exception {
195
195
assertContains (log , testOutput , "--keystore-password *****" );
196
196
assertContains (log , testOutput , "--truststore-password *****" );
197
197
}
198
+
199
+ /**
200
+ * Verify that the command work correctly when request starts with the --password argument
201
+ * without value that invoke console password input for user, and that it is requested only once.
202
+ *
203
+ * @throws Exception If failed.
204
+ */
205
+ @ Test
206
+ public void testInputKeyUserPwdOnlyOncePwdArgStart () throws Exception {
207
+ performTest (Arrays .asList (
208
+ "--password" ,
209
+ "--state" ,
210
+ "--user" , login ,
211
+ "--keystore" , keyStorePath ("connectorClient" ),
212
+ "--keystore-password" , keyStorePassword (),
213
+ "--truststore" , keyStorePath ("trustthree" ),
214
+ "--truststore-password" , keyStorePassword ()));
215
+ }
216
+
217
+ /**
218
+ * Verify that the command work correctly when request contains the --password argument inside
219
+ * without value that invoke console password input for user, and that it is requested only once.
220
+ *
221
+ * @throws Exception If failed.
222
+ */
223
+ @ Test
224
+ public void testInputKeyUserPwdOnlyOncePwdArgMiddle () throws Exception {
225
+ performTest (Arrays .asList (
226
+ "--state" ,
227
+ "--user" , login ,
228
+ "--password" ,
229
+ "--keystore" , keyStorePath ("connectorClient" ),
230
+ "--keystore-password" , keyStorePassword (),
231
+ "--truststore" , keyStorePath ("trustthree" ),
232
+ "--truststore-password" , keyStorePassword ()));
233
+ }
234
+
235
+ /**
236
+ * Verify that the command work correctly when request ends with the --password argument
237
+ * without value that invoke console password input for user, and that it is requested only once.
238
+ *
239
+ * @throws Exception If failed.
240
+ */
241
+ @ Test
242
+ public void testInputKeyUserPwdOnlyOncePwdArgEnd () throws Exception {
243
+ performTest (Arrays .asList (
244
+ "--state" ,
245
+ "--user" , login ,
246
+ "--keystore" , keyStorePath ("connectorClient" ),
247
+ "--keystore-password" , keyStorePassword (),
248
+ "--truststore" , keyStorePath ("trustthree" ),
249
+ "--truststore-password" , keyStorePassword (),
250
+ "--password" ));
251
+ }
252
+
253
+ /**
254
+ * Perform the test with prepared List arguments
255
+ *
256
+ * @param args List of query arguments.
257
+ * @throws Exception If failed.
258
+ */
259
+ private void performTest (List <String > args ) throws Exception {
260
+ IgniteEx crd = startGrid ();
261
+
262
+ crd .cluster ().state (ACTIVE );
263
+
264
+ TestCommandHandler hnd = newCommandHandler ();
265
+
266
+ AtomicInteger pwdCnt = new AtomicInteger ();
267
+
268
+ ((CommandHandler )GridTestUtils .getFieldValue (hnd , "hnd" )).console = new NoopConsole () {
269
+ /** {@inheritDoc} */
270
+ @ Override public char [] readPassword (String fmt , Object ... args ) {
271
+ pwdCnt .incrementAndGet ();
272
+ log .info ("PASSWORD: " + pwd );
273
+ return pwd .toCharArray ();
274
+ }
275
+ };
276
+
277
+ int exitCode = hnd .execute (args );
278
+
279
+ assertEquals (EXIT_CODE_OK , exitCode );
280
+ assertEquals (1 , pwdCnt .get ());
281
+ }
198
282
}
0 commit comments