This is an automated email from the ASF dual-hosted git repository. amashenkov pushed a commit to branch ignite-25588 in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit d7c4bdd77198b8b0439ee7d14a98fb32ff84bdd9 Author: amashenkov <[email protected]> AuthorDate: Thu Jul 24 14:40:11 2025 +0300 Add test for thin and jdbc clients. --- .../ignite/jdbc/ItJdbcAuthenticationTest.java | 40 ++++++++++++++++++++++ .../app/client/ItThinClientAuthenticationTest.java | 36 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcAuthenticationTest.java b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcAuthenticationTest.java index 1b4d0b1c8c6..8248351a39a 100644 --- a/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcAuthenticationTest.java +++ b/modules/jdbc/src/integrationTest/java/org/apache/ignite/jdbc/ItJdbcAuthenticationTest.java @@ -17,8 +17,13 @@ package org.apache.ignite.jdbc; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.Connection; import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import org.apache.ignite.InitParametersBuilder; import org.apache.ignite.internal.ClusterPerClassIntegrationTest; @@ -69,6 +74,10 @@ class ItJdbcAuthenticationTest { + " {\n" + " \"username\": \"usr\",\n" + " \"password\": \"pwd\"\n" + + " },\n" + + " {\n" + + " \"username\": \"admin\",\n" + + " \"password\": \"admin\"\n" + " }\n" + " ]\n" + " }\n" @@ -96,5 +105,36 @@ class ItJdbcAuthenticationTest { // No-op. } } + + @Test + void jdbcCurrentUser() throws SQLException { + var url1 = "jdbc:ignite:thin://127.0.0.1:10800" + + "?username=usr" + + "&password=pwd"; + + var url2 = "jdbc:ignite:thin://127.0.0.1:10800" + + "?username=admin" + + "&password=admin"; + try ( + Connection conn1 = DriverManager.getConnection(url1); + Connection conn2 = DriverManager.getConnection(url2) + ) { + try ( + PreparedStatement stmt1 = conn1.prepareStatement("SELECT CURRENT_USER()"); + PreparedStatement stmt2 = conn2.prepareStatement("SELECT CURRENT_USER()"); + ) { + try ( + ResultSet rs1 = stmt1.executeQuery(); + ResultSet rs2 = stmt2.executeQuery(); + ) { + assertTrue(rs1.next()); + assertTrue(rs2.next()); + + assertEquals("usr", rs1.getString(0)); + assertEquals("admin", rs2.getString(0)); + } + } + } + } } } diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientAuthenticationTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientAuthenticationTest.java index e86e3b48b55..64d009527fe 100644 --- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientAuthenticationTest.java +++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientAuthenticationTest.java @@ -19,11 +19,13 @@ package org.apache.ignite.internal.runner.app.client; import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; import static org.apache.ignite.internal.configuration.hocon.HoconConverter.hoconSource; +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowWithCauseOrSuppressed; import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; import static org.apache.ignite.internal.util.IgniteUtils.closeAll; import static org.awaitility.Awaitility.await; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.typesafe.config.ConfigFactory; import java.util.concurrent.CompletableFuture; @@ -36,6 +38,9 @@ import org.apache.ignite.internal.security.authentication.basic.BasicAuthenticat import org.apache.ignite.internal.security.configuration.SecurityConfiguration; import org.apache.ignite.internal.security.configuration.SecurityExtensionConfiguration; import org.apache.ignite.security.exception.InvalidCredentialsException; +import org.apache.ignite.sql.ColumnType; +import org.apache.ignite.sql.SqlRow; +import org.apache.ignite.sql.async.AsyncResultSet; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -182,6 +187,37 @@ public class ItThinClientAuthenticationTest extends ItAbstractThinClientTest { } } + /** + * Tests that the current user can be retrieved correctly for different authenticated users. + * + * @see ItThinClientSqlTest#testCurrentUser() covers the case, when authentication is not enabled. + */ + @Test + public void testCurrentUser() { + IgniteClient client2WithAuth = IgniteClient.builder() + .authenticator(BasicAuthenticator.builder() + .username(USERNAME_2) + .password(PASSWORD_2) + .build()) + .addresses(getClientAddresses().toArray(new String[0])) + .build(); + + validateCurrentUser(client2WithAuth, "admin"); + validateCurrentUser(clientWithAuth, "developer"); + } + + private static void validateCurrentUser(IgniteClient client, String user) { + AsyncResultSet<SqlRow> resultSet = client.sql() + .executeAsync(null, "SELECT CURRENT_USER") + .join(); + + SqlRow row = resultSet.currentPage().iterator().next(); + + assertEquals(ColumnType.STRING, resultSet.metadata().columns().get(0).type()); + assertEquals(format("ClientSqlRow [CURRENT_USER={}]", user), row.toString()); + } + + private static CompletableFuture<Void> checkConnection(IgniteClient client) { return client.sql().executeAsync(null, "select 1 as num, 'hello' as str") .thenApply(ignored -> null);
