nevdmitry commented on code in PR #2339:
URL: https://github.com/apache/ignite-3/pull/2339#discussion_r1270869442


##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/connect/ItConnectWithBasicAuthenticationCommandTest.java:
##########
@@ -99,4 +103,155 @@ void failToConnectWithWrongCredentials() {
         // And prompt is still disconnected
         assertThat(getPrompt()).isEqualTo("[disconnected]> ");
     }
+
+    @Test
+    @DisplayName("Should connect to cluster with username/password")
+    void connectWithAuthenticationParameters() {
+        // Given basic authentication is NOT configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTestsConfig());
+
+        // Given prompt before connect
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+
+        // When connect with auth parameters
+        //execute("connect", nodeName(), "--username", "admin1", "--password", 
"password1");
+
+        execute("connect", "--username", "admin", "--password", "password");
+
+        // Then
+        assertAll(
+                this::assertErrOutputIsEmpty,
+                () -> assertOutputContains("Connected to 
http://localhost:10300";)
+        );
+
+        // And prompt shows user name and node name
+        assertThat(getPrompt()).isEqualTo("[admin:" + nodeName() + "]> ");
+    }
+
+    @Test
+    @DisplayName("Should NOT connect to cluster with incorrect password")
+    void connectWithWrongAuthenticationParameters() {
+        // Given basic authentication is NOT configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTestsConfig());
+
+        // Given prompt before connect
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+
+        // When connect with auth parameters
+        execute("connect", "--username", "admin", "--password", 
"wrong-password");
+
+        // Then
+        assertAll(
+                this::assertOutputIsEmpty,
+                () -> assertErrOutputIs("Authentication error" + 
System.lineSeparator()
+                        + "Could not connect to node with URL 
http://localhost:10300. Check authentication configuration"
+                        + System.lineSeparator())
+        );
+        // And prompt is still disconnected
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+    }
+
+    @Test
+    void connectFailIfPasswordNotDefined() {
+        // Given basic authentication is NOT configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTestsConfig());
+
+        // Given prompt before connect
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+
+        // When connect with auth parameters
+        //execute("connect", nodeName(), "--username", "admin1", "--password", 
"password1");
+
+        execute("connect", "--username", "admin", "--password", "");
+
+        // Then
+        assertAll(
+                this::assertOutputIsEmpty,
+                () -> assertErrOutputIs("Authentication error" + 
System.lineSeparator()
+                        + "Could not connect to node with URL 
http://localhost:10300. Check authentication configuration"
+                        + System.lineSeparator())
+        );
+        // And prompt is still disconnected
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+    }
+
+    @Test
+    @DisplayName("Should connect to cluster with incorrect password in config 
but correct in command")
+    void connectWithWrongAuthenticationParametersInConfig() {
+        // Given basic authentication is configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTestsConfig(), 
createJdbcTestsBasicSecretConfig());
+        // And wrong password is in config
+        
configManagerProvider.configManager.setProperty(CliConfigKeys.Constants.BASIC_AUTHENTICATION_PASSWORD,
 "wrong-password");
+
+        // Given prompt before connect
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+
+        // When connect with auth parameters
+        execute("connect", "--username", "admin", "--password", "password");
+
+        // Then
+        assertAll(
+                this::assertErrOutputIsEmpty,
+                () -> assertOutputContains("Connected to 
http://localhost:10300";)
+        );
+
+        // And prompt shows user name and node name
+        assertThat(getPrompt()).isEqualTo("[admin:" + nodeName() + "]> ");
+    }
+
+    @Test
+    @DisplayName("Should restore initial values in config in case of connect 
failed")
+    void connectWithWrongAuthenticationParametersRestorePreviousCredentials() {
+        // Given basic authentication is configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTestsConfig(), 
createJdbcTestsBasicSecretConfig());
+
+        // Given prompt before connect
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+
+        // When connect with auth parameters
+        execute("connect", "--username", "admin", "--password", 
"wrong-password");
+
+        // Then
+        assertAll(
+                this::assertOutputIsEmpty,
+                () -> assertErrOutputIs("Authentication error" + 
System.lineSeparator()
+                        + "Could not connect to node with URL 
http://localhost:10300. Check authentication configuration"
+                        + System.lineSeparator())
+        );
+        // And prompt is still disconnected
+        assertThat(getPrompt()).isEqualTo("[disconnected]> ");
+        //Previous correct values restored in config
+        assertEquals("admin", 
configManagerProvider.get().getCurrentProperty(Constants.BASIC_AUTHENTICATION_USERNAME));
+        assertEquals("password", 
configManagerProvider.get().getCurrentProperty(Constants.BASIC_AUTHENTICATION_PASSWORD));
+    }
+
+    @Test
+    @DisplayName("Should ask to store credentials")
+    void shouldAskToStoreCredentials() throws IOException {
+        // Given basic authentication is NOT configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTestsConfig());
+        // Given prompt before connect
+        String promptBefore = getPrompt();
+        assertThat(promptBefore).isEqualTo("[disconnected]> ");
+
+        // And connected
+        execute("connect", "--username", "admin", "--password", "password");
+
+        // And output is
+        assertAll(
+                this::assertErrOutputIsEmpty,
+                () -> assertOutputIs("Connected to http://localhost:10300"; + 
System.lineSeparator())
+        );
+
+        // And answer is "y"
+        bindAnswers("y");
+
+        // And disconnect
+        resetOutput();
+        execute("disconnect");
+
+        // And prompt is changed to another node
+        String promptAfter = getPrompt();
+        assertThat(promptAfter).isEqualTo("[" + CLUSTER_NODES.get(1).name() + 
"]> ");

Review Comment:
   fixed



##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/ssl/ItSslTest.java:
##########
@@ -36,7 +36,7 @@ public class ItSslTest extends 
CliSslNotInitializedIntegrationTestBase {
      * wouldn't help because it will start to ask questions.
      */
     private void connect(String url) {
-        Flows.from(new UrlCallInput(url))
+        Flows.from(new ConnectCallInput(url, null, null))

Review Comment:
   fixed



-- 
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]

Reply via email to