Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void tearDown() {
EnvFactory.getEnv().cleanClusterEnvironment();
}

private void cleanUserAndRole(IConfigNodeRPCService.Iface client)
throws TException, IllegalPathException {
private void cleanUserAndRole(IConfigNodeRPCService.Iface client) throws TException {
TSStatus status;

// clean user
Expand Down Expand Up @@ -121,15 +120,13 @@ public void permissionTest() throws IllegalPathException {
TCheckUserPrivilegesReq checkUserPrivilegesReq;

Set<Integer> privilegeList = new HashSet<>();
privilegeList.add(PrivilegeType.DELETE_USER.ordinal());
privilegeList.add(PrivilegeType.CREATE_USER.ordinal());
privilegeList.add(PrivilegeType.USER_PRIVILEGE.ordinal());

Set<Integer> revokePrivilege = new HashSet<>();
revokePrivilege.add(PrivilegeType.DELETE_USER.ordinal());
revokePrivilege.add(PrivilegeType.USER_PRIVILEGE.ordinal());

List<String> privilege = new ArrayList<>();
privilege.add("root.** : CREATE_USER");
privilege.add("root.** : CREATE_USER");
privilege.add("root.** : USER_PRIVILEGE");

List<PartialPath> paths = new ArrayList<>();
paths.add(new PartialPath("root.ln.**"));
Expand Down Expand Up @@ -159,7 +156,7 @@ public void permissionTest() throws IllegalPathException {
new TCheckUserPrivilegesReq(
"tempuser0",
AuthUtils.serializePartialPathList(paths),
PrivilegeType.DELETE_USER.ordinal());
PrivilegeType.USER_PRIVILEGE.ordinal());
status = client.checkUserPrivileges(checkUserPrivilegesReq).getStatus();
assertEquals(TSStatusCode.NO_PERMISSION.getStatusCode(), status.getCode());

Expand Down Expand Up @@ -270,7 +267,7 @@ public void permissionTest() throws IllegalPathException {
new TCheckUserPrivilegesReq(
"tempuser0",
AuthUtils.serializePartialPathList(paths),
PrivilegeType.DELETE_USER.ordinal());
PrivilegeType.USER_PRIVILEGE.ordinal());
status = client.checkUserPrivileges(checkUserPrivilegesReq).getStatus();
assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());

Expand Down Expand Up @@ -356,6 +353,7 @@ public void permissionTest() throws IllegalPathException {
authorizerResp = client.queryPermission(authorizerReq);
status = authorizerResp.getStatus();
assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
privilege.remove(0);
Assert.assertEquals(
privilege, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE));

Expand Down Expand Up @@ -388,7 +386,6 @@ public void permissionTest() throws IllegalPathException {
authorizerResp = client.queryPermission(authorizerReq);
status = authorizerResp.getStatus();
assertEquals(TSStatusCode.SUCCESS_STATUS.getStatusCode(), status.getCode());
privilege.remove(0);
assertEquals(
0, authorizerResp.getAuthorizerInfo().get(IoTDBConstant.COLUMN_PRIVILEGE).size());

Expand Down
163 changes: 64 additions & 99 deletions integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBAuthIT.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -591,32 +591,10 @@ public void testUDFName() {
public void testUserName() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
String[] userNames =
new String[] {
"userid",
"userid0",
"user_id",
"user0id",
"`22233`",
"`userab!`",
"`user'ab'`",
"`usera.b`",
"`usera``b`"
};
String[] userNames = new String[] {"userid", "userid0", "user_id", "user0id", "`a22233`"};

String[] resultNames =
new String[] {
"root",
"userid",
"userid0",
"user_id",
"user0id",
"22233",
"userab!",
"user'ab'",
"usera.b",
"usera`b"
};
new String[] {"root", "userid", "userid0", "user_id", "user0id", "a22233"};

String createUsersSql = "create user %s 'pwd123' ";
for (String userName : userNames) {
Expand Down Expand Up @@ -678,31 +656,9 @@ public void testUserName() {
public void testRoleName() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
String[] roleNames =
new String[] {
"roleid",
"roleid0",
"role_id",
"role0id",
"`22233`",
"`roleab!`",
"`role'ab'`",
"`rolea.b`",
"`rolea``b`"
};
String[] roleNames = new String[] {"roleid", "roleid0", "role_id", "role0id", "`a22233`"};

String[] resultNames =
new String[] {
"roleid",
"roleid0",
"role_id",
"role0id",
"22233",
"roleab!",
"role'ab'",
"rolea.b",
"rolea`b"
};
String[] resultNames = new String[] {"roleid", "roleid0", "role_id", "role0id", "a22233"};
String createRolesSql = "create role %s";
for (String roleName : roleNames) {
statement.execute(String.format(createRolesSql, roleName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,11 @@ public void testShowAuth() {
} catch (Exception e) {
assertEquals(
TSStatusCode.NO_PERMISSION.getStatusCode()
+ ": No permissions for this operation, please add privilege SHOW_CONTINUOUS_QUERIES",
+ ": No permissions for this operation, please add privilege CONTINUOUS_QUERY_PRIVILEGE",
e.getMessage());
}

statement.execute("GRANT USER `zmty` PRIVILEGES SHOW_CONTINUOUS_QUERIES");
statement.execute("GRANT USER `zmty` PRIVILEGES CONTINUOUS_QUERY_PRIVILEGE");

try (ResultSet resultSet = statement2.executeQuery("show CQS")) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public void testPermission1() throws SQLException {
try (Connection adminCon = EnvFactory.getEnv().getConnection();
Statement adminStmt = adminCon.createStatement()) {
adminStmt.execute("CREATE USER tempuser1 'temppw1'");
adminStmt.execute("GRANT USER tempuser1 PRIVILEGES INSERT_TIMESERIES on root.sg_bk.**;");
adminStmt.execute("GRANT USER tempuser1 PRIVILEGES WRITE_DATA on root.sg_bk.**;");

try (Connection userCon = EnvFactory.getEnv().getConnection("tempuser1", "temppw1");
Statement userStmt = userCon.createStatement()) {
Expand All @@ -561,8 +561,7 @@ public void testPermission1() throws SQLException {
Assert.assertTrue(
e.getMessage(),
e.getMessage()
.contains(
"No permissions for this operation, please add privilege READ_TIMESERIES"));
.contains("No permissions for this operation, please add privilege READ_DATA"));
}
}
}
Expand All @@ -572,7 +571,7 @@ public void testPermission2() throws SQLException {
try (Connection adminCon = EnvFactory.getEnv().getConnection();
Statement adminStmt = adminCon.createStatement()) {
adminStmt.execute("CREATE USER tempuser2 'temppw2'");
adminStmt.execute("GRANT USER tempuser2 PRIVILEGES READ_TIMESERIES on root.sg.**;");
adminStmt.execute("GRANT USER tempuser2 PRIVILEGES WRITE_DATA on root.sg.**;");

try (Connection userCon = EnvFactory.getEnv().getConnection("tempuser2", "temppw2");
Statement userStmt = userCon.createStatement()) {
Expand All @@ -583,8 +582,7 @@ public void testPermission2() throws SQLException {
Assert.assertTrue(
e.getMessage(),
e.getMessage()
.contains(
"No permissions for this operation, please add privilege INSERT_TIMESERIES"));
.contains("No permissions for this operation, please add privilege READ_DATA"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,12 @@ public void testCreateAuth() {
} catch (Exception e) {
assertEquals(
TSStatusCode.NO_PERMISSION.getStatusCode()
+ ": No permissions for this operation, please add privilege CREATE_TRIGGER",
+ ": No permissions for this operation, please add privilege TRIGGER_PRIVILEGE",
e.getMessage());
}

statement.execute("GRANT USER `zmty` PRIVILEGES CREATE_TRIGGER on root.test.stateless.a");
statement.execute(
"GRANT USER `zmty` PRIVILEGES TRIGGER_PRIVILEGE on root.test.stateless.a");

try {
statement2.execute(
Expand All @@ -576,7 +577,7 @@ public void testCreateAuth() {
} catch (Exception e) {
assertEquals(
TSStatusCode.NO_PERMISSION.getStatusCode()
+ ": No permissions for this operation, please add privilege CREATE_TRIGGER",
+ ": No permissions for this operation, please add privilege TRIGGER_PRIVILEGE",
e.getMessage());
}
}
Expand Down Expand Up @@ -608,23 +609,25 @@ public void testDropAuth() {
} catch (Exception e) {
assertEquals(
TSStatusCode.NO_PERMISSION.getStatusCode()
+ ": No permissions for this operation, please add privilege DROP_TRIGGER",
+ ": No permissions for this operation, please add privilege TRIGGER_PRIVILEGE",
e.getMessage());
}

statement.execute("GRANT USER `zmty` PRIVILEGES CREATE_TRIGGER on root.test.stateless.b");
statement.execute(
"GRANT USER `zmty` PRIVILEGES TRIGGER_PRIVILEGE on root.test.stateless.b");

try {
statement2.execute("drop trigger " + STATELESS_TRIGGER_BEFORE_INSERTION_PREFIX + "a");
fail();
} catch (Exception e) {
assertEquals(
TSStatusCode.NO_PERMISSION.getStatusCode()
+ ": No permissions for this operation, please add privilege DROP_TRIGGER",
+ ": No permissions for this operation, please add privilege TRIGGER_PRIVILEGE",
e.getMessage());
}

statement.execute("GRANT USER `zmty` PRIVILEGES DROP_TRIGGER on root.test.stateless.a");
statement.execute(
"GRANT USER `zmty` PRIVILEGES TRIGGER_PRIVILEGE on root.test.stateless.a");

try {
statement2.execute("drop trigger " + STATELESS_TRIGGER_BEFORE_INSERTION_PREFIX + "a");
Expand Down
Loading