Search in sources :

Example 1 with NoopConsole

use of org.apache.ignite.internal.commandline.NoopConsole in project ignite by apache.

the class GridCommandHandlerSslWithSecurityTest method testInputKeyTrustStorePwdOnlyOnce.

/**
 * Verify that the command work correctly when entering passwords for
 * keystore and truststore, and that these passwords are requested only
 * once.
 *
 * @throws Exception If failed.
 */
@Test
public void testInputKeyTrustStorePwdOnlyOnce() throws Exception {
    IgniteEx crd = startGrid();
    crd.cluster().state(ACTIVE);
    CommandHandler cmd = new CommandHandler();
    AtomicInteger keyStorePwdCnt = new AtomicInteger();
    AtomicInteger trustStorePwdCnt = new AtomicInteger();
    cmd.console = new NoopConsole() {

        /**
         * {@inheritDoc}
         */
        @Override
        public char[] readPassword(String fmt, Object... args) {
            if (fmt.contains("keystore")) {
                keyStorePwdCnt.incrementAndGet();
                return keyStorePassword().toCharArray();
            } else if (fmt.contains("truststore")) {
                trustStorePwdCnt.incrementAndGet();
                return keyStorePassword().toCharArray();
            }
            return pwd.toCharArray();
        }
    };
    List<String> args = new ArrayList<>();
    args.add(DEACTIVATE.text());
    args.add("--force");
    args.add("--yes");
    args.add("--user");
    args.add(login);
    args.add("--keystore");
    args.add(keyStorePath("connectorServer"));
    args.add("--truststore");
    args.add(keyStorePath("trustthree"));
    assertEquals(EXIT_CODE_OK, cmd.execute(args));
    assertEquals(1, keyStorePwdCnt.get());
    assertEquals(1, trustStorePwdCnt.get());
}
Also used : NoopConsole(org.apache.ignite.internal.commandline.NoopConsole) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ArrayList(java.util.ArrayList) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 CommandHandler (org.apache.ignite.internal.commandline.CommandHandler)1 NoopConsole (org.apache.ignite.internal.commandline.NoopConsole)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1