DenisPolo commented on code in PR #11604:
URL: https://github.com/apache/ignite/pull/11604#discussion_r1942181032
##########
modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java:
##########
@@ -200,4 +200,127 @@ public void testConnector() throws Exception {
assertContains(log, testOutput, "--keystore-password *****");
assertContains(log, testOutput, "--truststore-password *****");
}
+
+ /**
+ * Verify that the command work correctly when request starts with the
--password argument
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgStart() throws Exception {
+ performTest(Arrays.asList(
+ "--password",
+ "--state",
+ "--user", login,
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword()));
+ }
+
+ /**
+ * Verify that the command work correctly when request contains the
--password argument inside
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgMiddle() throws Exception {
+ performTest(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--password",
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword()));
+ }
+
+ /**
+ * Verify that the command work correctly when request ends with the
--password argument
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgEnd() throws Exception {
+ performTest(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword(),
+ "--password"));
+ }
+
+ /**
+ * Perform the test with prepared List arguments.
+ *
+ * @param args List of query arguments.
+ * @throws Exception If failed.
+ */
+ private void performTest(List<String> args) throws Exception {
+ IgniteEx crd = startGrid();
+
+ crd.cluster().state(ACTIVE);
+
+ TestCommandHandler hnd = newCommandHandler();
+
+ AtomicInteger pwdCnt = new AtomicInteger();
+
+ ((CommandHandler)GridTestUtils.getFieldValue(hnd, "hnd")).console =
new NoopConsole() {
+ @Override public char[] readPassword(String fmt, Object... args) {
+ pwdCnt.incrementAndGet();
+
+ return pwd.toCharArray();
+ }
+ };
+
+ int exitCode = hnd.execute(args);
+
+ assertEquals(EXIT_CODE_OK, exitCode);
+ assertEquals(1, pwdCnt.get());
+ }
+
+ /**
+ * Verify that the command work correctly when request few arguments
+ * without value that invoke console input.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyForFewRequestedArguments() throws Exception {
+ IgniteEx crd = startGrid();
+
+ crd.cluster().state(ACTIVE);
+
+ TestCommandHandler hnd = newCommandHandler();
+
+ AtomicInteger reqCnt = new AtomicInteger();
+
+ ((CommandHandler)GridTestUtils.getFieldValue(hnd, "hnd")).console =
new NoopConsole() {
+ @Override public char[] readPassword(String fmt, Object... args) {
+ reqCnt.incrementAndGet();
+ if (reqCnt.get() == 1)
+ return keyStorePassword().toCharArray();
+ else
+ return pwd.toCharArray();
+ }
+ };
+
+ int exitCode = hnd.execute(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--verbose",
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password",
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword(),
+ "--password"));
Review Comment:
Done
##########
modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java:
##########
@@ -200,4 +200,127 @@ public void testConnector() throws Exception {
assertContains(log, testOutput, "--keystore-password *****");
assertContains(log, testOutput, "--truststore-password *****");
}
+
+ /**
+ * Verify that the command work correctly when request starts with the
--password argument
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgStart() throws Exception {
+ performTest(Arrays.asList(
+ "--password",
+ "--state",
+ "--user", login,
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword()));
+ }
+
+ /**
+ * Verify that the command work correctly when request contains the
--password argument inside
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgMiddle() throws Exception {
+ performTest(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--password",
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword()));
+ }
+
+ /**
+ * Verify that the command work correctly when request ends with the
--password argument
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgEnd() throws Exception {
+ performTest(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword(),
+ "--password"));
Review Comment:
Done
##########
modules/control-utility/src/test/java/org/apache/ignite/internal/processors/security/GridCommandHandlerSslWithSecurityTest.java:
##########
@@ -200,4 +200,127 @@ public void testConnector() throws Exception {
assertContains(log, testOutput, "--keystore-password *****");
assertContains(log, testOutput, "--truststore-password *****");
}
+
+ /**
+ * Verify that the command work correctly when request starts with the
--password argument
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgStart() throws Exception {
+ performTest(Arrays.asList(
+ "--password",
+ "--state",
+ "--user", login,
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword()));
+ }
+
+ /**
+ * Verify that the command work correctly when request contains the
--password argument inside
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgMiddle() throws Exception {
+ performTest(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--password",
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword()));
+ }
+
+ /**
+ * Verify that the command work correctly when request ends with the
--password argument
+ * without value that invoke console password input for user, and that it
is requested only once.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyUserPwdOnlyOncePwdArgEnd() throws Exception {
+ performTest(Arrays.asList(
+ "--state",
+ "--user", login,
+ "--keystore", keyStorePath(CLI_CMD_HND.equals(commandHandler)
? "thinClient" : "connectorServer"),
+ "--keystore-password", keyStorePassword(),
+ "--truststore",
keyStorePath(CLI_CMD_HND.equals(commandHandler) ? "trusttwo" : "trustthree"),
+ "--truststore-password", keyStorePassword(),
+ "--password"));
+ }
+
+ /**
+ * Perform the test with prepared List arguments.
+ *
+ * @param args List of query arguments.
+ * @throws Exception If failed.
+ */
+ private void performTest(List<String> args) throws Exception {
+ IgniteEx crd = startGrid();
+
+ crd.cluster().state(ACTIVE);
+
+ TestCommandHandler hnd = newCommandHandler();
+
+ AtomicInteger pwdCnt = new AtomicInteger();
+
+ ((CommandHandler)GridTestUtils.getFieldValue(hnd, "hnd")).console =
new NoopConsole() {
+ @Override public char[] readPassword(String fmt, Object... args) {
+ pwdCnt.incrementAndGet();
+
+ return pwd.toCharArray();
+ }
+ };
+
+ int exitCode = hnd.execute(args);
+
+ assertEquals(EXIT_CODE_OK, exitCode);
+ assertEquals(1, pwdCnt.get());
+ }
+
+ /**
+ * Verify that the command work correctly when request few arguments
+ * without value that invoke console input.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testInputKeyForFewRequestedArguments() throws Exception {
+ IgniteEx crd = startGrid();
+
+ crd.cluster().state(ACTIVE);
+
+ TestCommandHandler hnd = newCommandHandler();
+
+ AtomicInteger reqCnt = new AtomicInteger();
+
+ ((CommandHandler)GridTestUtils.getFieldValue(hnd, "hnd")).console =
new NoopConsole() {
+ @Override public char[] readPassword(String fmt, Object... args) {
+ reqCnt.incrementAndGet();
+ if (reqCnt.get() == 1)
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]