Caideyipi commented on code in PR #13158:
URL: https://github.com/apache/iotdb/pull/13158#discussion_r1924798582


##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/auth/AuthorizerManagerTest.java:
##########
@@ -190,114 +116,125 @@ public void permissionCacheTest() throws 
IllegalPathException {
 
   @Test
   public void grantOptTest() throws IllegalPathException {
-    User user = new User();
-    Role role = new Role();
-
-    Set<Integer> sysPri = new HashSet<>();
-    sysPri.add(PrivilegeType.MANAGE_DATABASE.ordinal());
-    sysPri.add(PrivilegeType.USE_PIPE.ordinal());
-    user.setSysPrivilegeSet(sysPri);
-
-    Set<Integer> sysGrantOpt = new HashSet<>();
-    sysGrantOpt.add(PrivilegeType.USE_PIPE.ordinal());
-    user.setSysPriGrantOpt(sysGrantOpt);
+    User user = new User("user1", "123456");
+    Role role = new Role("role1");
 
-    List<PathPrivilege> pathList = new ArrayList<>();
-    PartialPath pathRoot = new PartialPath("root.**");
-    PartialPath path1 = new PartialPath("root.d1.**");
-    PathPrivilege priv1 = new PathPrivilege(path1);
-    priv1.grantPrivilege(PrivilegeType.READ_DATA.ordinal(), false);
-    priv1.grantPrivilege(PrivilegeType.WRITE_SCHEMA.ordinal(), true);
-    pathList.add(priv1);
+    user.grantSysPrivilege(PrivilegeType.MANAGE_DATABASE, false);
+    user.grantSysPrivilege(PrivilegeType.USE_PIPE, true);
 
-    user.setPrivilegeList(pathList);
+    user.grantPathPrivilege(new PartialPath("root.d1.**"), 
PrivilegeType.READ_DATA, false);
+    user.grantPathPrivilege(new PartialPath("root.d1.**"), 
PrivilegeType.WRITE_SCHEMA, true);
 
-    user.setName("user1");
-    user.setPassword("123456");
+    user.grantDBPrivilege("database", PrivilegeType.SELECT, false);
+    user.grantDBPrivilege("database", PrivilegeType.ALTER, true);
+    user.grantTBPrivilege("database", "table", PrivilegeType.DELETE, true);
+    role.grantSysPrivilege(PrivilegeType.USE_UDF, false);
+    role.grantSysPrivilege(PrivilegeType.USE_CQ, true);
+    role.grantSysPrivilegeGrantOption(PrivilegeType.USE_CQ);
+    role.grantPathPrivilege(new PartialPath("root.t.**"), 
PrivilegeType.READ_DATA, true);
+    role.grantDBPrivilege("database", PrivilegeType.INSERT, true);
 
     // user's priv:
     // 1. MANAGE_DATABASE
     // 2. USE_PIPE with grant option
     // 3. READ_DATA root.d1.**
     // 4. WRITE_SCHEMA root.d1.** with grant option
+    // 5. SELECT on database, ALTER on database with grant option
+    // 6. DELETE on database.table with grant option
 
     // role's priv:
     // 1. USE_UDF
     // 2. USE_CQ with grant option
-    // 3. READ_DATA root.t9.** with grant option
-
-    role.setName("role1");
-    Set<Integer> sysPriRole = new HashSet<>();
-    sysPriRole.add(PrivilegeType.USE_UDF.ordinal());
-    sysPriRole.add(PrivilegeType.USE_CQ.ordinal());
-    role.setSysPrivilegeSet(sysPriRole);
-
-    Set<Integer> sysGrantOptRole = new HashSet<>();
-    sysGrantOptRole.add(PrivilegeType.USE_CQ.ordinal());
-    role.setSysPriGrantOpt(sysGrantOptRole);
-
-    PathPrivilege privRole = new PathPrivilege(new PartialPath("root.t9.**"));
-    privRole.grantPrivilege(PrivilegeType.READ_DATA.ordinal(), true);
-    role.setPrivilegeList(Collections.singletonList(privRole));
-    user.setRoleList(Collections.singletonList("role1"));
+    // 3. READ_DATA root.t.** with grant option

Review Comment:
   // 4. INSERT on database with grant option



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/parser/StatementGeneratorTest.java:
##########
@@ -718,12 +718,13 @@ public void testNormalGrantRevoke() {
 
     // 1. check simple privilege grant to user/role with/without grant option.
     for (PrivilegeType privilege : PrivilegeType.values()) {
+      if (privilege.isRelationalPrivilege()) continue;

Review Comment:
   Better add {
   }



##########
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AuthorStatementTest.java:
##########
@@ -0,0 +1,351 @@
+/*
+ * 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.queryengine.plan.relational.sql.parser;
+
+import org.apache.iotdb.commons.auth.entity.PrivilegeModelType;
+import org.apache.iotdb.commons.auth.entity.PrivilegeType;
+import org.apache.iotdb.db.protocol.session.IClientSession;
+import org.apache.iotdb.db.protocol.session.InternalClientSession;
+import 
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RelationalAuthorStatement;
+import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.Statement;
+import org.apache.iotdb.db.queryengine.plan.relational.type.AuthorRType;
+
+import org.junit.Test;
+
+import java.time.ZonedDateTime;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+public class AuthorStatementTest {
+  private SqlParser parser = new SqlParser();
+  IClientSession clientSession = new InternalClientSession("internal");
+  private final String databaseName = "test";
+  private final String idName = "iotdb_user";
+
+  public AuthorStatementTest() {
+    clientSession.setDatabaseName(databaseName);
+  }
+
+  private RelationalAuthorStatement createAuthorStatement(String sql) {
+    Statement stmt = parser.createStatement(sql, 
ZonedDateTime.now().getOffset(), clientSession);
+    return (RelationalAuthorStatement) stmt;
+  }
+
+  private void checkUserManagerFiled(RelationalAuthorStatement 
authorStatement) {

Review Comment:
   checkNonPrivilegeStatement?



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