Skip to content

Commit 3f515d7

Browse files
committed
fix
1 parent b9820f3 commit 3f515d7

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitorTest.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.apache.iotdb.confignode.manager.pipe.source;
2121

2222
import org.apache.iotdb.common.rpc.thrift.TSStatus;
23+
import org.apache.iotdb.commons.audit.UserEntity;
2324
import org.apache.iotdb.commons.auth.entity.PrivilegeType;
2425
import org.apache.iotdb.commons.auth.entity.PrivilegeUnion;
2526
import org.apache.iotdb.commons.exception.MetadataException;
@@ -57,7 +58,7 @@
5758
import java.util.function.BiFunction;
5859

5960
public class PipeConfigTreePrivilegeParseVisitorTest {
60-
61+
private static final UserEntity FAKE_USER_ENTITY = new UserEntity(0L, "", "");
6162
private final PipeConfigTreePrivilegeParseVisitor skipVisitor =
6263
new PipeConfigTreePrivilegeParseVisitor(true);
6364
private final PipeConfigTreePrivilegeParseVisitor throwVisitor =
@@ -85,28 +86,28 @@ public void tearDown() throws IOException, StorageEngineException {
8586
public void testCanReadSysSchema() {
8687
permissionManager.setUserPrivilege(
8788
(userName, privilegeUnion) -> privilegeUnion.getPrivilegeType() == PrivilegeType.SYSTEM);
88-
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true));
89+
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, true));
8990

9091
permissionManager.setUserPrivilege(
9192
(userName, privilegeUnion) ->
9293
privilegeUnion.getPrivilegeType() == PrivilegeType.READ_SCHEMA
9394
&& privilegeUnion.getPaths().stream().allMatch(path -> path.equals("root.db")));
94-
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true));
95-
Assert.assertFalse(skipVisitor.canReadSysSchema("root.db", null, false));
95+
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, true));
96+
Assert.assertFalse(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, false));
9697
Assert.assertFalse(
9798
throwVisitor
9899
.visitCreateDatabase(
99100
new DatabaseSchemaPlan(
100101
ConfigPhysicalPlanType.CreateDatabase, new TDatabaseSchema("root.db1")),
101-
null)
102+
FAKE_USER_ENTITY)
102103
.isPresent());
103104

104105
permissionManager.setUserPrivilege(
105106
(userName, privilegeUnion) ->
106107
privilegeUnion.getPrivilegeType() == PrivilegeType.READ_SCHEMA
107108
&& privilegeUnion.getPaths().stream().allMatch(path -> path.equals("root.db.**")));
108-
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true));
109-
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, false));
109+
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, true));
110+
Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", FAKE_USER_ENTITY, false));
110111
}
111112

112113
@Test
@@ -116,39 +117,43 @@ public void testAuthPrivilege() {
116117
privilegeUnion.getPrivilegeType() == PrivilegeType.MANAGE_USER);
117118
Assert.assertTrue(
118119
skipVisitor
119-
.visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), null)
120+
.visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), FAKE_USER_ENTITY)
120121
.isPresent());
121122
Assert.assertTrue(
122123
skipVisitor
123-
.visitRevokeUser(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), null)
124+
.visitRevokeUser(
125+
new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), FAKE_USER_ENTITY)
124126
.isPresent());
125127
Assert.assertFalse(
126128
skipVisitor
127-
.visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), null)
129+
.visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), FAKE_USER_ENTITY)
128130
.isPresent());
129131
Assert.assertFalse(
130132
skipVisitor
131-
.visitRevokeRole(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), null)
133+
.visitRevokeRole(
134+
new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), FAKE_USER_ENTITY)
132135
.isPresent());
133136

