@Test
  public void illegalGrantRevokeUserTest() throws SQLException {
    try (Connection adminCon = EnvFactory.getEnv().getConnection();
        Statement adminStmt = adminCon.createStatement()) {
      adminStmt.execute("CREATE USER tempuser 'temppw'");

      try (Connection userCon = EnvFactory.getEnv().getConnection("tempuser", "temppw");
          Statement userStmt = userCon.createStatement()) {

        // grant a non-existing user
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("GRANT WRITE_SCHEMA on root.a TO USER 'not a user'"));
        // grant a non-existing privilege
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("GRANT NOT_A_PRIVILEGE on root.a TO USER tempuser"));
        adminStmt.execute("GRANT MANAGE_USER on root.** TO USER tempuser");
        // grant on an illegal seriesPath
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("GRANT WRITE_SCHEMA on a.b TO USER tempuser"));
        // grant admin
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("GRANT WRITE_SCHEMA on root.a.b TO USER root"));
        // no privilege to grant
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("GRANT WRITE_SCHEMA on root.a.b TO USER tempuser"));
        // revoke a non-existing privilege
        adminStmt.execute("REVOKE MANAGE_USER on root.** FROM USER tempuser");

        // revoke a non-existing user
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("REVOKE MANAGE_USER on root.** FROM USER tempuser1"));
        // revoke on an illegal seriesPath
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("REVOKE WRITE_SCHEMA on a.b FROM USER tempuser"));
        // revoke admin
        Assert.assertThrows(
            SQLException.class,
            () -> adminStmt.execute("REVOKE WRITE_SCHEMA on root.a.b FROM USER root"));
        // no privilege to revoke
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("REVOKE WRITE_SCHEMA on root.a.b FROM USER tempuser"));
        // grant privilege to grant
        Assert.assertThrows(
            SQLException.class,
            () -> userStmt.execute("GRANT WRITE_SCHEMA on root.a.b TO USER tempuser"));
        adminStmt.execute("GRANT WRITE_SCHEMA ON root.** TO USER tempuser WITH GRANT OPTION");
        userStmt.execute("GRANT WRITE_SCHEMA on root.** TO USER tempuser");
        userStmt.execute("REVOKE WRITE_SCHEMA on root.** FROM USER tempuser");
      }
    }
  }
This is an example for integration test.
integration-test/src/test/java/org/apache/iotdb/db/it/auth/IoTDBAuthIT.java