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 fadc303fafb add it for maintain & cluster management & ttl
fadc303fafb is described below

commit fadc303fafb07b94a27529c9dfb96ce4af347764
Author: shuwenwei <[email protected]>
AuthorDate: Thu Sep 18 10:37:02 2025 +0800

    add it for maintain & cluster management & ttl
---
 .../iotdb/db/it/auth/IoTDBSeriesPermissionIT.java  |  49 +++++++++
 .../iotdb/db/it/auth/IoTDBSystemPermissionIT.java  | 113 ++++++++++-----------
 .../org/apache/iotdb/db/it/utils/TestUtils.java    |   9 ++
 3 files changed, 113 insertions(+), 58 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSeriesPermissionIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSeriesPermissionIT.java
index 4e27ed86393..07867da8c7b 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSeriesPermissionIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBSeriesPermissionIT.java
@@ -27,11 +27,17 @@ import org.apache.iotdb.itbase.category.ClusterIT;
 import org.apache.iotdb.itbase.category.LocalStandaloneIT;
 
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
 import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.TIME;
 import static 
org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.countDevicesColumnHeaders;
 import static 
org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.countNodesColumnHeaders;
@@ -48,6 +54,7 @@ import static 
org.apache.iotdb.db.it.utils.TestUtils.executeNonQuery;
 import static org.apache.iotdb.db.it.utils.TestUtils.grantUserSeriesPrivilege;
 import static org.apache.iotdb.db.it.utils.TestUtils.grantUserSystemPrivileges;
 import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
+import static org.junit.Assert.fail;
 
 @RunWith(IoTDBTestRunner.class)
 @Category({LocalStandaloneIT.class, ClusterIT.class})
@@ -59,6 +66,7 @@ public class IoTDBSeriesPermissionIT {
     EnvFactory.getEnv().initClusterEnvironment();
     createUser("test", "test123123456");
     createUser("test1", "test123123456");
+    createUser("test2", "test123123456");
   }
 
   @After
@@ -306,4 +314,45 @@ public class IoTDBSeriesPermissionIT {
         "test",
         "test123123456");
   }