134137
permissionManager.setUserPrivilege(
135138
(userName, privilegeUnion) ->
136139
privilegeUnion.getPrivilegeType() == PrivilegeType.MANAGE_ROLE);
137140
Assert.assertFalse(
138141
skipVisitor
139-
.visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), null)
142+
.visitGrantUser(new AuthorTreePlan(ConfigPhysicalPlanType.GrantUser), FAKE_USER_ENTITY)
140143
.isPresent());
141144
Assert.assertFalse(
142145
skipVisitor
143-
.visitRevokeUser(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), null)
146+
.visitRevokeUser(
147+
new AuthorTreePlan(ConfigPhysicalPlanType.RevokeUser), FAKE_USER_ENTITY)
144148
.isPresent());
145149
Assert.assertTrue(
146150
skipVisitor
147-
.visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), null)
151+
.visitGrantRole(new AuthorTreePlan(ConfigPhysicalPlanType.GrantRole), FAKE_USER_ENTITY)
148152
.isPresent());
149153
Assert.assertTrue(
150154
skipVisitor
151-
.visitRevokeRole(new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), null)
155+
.visitRevokeRole(
156+
new AuthorTreePlan(ConfigPhysicalPlanType.RevokeRole), FAKE_USER_ENTITY)
152157
.isPresent());
153158
}
154159

@@ -172,7 +177,8 @@ public void testPatternRelatedPrivilege() throws IOException {
172177
PathPatternTree.deserialize(
173178
((PipeDeleteTimeSeriesPlan)
174179
skipVisitor
175-
.visitPipeDeleteTimeSeries(new PipeDeleteTimeSeriesPlan(buffer), null)
180+
.visitPipeDeleteTimeSeries(
181+
new PipeDeleteTimeSeriesPlan(buffer), FAKE_USER_ENTITY)
176182
.get())
177183
.getPatternTreeBytes())
178184
.getAllPathPatterns());
@@ -181,16 +187,21 @@ public void testPatternRelatedPrivilege() throws IOException {
181187
PathPatternTree.deserialize(
182188
((PipeDeleteLogicalViewPlan)
183189
skipVisitor
184-
.visitPipeDeleteLogicalView(new PipeDeleteLogicalViewPlan(buffer), null)
190+
.visitPipeDeleteLogicalView(
191+
new PipeDeleteLogicalViewPlan(buffer), FAKE_USER_ENTITY)
185192
.get())
186193
.getPatternTreeBytes())
187194
.getAllPathPatterns());
188195
Assert.assertThrows(
189196
AccessDeniedException.class,
190-
() -> throwVisitor.visitPipeDeleteTimeSeries(new PipeDeleteTimeSeriesPlan(buffer), null));
197+
() ->
198+
throwVisitor.visitPipeDeleteTimeSeries(
199+
new PipeDeleteTimeSeriesPlan(buffer), FAKE_USER_ENTITY));
191200
Assert.assertThrows(
192201
AccessDeniedException.class,
193-
() -> throwVisitor.visitPipeDeleteLogicalView(new PipeDeleteLogicalViewPlan(buffer), null));
202+
() ->
203+
throwVisitor.visitPipeDeleteLogicalView(
204+
new PipeDeleteLogicalViewPlan(buffer), FAKE_USER_ENTITY));
194205

195206
Assert.assertEquals(
196207
Collections.singleton(matchedPath),
@@ -204,7 +215,7 @@ public void testPatternRelatedPrivilege() throws IOException {
204215
put(unmatchedPath, Collections.singletonList(new Template()));
205216
}
206217
}),
207-
null)
218+
FAKE_USER_ENTITY)
208219
.get())
209220
.getTemplateSetInfo()
210221
.keySet());
@@ -215,13 +226,14 @@ public void testPatternRelatedPrivilege() throws IOException {
215226
skipVisitor
216227
.visitTTL(
217228
new SetTTLPlan(new String[] {"root", "*", "device", "measurement"}, 100),
218-
null)
229+
FAKE_USER_ENTITY)
219230
.get())
220231
.getPathPattern());
221232
Assert.assertFalse(
222233
skipVisitor
223234
.visitTTL(
224-
new SetTTLPlan(new String[] {"root", "db2", "device", "measurement"}, 100), null)
235+
new SetTTLPlan(new String[] {"root", "db2", "device", "measurement"}, 100),
236+
FAKE_USER_ENTITY)
225237
.isPresent());
226238
}
227239

0 commit comments

Comments
 (0)