|
17 | 17 | package org.apache.kafka.tools;
|
18 | 18 |
|
19 | 19 | import org.apache.kafka.common.acl.AccessControlEntry;
|
| 20 | +import org.apache.kafka.common.acl.AclBinding; |
20 | 21 | import org.apache.kafka.common.acl.AclBindingFilter;
|
21 | 22 | import org.apache.kafka.common.acl.AclOperation;
|
22 | 23 | import org.apache.kafka.common.acl.AclPermissionType;
|
|
79 | 80 | import static org.apache.kafka.server.config.ServerConfigs.AUTHORIZER_CLASS_NAME_CONFIG;
|
80 | 81 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
81 | 82 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 83 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
82 | 84 | import static org.junit.jupiter.api.Assertions.assertNull;
|
83 | 85 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
84 | 86 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
@@ -275,6 +277,24 @@ public void testPatternTypesWithAdminAPIAndBootstrapController(ClusterInstance c
|
275 | 277 | testPatternTypes(adminArgsWithBootstrapController(cluster.bootstrapControllers(), Optional.empty()));
|
276 | 278 | }
|
277 | 279 |
|
| 280 | + @ClusterTest |
| 281 | + public void testDuplicateAdd(ClusterInstance cluster) { |
| 282 | + final String topicName = "test-topic"; |
| 283 | + final String principal = "User:Alice"; |
| 284 | + ResourcePattern resource = new ResourcePattern(ResourceType.TOPIC, topicName, PatternType.LITERAL); |
| 285 | + AccessControlEntry ace = new AccessControlEntry(principal, WILDCARD_HOST, READ, ALLOW); |
| 286 | + AclBinding binding = new AclBinding(resource, ace); |
| 287 | + List<String> cmdArgs = adminArgs(cluster.bootstrapServers(), Optional.empty()); |
| 288 | + List<String> initialAddArgs = new ArrayList<>(cmdArgs); |
| 289 | + initialAddArgs.addAll(List.of(ADD, TOPIC, topicName, "--allow-principal", principal, OPERATION, "Read")); |
| 290 | + |
| 291 | + callMain(initialAddArgs); |
| 292 | + String out = callMain(initialAddArgs).getKey(); |
| 293 | + |
| 294 | + assertTrue(out.contains("Acl " + binding + " already exists.")); |
| 295 | + assertFalse(out.contains("Adding ACLs for resource")); |
| 296 | + } |
| 297 | + |
278 | 298 | @Test
|
279 | 299 | public void testUseBootstrapServerOptWithBootstrapControllerOpt() {
|
280 | 300 | assertInitializeInvalidOptionsExitCodeAndMsg(
|
|
0 commit comments