+
+  @Test
+  public void ttlOperationsTest() {
+    try (Connection connection = EnvFactory.getEnv().getConnection("test2", 
"test123123456");
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery("show all ttl");
+      Assert.assertFalse(resultSet.next());
+      assertNonQueryTestFail(
+          statement,
+          "set ttl to root.test.** 1",
+          "803: No permissions for this operation, please add privilege 
WRITE_SCHEMA on [root.test.**]");
+      assertNonQueryTestFail(
+          statement,
+          "unset ttl from root.test.**",
+          "803: No permissions for this operation, please add privilege 
WRITE_SCHEMA on [root.test.**]");
+    } catch (SQLException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      ResultSet resultSet = statement.executeQuery("show all ttl");
+      Assert.assertTrue(resultSet.next());
+      Assert.assertFalse(resultSet.next());
+      statement.execute("grant WRITE_SCHEMA on root.test.** to user test2");
+    } catch (SQLException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+    try (Connection connection = EnvFactory.getEnv().getConnection("test2", 
"test123123456");
+        Statement statement = connection.createStatement()) {
+      statement.execute("set ttl to root.test.** 1");
+      ResultSet resultSet = statement.executeQuery("show all ttl");
+      Assert.assertTrue(resultSet.next());
+      Assert.assertFalse(resultSet.next());
+      statement.execute("unset ttl from root.test.**");
+    } catch (SQLException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+  }
 }
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 85ed9a42cc3..db814e98b24 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
@@ -59,6 +59,7 @@ public class IoTDBSystemPermissionIT {
     createUser("test5", "test123123456");
     createUser("test6", "test123123456");
     createUser("test7", "test123123456");
+    createUser("test8", "test123123456");
     executeNonQuery("create database root.test1");
   }
 
@@ -67,17 +68,6 @@ public class IoTDBSystemPermissionIT {
     EnvFactory.getEnv().cleanClusterEnvironment();
   }
 
-  @Test
-  public void showVersionTest() {
-    assertNonQueryTestFail(
-        "show version",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test4",
-        "test123123456");
-    grantUserSystemPrivileges("test4", PrivilegeType.SYSTEM);
-    executeQuery("show version", "test4", "test123123456");
-  }
-
   @Test
   public void manageDataBaseTest() {
     assertNonQueryTestFail(
@@ -141,11 +131,7 @@ public class IoTDBSystemPermissionIT {
         "803: No permissions for this operation, please add privilege SYSTEM",
         "test3",
         "test123123456");
-    assertTestFail(
-        "show functions",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test3",
-        "test123123456");
+    executeQuery("show functions", "test3", "test123123456");
 
     grantUserSystemPrivileges("test3", PrivilegeType.SYSTEM);
 
@@ -206,65 +192,76 @@ public class IoTDBSystemPermissionIT {
 
   @Test
   public void maintainOperationsTest() {
+    executeQuery("show queries", "test6", "test123123456");
     assertNonQueryTestFail(
-        "show queries",
+        "kill query '20250918_015728_00003_1'", "714: No such query", "test6", 
"test123123456");
+    assertNonQueriesTestFail(
+        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: No permissions for this operation, please add privilege SYSTEM",
         "test6",
         "test123123456");
-    assertNonQueryTestFail(
-        "kill query 'test'",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test6",
-        "test123123456");
-    assertNonQueryTestFail(
-        "show cluster",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test6",
-        "test123123456");
-    assertNonQueryTestFail(
-        "show cluster details",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test6",
-        "test123123456");
-
     grantUserSystemPrivileges("test6", PrivilegeType.SYSTEM);
-
-    executeNonQuery("show queries", "test6", "test123123456");
-    assertNonQueryTestFail(
-        "kill query 'test'",
-        "701: Please ensure your input <queryId> is correct",
-        "test6",
-        "test123123456");
-    executeNonQuery("show cluster", "test6", "test123123456");
-    executeNonQuery("show cluster details", "test6", "test123123456");
+    executeNonQuery("flush", "test6", "test123123456");
+    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("start repair data", "test6", "test123123456");
+    executeNonQuery("stop repair data", "test6", "test123123456");
+    executeQuery("show queries", "test6", "test123123456");
+    executeNonQuery("show version", "test6", "test123123456");
   }
 
   @Test
-  public void adminOperationsTest() {
-    assertNonQueryTestFail(
-        "flush",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test7",
-        "test123123456");
-    assertNonQueryTestFail(
-        "clear cache",
+  public void clusterManagemantOperationsTest() {
+    assertNonQueriesTestFail(
+        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: No permissions for this operation, please add privilege SYSTEM",
         "test7",
         "test123123456");
     assertNonQueryTestFail(
-        "set system to readonly",
-        "803: No permissions for this operation, please add privilege SYSTEM",
-        "test7",
-        "test123123456");
-    assertNonQueryTestFail(
-        "set system to running",
-        "803: No permissions for this operation, please add privilege SYSTEM",
+        "load configuration",
+        "803: Only the admin user can perform this operation",
         "test7",
         "test123123456");
+    grantUserSystemPrivileges("test7", PrivilegeType.SYSTEM);
+
+    executeQuery("show confignodes", "test7", "test123123456");
+    executeQuery("show datanodes", "test7", "test123123456");
+    executeQuery("show ainodes", "test7", "test123123456");
+    executeQuery("show regions", "test7", "test123123456");
+    executeQuery("show cluster", "test7", "test123123456");
+    executeQuery("show cluster details", "test7", "test123123456");
     assertNonQueryTestFail(
         "load configuration",
-        "803: No permissions for this operation, please add privilege SYSTEM",
+        "803: Only the admin user can perform this operation",
         "test7",
         "test123123456");
   }
+
+  private void assertNonQueriesTestFail(
+      String[] sqls, String msg, String username, String password) {
+    for (String sql : sqls) {
+      assertNonQueryTestFail(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 5e23c553b51..33292138d21 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
@@ -665,6 +665,15 @@ public class TestUtils {
     assertNonQueryTestFail(EnvFactory.getEnv(), sql, errMsg, userName, 
password);
   }
 
+  public static void assertNonQueryTestFail(Statement statement, String sql, 
String errMsg) {
+    try {
+      statement.execute(sql);
+      fail("No exception!");
+    } catch (SQLException e) {
+      Assert.assertTrue(e.getMessage(), e.getMessage().contains(errMsg));
+    }
+  }
+
   public static void assertTableNonQueryTestFail(
       String sql, String errMsg, String userName, String password, String 
dbName) {
     assertTableNonQueryTestFail(EnvFactory.getEnv(), sql, errMsg, userName, 
password, dbName);

Reply via email to