|
25 | 25 | import org.apache.iotdb.commons.exception.MetadataException; |
26 | 26 | import org.apache.iotdb.commons.utils.StatusUtils; |
27 | 27 | import org.apache.iotdb.confignode.consensus.request.ConfigPhysicalPlanType; |
| 28 | +import org.apache.iotdb.confignode.consensus.request.write.auth.AuthorTreePlan; |
28 | 29 | import org.apache.iotdb.confignode.consensus.request.write.database.DatabaseSchemaPlan; |
29 | 30 | import org.apache.iotdb.confignode.manager.ConfigManager; |
30 | 31 | import org.apache.iotdb.confignode.manager.PermissionManager; |
@@ -96,6 +97,49 @@ ConfigPhysicalPlanType.CreateDatabase, new TDatabaseSchema("root.db1")), |
96 | 97 | Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, false)); |
97 | 98 | } |
98 | 99 |
|
| 100 | + @Test |
| 101 | + public void testAuthPrivilege() { |
| 102 | + permissionManager.setUserPrivilege( |
| 103 | + (userName, privilegeUnion) -> |
| 104 | + privilegeUnion.getPrivilegeType() == PrivilegeType.MANAGE_USER); |
| 105 | + Assert.assertTrue( |
| 106 | + skipVisitor |
| 107 | + .visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), null) |
| 108 | + .isPresent()); |
| 109 | + Assert.assertTrue( |
| 110 | + skipVisitor |
| 111 | + .visitRevokeUser(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), null) |
| 112 | + .isPresent()); |
| 113 | + Assert.assertFalse( |
| 114 | + skipVisitor |
| 115 | + .visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), null) |
| 116 | + .isPresent()); |
| 117 | + Assert.assertFalse( |
| 118 | + skipVisitor |
| 119 | + .visitRevokeRole(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), null) |
| 120 | + .isPresent()); |
| 121 | + |
| 122 | + permissionManager.setUserPrivilege( |
| 123 | + (userName, privilegeUnion) -> |
| 124 | + privilegeUnion.getPrivilegeType() == PrivilegeType.MANAGE_ROLE); |
| 125 | + Assert.assertFalse( |
| 126 | + skipVisitor |
| 127 | + .visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), null) |
| 128 | + .isPresent()); |
| 129 | + Assert.assertFalse( |
| 130 | + skipVisitor |
| 131 | + .visitRevokeUser(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), null) |
| 132 | + .isPresent()); |
| 133 | + Assert.assertTrue( |
| 134 | + skipVisitor |
| 135 | + .visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), null) |
| 136 | + .isPresent()); |
| 137 | + Assert.assertTrue( |
| 138 | + skipVisitor |
| 139 | + .visitRevokeRole(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), null) |
| 140 | + .isPresent()); |
| 141 | + } |
| 142 | + |
99 | 143 | private static class TestPermissionManager extends PermissionManager { |
100 | 144 |
|
101 | 145 | private BiFunction<String, PrivilegeUnion, Boolean> checkUserPrivileges = |
|
0 commit comments