Skip to content

Commit

Permalink
IGNITE-23459 Add сщтÑconsole input password if --user argument presen…
Browse files Browse the repository at this point in the history
…ted for ./control.sh
  • Loading branch information
Положаев Денис Александрович committed Oct 17, 2024
1 parent 15c7d74 commit a639fe9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,10 @@ private String argumentsToString(List<String> rawArgs) {
clientCfg.setServers(Collections.singletonList(args.host() + ":" + args.port()));

if (!F.isEmpty(userName))
clientCfg.setSecurityCredentialsProvider(getSecurityCredentialsProvider(userName, password, clientCfg));
clientCfg.setSecurityCredentialsProvider(getSecurityCredentialsProvider(
userName,
F.isEmpty(password) ? new String(requestPasswordFromConsole("password: ")) : password,
clientCfg));

if (!F.isEmpty(args.sslKeyStorePath()) || !F.isEmpty(args.sslFactoryConfigPath())) {
if (!F.isEmpty(args.sslKeyStorePath()) && !F.isEmpty(args.sslFactoryConfigPath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,41 @@ public void testConnector() throws Exception {
assertContains(log, testOutput, "--keystore-password *****");
assertContains(log, testOutput, "--truststore-password *****");
}

/**
* Verify that the command work correctly when entering password
* for user, and that it is requested only once.
*
* @throws Exception If failed.
*/
@Test
public void testInputKeyUserPwdOnlyOnce() throws Exception {
IgniteEx crd = startGrid();

crd.cluster().state(ACTIVE);

TestCommandHandler hnd = newCommandHandler();

AtomicInteger pwdCnt = new AtomicInteger();

((CommandHandler)GridTestUtils.getFieldValue(hnd, "hnd")).console = new NoopConsole() {
/** {@inheritDoc} */
@Override public char[] readPassword(String fmt, Object... args) {
pwdCnt.incrementAndGet();

return pwd.toCharArray();
}
};

int exitCode = hnd.execute(Arrays.asList(
"--state",
"--user", login,
"--keystore", keyStorePath("connectorClient"),
"--keystore-password", keyStorePassword(),
"--truststore", keyStorePath("trustthree"),
"--truststore-password", keyStorePassword()));

assertEquals(EXIT_CODE_OK, exitCode);
assertEquals(1, pwdCnt.get());
}
}

0 comments on commit a639fe9

Please sign in to comment.