This is an automated email from the ASF dual-hosted git repository.
shuwenwei pushed a commit to branch AuthEnhance
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/AuthEnhance by this push:
new 256e0273879 add IoTDBSystemPermissionRelationalIT
256e0273879 is described below
commit 256e0273879f8745d104ebcbad59a4d9958c10f8
Author: shuwenwei <[email protected]>
AuthorDate: Thu Sep 18 15:53:43 2025 +0800
add IoTDBSystemPermissionRelationalIT
---
.../iotdb/db/it/auth/IoTDBSystemPermissionIT.java | 3 +-
.../it/auth/IoTDBSystemPermissionRelationalIT.java | 140 +++++++++++++++++++++
.../org/apache/iotdb/db/it/utils/TestUtils.java | 39 ++++++
3 files changed, 181 insertions(+), 1 deletion(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionIT.java
index db814e98b24..2e8da7e3667 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionIT.java
@@ -215,7 +215,8 @@ public class IoTDBSystemPermissionIT {
executeNonQuery("clear cache", "test6", "test123123456");
executeNonQuery("set system to readonly", "test6", "test123123456");
executeNonQuery("set system to running", "test6", "test123123456");
- executeNonQuery("set configuration 'enable_seq_space_compaction'='true'");
+ executeNonQuery(
+ "set configuration 'enable_seq_space_compaction'='true'", "test6",
"test123123456");
executeNonQuery("start repair data", "test6", "test123123456");
executeNonQuery("stop repair data", "test6", "test123123456");
executeQuery("show queries", "test6", "test123123456");
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionRelationalIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionRelationalIT.java
new file mode 100644
index 00000000000..d7b9a2fe769
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSystemPermissionRelationalIT.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.it.auth;
+
+import org.apache.iotdb.commons.auth.entity.PrivilegeType;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.TableClusterIT;
+import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import static
org.apache.iotdb.db.it.utils.TestUtils.assertTableNonQueryTestFail;
+import static org.apache.iotdb.db.it.utils.TestUtils.createUser;
+import static org.apache.iotdb.db.it.utils.TestUtils.executeNonQuery;
+import static org.apache.iotdb.db.it.utils.TestUtils.executeTableNonQuery;
+import static org.apache.iotdb.db.it.utils.TestUtils.executeTableQuery;
+import static org.apache.iotdb.db.it.utils.TestUtils.grantUserSystemPrivileges;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
+public class IoTDBSystemPermissionRelationalIT {
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+
EnvFactory.getEnv().getConfig().getCommonConfig().setEnforceStrongPassword(false);
+ EnvFactory.getEnv().initClusterEnvironment();
+ createUser("test1", "test123123456");
+ createUser("test2", "test123123456");
+ createUser("test3", "test123123456");
+ createUser("test4", "test123123456");
+ createUser("test5", "test123123456");
+ createUser("test6", "test123123456");
+ createUser("test7", "test123123456");
+ createUser("test8", "test123123456");
+ executeNonQuery("create database root.test1");
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void maintainOperationsTest() {
+ executeTableQuery("show queries", "test6", "test123123456");
+ assertTableNonQueryTestFail(
+ "kill query '20250918_015728_00003_1'", "714: No such query", "test6",
"test123123456");
+ assertTableNonQueriesTestFail(
+ new String[] {
+ "show variables",
+ "flush",
+ "clear cache",
+ "set system to readonly",
+ "set system to running",
+ "set configuration enable_seq_space_compaction='true'",
+ "start repair data",
+ "stop repair data",
+ "show version"
+ },
+ "803: Access Denied: No permissions for this operation, please add
privilege SYSTEM",
+ "test6",
+ "test123123456");
+ grantUserSystemPrivileges("test6", PrivilegeType.SYSTEM);
+ executeTableNonQuery("flush", "test6", "test123123456");
+ executeTableNonQuery("clear cache", "test6", "test123123456");
+ executeTableNonQuery("set system to readonly", "test6", "test123123456");
+ executeTableNonQuery("set system to running", "test6", "test123123456");
+ executeTableNonQuery(
+ "set configuration enable_seq_space_compaction='true'", "test6",
"test123123456");
+ executeTableNonQuery("start repair data", "test6", "test123123456");
+ executeTableNonQuery("stop repair data", "test6", "test123123456");
+ executeTableQuery("show queries", "test6", "test123123456");
+ executeTableNonQuery("show version", "test6", "test123123456");
+ }
+
+ @Test
+ public void clusterManagemantOperationsTest() {
+ assertTableNonQueriesTestFail(
+ new String[] {
+ "show confignodes",
+ "show datanodes",
+ "show ainodes",
+ "show regions",
+ "migrate region 1 from 1 to 2",
+ "remove region 1 from 1",
+ "show cluster",
+ "show cluster details",
+ },
+ "803: Access Denied: No permissions for this operation, please add
privilege SYSTEM",
+ "test7",
+ "test123123456");
+ assertTableNonQueryTestFail(
+ "load configuration",
+ "803: Access Denied: No permissions for this operation, only root user
is allowed",
+ "test7",
+ "test123123456");
+ grantUserSystemPrivileges("test7", PrivilegeType.SYSTEM);
+
+ executeTableQuery("show confignodes", "test7", "test123123456");
+ executeTableQuery("show datanodes", "test7", "test123123456");
+ executeTableQuery("show ainodes", "test7", "test123123456");
+ executeTableQuery("show regions", "test7", "test123123456");
+ executeTableQuery("show cluster", "test7", "test123123456");
+ executeTableQuery("show cluster details", "test7", "test123123456");
+ assertTableNonQueryTestFail(
+ "load configuration",
+ "803: Access Denied: No permissions for this operation, only root user
is allowed",
+ "test7",
+ "test123123456");
+ }
+
+ private void assertTableNonQueriesTestFail(
+ String[] sqls, String msg, String username, String password) {
+ for (String sql : sqls) {
+ assertTableNonQueryTestFail(sql, msg, username, password);
+ }
+ }
+}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
index 33292138d21..93cd8724b88 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
@@ -61,6 +61,7 @@ import java.util.function.Consumer;
import static org.apache.iotdb.itbase.constant.TestConstant.DELTA;
import static org.apache.iotdb.itbase.constant.TestConstant.NULL;
import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
+import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT;
import static org.apache.iotdb.itbase.env.BaseEnv.TREE_SQL_DIALECT;
import static org.awaitility.Awaitility.await;
import static org.junit.Assert.assertArrayEquals;
@@ -665,6 +666,11 @@ public class TestUtils {
assertNonQueryTestFail(EnvFactory.getEnv(), sql, errMsg, userName,
password);
}
+ public static void assertTableNonQueryTestFail(
+ String sql, String errMsg, String userName, String password) {
+ assertTableNonQueryTestFail(EnvFactory.getEnv(), sql, errMsg, userName,
password);
+ }
+
public static void assertNonQueryTestFail(Statement statement, String sql,
String errMsg) {
try {
statement.execute(sql);
@@ -690,6 +696,17 @@ public class TestUtils {
}
}
+ public static void assertTableNonQueryTestFail(
+ BaseEnv env, String sql, String errMsg, String userName, String
password) {
+ try (Connection connection = env.getConnection(userName, password,
BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+ statement.execute(sql);
+ fail("No exception!");
+ } catch (SQLException e) {
+ Assert.assertTrue(e.getMessage(), e.getMessage().contains(errMsg));
+ }
+ }
+
public static void assertTableNonQueryTestFail(
BaseEnv env, String sql, String errMsg, String userName, String
password, String db) {
try (Connection connection = env.getConnection(userName, password,
BaseEnv.TABLE_SQL_DIALECT);
@@ -884,6 +901,17 @@ public class TestUtils {
}
}
+ public static void executeTableNonQuery(String sql, String userName, String
password) {
+ try (Connection connection =
+ EnvFactory.getEnv().getConnection(userName, password,
TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+ statement.execute(sql);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
public static void executeNonQueryWithRetry(final BaseEnv env, final String
sql) {
executeNonQueryWithRetry(env, sql, SessionConfig.DEFAULT_USER,
SessionConfig.DEFAULT_PASSWORD);
}
@@ -1202,6 +1230,17 @@ public class TestUtils {
}
}
+ public static void executeTableQuery(String sql, String userName, String
password) {
+ try (Connection connection =
+ EnvFactory.getEnv().getConnection(userName, password,
TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+ statement.executeQuery(sql);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
public static void executeQueryWithRetry(
final BaseEnv env, final String sql, final String userName, final String
password) {
executeQueryWithRetry(env, sql, userName, password, null,
TREE_SQL_DIALECT);