|
48 | 48 | import org.apache.kafka.server.authorizer.AuthorizationResult;
|
49 | 49 | import org.apache.kafka.server.authorizer.AuthorizerServerInfo;
|
50 | 50 | import org.apache.kafka.server.common.ApiMessageAndVersion;
|
| 51 | +import org.apache.kafka.server.mutable.BoundedListTooLongException; |
51 | 52 | import org.apache.kafka.timeline.SnapshotRegistry;
|
52 | 53 |
|
53 | 54 | import org.junit.jupiter.api.Test;
|
|
71 | 72 | import static org.apache.kafka.common.resource.PatternType.LITERAL;
|
72 | 73 | import static org.apache.kafka.common.resource.PatternType.MATCH;
|
73 | 74 | import static org.apache.kafka.common.resource.ResourceType.TOPIC;
|
| 75 | +import static org.apache.kafka.controller.QuorumController.MAX_RECORDS_PER_USER_OP; |
74 | 76 | import static org.apache.kafka.metadata.authorizer.StandardAclWithIdTest.TEST_ACLS;
|
75 | 77 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
76 | 78 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
@@ -366,4 +368,60 @@ public void testDeleteDedupe() {
|
366 | 368 | assertEquals(id, ((RemoveAccessControlEntryRecord) deleteAclResultsBothFilters.records().get(0).message()).id());
|
367 | 369 | assertEquals(2, deleteAclResultsBothFilters.response().size());
|
368 | 370 | }
|
| 371 | + |
| 372 | + @Test |
| 373 | + public void testDeleteExceedsMaxRecords() { |
| 374 | + AclControlManager manager = new AclControlManager.Builder().build(); |
| 375 | + MockClusterMetadataAuthorizer authorizer = new MockClusterMetadataAuthorizer(); |
| 376 | + authorizer.loadSnapshot(manager.idToAcl()); |
| 377 | + |
| 378 | + List<AclBinding> firstCreate = new ArrayList<>(); |
| 379 | + List<AclBinding> secondCreate = new ArrayList<>(); |
| 380 | + |
| 381 | + // create MAX_RECORDS_PER_USER_OP + 2 ACLs |
| 382 | + for (int i = 0; i < MAX_RECORDS_PER_USER_OP + 2; i++) { |
| 383 | + StandardAclWithId acl = new StandardAclWithId(Uuid.randomUuid(), |
| 384 | + new StandardAcl( |
| 385 | + ResourceType.TOPIC, |
| 386 | + "mytopic_" + i, |
| 387 | + PatternType.LITERAL, |
| 388 | + "User:alice", |
| 389 | + "127.0.0.1", |
| 390 | + AclOperation.READ, |
| 391 | + AclPermissionType.ALLOW)); |
| 392 | + |
| 393 | + // split acl creations between two create requests |
| 394 | + if (i % 2 == 0) { |
| 395 | + firstCreate.add(acl.toBinding()); |
| 396 | + } else { |
| 397 | + secondCreate.add(acl.toBinding()); |
| 398 | + } |
| 399 | + } |
| 400 | + ControllerResult<List<AclCreateResult>> firstCreateResult = manager.createAcls(firstCreate); |
| 401 | + assertEquals((MAX_RECORDS_PER_USER_OP / 2) + 1, firstCreateResult.response().size()); |
| 402 | + for (AclCreateResult result : firstCreateResult.response()) { |
| 403 | + assertTrue(!result.exception().isPresent()); |
| 404 | + } |
| 405 | + |
| 406 | + ControllerResult<List<AclCreateResult>> secondCreateResult = manager.createAcls(secondCreate); |
| 407 | + assertEquals((MAX_RECORDS_PER_USER_OP / 2) + 1, secondCreateResult.response().size()); |
| 408 | + for (AclCreateResult result : secondCreateResult.response()) { |
| 409 | + assertTrue(!result.exception().isPresent()); |
| 410 | + } |
| 411 | + |
| 412 | + RecordTestUtils.replayAll(manager, firstCreateResult.records()); |
| 413 | + RecordTestUtils.replayAll(manager, secondCreateResult.records()); |
| 414 | + assertFalse(manager.idToAcl().isEmpty()); |
| 415 | + |
| 416 | + ArrayList<AclBindingFilter> filters = new ArrayList<>(); |
| 417 | + for (int i = 0; i < MAX_RECORDS_PER_USER_OP + 2; i++) { |
| 418 | + filters.add(new AclBindingFilter( |
| 419 | + new ResourcePatternFilter(ResourceType.TOPIC, "mytopic_" + i, PatternType.LITERAL), |
| 420 | + AccessControlEntryFilter.ANY)); |
| 421 | + } |
| 422 | + |
| 423 | + Exception exception = assertThrows(InvalidRequestException.class, () -> manager.deleteAcls(filters)); |
| 424 | + assertEquals(BoundedListTooLongException.class, exception.getCause().getClass()); |
| 425 | + assertEquals("Cannot remove more than " + MAX_RECORDS_PER_USER_OP + " acls in a single delete operation.", exception.getCause().getMessage()); |
| 426 | + } |
369 | 427 | }
|
0 commit comments