|
20 | 20 | package org.apache.iotdb.db.pipe.event; |
21 | 21 |
|
22 | 22 | import org.apache.iotdb.commons.exception.IllegalPathException; |
| 23 | +import org.apache.iotdb.commons.exception.auth.AccessDeniedException; |
23 | 24 | import org.apache.iotdb.commons.path.PartialPath; |
| 25 | +import org.apache.iotdb.commons.pipe.datastructure.pattern.IoTDBTreePattern; |
24 | 26 | import org.apache.iotdb.commons.pipe.datastructure.pattern.PrefixTreePattern; |
| 27 | +import org.apache.iotdb.commons.pipe.datastructure.pattern.TablePattern; |
| 28 | +import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory; |
| 29 | +import org.apache.iotdb.db.auth.AuthorityChecker; |
| 30 | +import org.apache.iotdb.db.pipe.event.common.tablet.PipeInsertNodeTabletInsertionEvent; |
25 | 31 | import org.apache.iotdb.db.pipe.event.common.tablet.PipeRawTabletInsertionEvent; |
26 | 32 | import org.apache.iotdb.db.pipe.event.common.tablet.parser.TabletInsertionEventTreePatternParser; |
27 | 33 | import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId; |
28 | 34 | import org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertRowNode; |
29 | 35 | import org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertTabletNode; |
| 36 | +import org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.RelationalInsertRowNode; |
| 37 | +import org.apache.iotdb.db.queryengine.plan.relational.security.AccessControl; |
30 | 38 |
|
31 | 39 | import org.apache.tsfile.enums.TSDataType; |
32 | 40 | import org.apache.tsfile.utils.Binary; |
|
40 | 48 |
|
41 | 49 | import java.time.LocalDate; |
42 | 50 | import java.util.Arrays; |
| 51 | +import java.util.Collections; |
| 52 | + |
| 53 | +import static org.apache.iotdb.commons.pipe.datastructure.pattern.TreePattern.buildUnionPattern; |
43 | 54 |
|
44 | 55 | public class PipeTabletInsertionEventTest { |
45 | 56 |
|
@@ -398,4 +409,66 @@ public void isEventTimeOverlappedWithTimeRangeTest() { |
398 | 409 | event = new PipeRawTabletInsertionEvent(tabletForInsertTabletNode, 115L, Long.MAX_VALUE); |
399 | 410 | Assert.assertFalse(event.mayEventTimeOverlappedWithTimeRange()); |
400 | 411 | } |
| 412 | + |
| 413 | + @Test |
| 414 | + public void testAuthCheck() { |
| 415 | + PipeInsertNodeTabletInsertionEvent event; |
| 416 | + |
| 417 | + event = |
| 418 | + new PipeInsertNodeTabletInsertionEvent( |
| 419 | + false, |
| 420 | + "root.db", |
| 421 | + insertRowNode, |
| 422 | + null, |
| 423 | + 0, |
| 424 | + null, |
| 425 | + buildUnionPattern(false, Collections.singletonList(new IoTDBTreePattern(false, null))), |
| 426 | + new TablePattern(true, null, null), |
| 427 | + "0", |
| 428 | + "user", |
| 429 | + "localhost", |
| 430 | + false, |
| 431 | + Long.MIN_VALUE, |
| 432 | + Long.MAX_VALUE); |
| 433 | + final AccessControl oldControl = AuthorityChecker.getAccessControl(); |
| 434 | + try { |
| 435 | + AuthorityChecker.setAccessControl(new PipeTsFileInsertionEventTest.TestAccessControl()); |
| 436 | + Assert.assertThrows(AccessDeniedException.class, event::throwIfNoPrivilege); |
| 437 | + |
| 438 | + event = |
| 439 | + new PipeInsertNodeTabletInsertionEvent( |
| 440 | + true, |
| 441 | + "db", |
| 442 | + new RelationalInsertRowNode( |
| 443 | + new PlanNodeId("plan node 1"), |
| 444 | + new PartialPath("tb", false), |
| 445 | + false, |
| 446 | + new String[] {"s1", "s4"}, |
| 447 | + new TSDataType[] {TSDataType.DOUBLE, TSDataType.BOOLEAN}, |
| 448 | + 2000L, |
| 449 | + new Object[] {2.0, false}, |
| 450 | + false, |
| 451 | + new TsTableColumnCategory[] { |
| 452 | + TsTableColumnCategory.TAG, |
| 453 | + TsTableColumnCategory.ATTRIBUTE, |
| 454 | + TsTableColumnCategory.FIELD |
| 455 | + }), |
| 456 | + null, |
| 457 | + 0, |
| 458 | + null, |
| 459 | + buildUnionPattern( |
| 460 | + false, Collections.singletonList(new IoTDBTreePattern(false, null))), |
| 461 | + new TablePattern(true, null, null), |
| 462 | + "0", |
| 463 | + "user", |
| 464 | + "localhost", |
| 465 | + false, |
| 466 | + Long.MIN_VALUE, |
| 467 | + Long.MAX_VALUE); |
| 468 | + Assert.assertThrows(AccessDeniedException.class, event::throwIfNoPrivilege); |
| 469 | + } finally { |
| 470 | + AuthorityChecker.setAccessControl(oldControl); |
| 471 | + event.close(); |
| 472 | + } |
| 473 | + } |
401 | 474 | } |
0 commit comments