Skip to content

Commit

Permalink
add unittest for cleanup empty TopicAuthenticationMap
Browse files Browse the repository at this point in the history
  • Loading branch information
fanjianye committed Aug 8, 2022
1 parent 38ce8de commit 3b68294
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,45 @@ public void testDeleteAuthenticationPoliciesOfTopic() throws Exception {
admin.tenants().deleteTenant("p1");
admin.clusters().deleteCluster("test");
}

@Test
public void testCleanupEmptyTopicAuthenticationMap() throws Exception {
Map<String, String> authParams = new HashMap<>();
authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
Authentication authTls = new AuthenticationTls();
authTls.configure(authParams);
internalSetup(authTls);

admin.clusters().createCluster("test", ClusterData.builder().build());
admin.tenants().createTenant("p1",
new TenantInfoImpl(Collections.emptySet(), new HashSet<>(admin.clusters().getClusters())));
admin.namespaces().createNamespace("p1/ns1");

String topic = "persistent://p1/ns1/topic";
admin.topics().createNonPartitionedTopic(topic);
assertFalse(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
.get().auth_policies.getTopicAuthentication().containsKey(topic));

// grant permission
admin.topics().grantPermission(topic, "test-user-1", EnumSet.of(AuthAction.consume));
Awaitility.await().untilAsserted(() -> {
assertTrue(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
.get().auth_policies.getTopicAuthentication().containsKey(topic));
});

// revoke permission
admin.topics().revokePermissions(topic, "test-user-1");
Awaitility.await().untilAsserted(() -> {
assertFalse(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
.get().auth_policies.getTopicAuthentication().containsKey(topic));
});

// grant permission again
admin.topics().grantPermission(topic, "test-user-1", EnumSet.of(AuthAction.consume));
Awaitility.await().untilAsserted(() -> {
assertTrue(pulsar.getPulsarResources().getNamespaceResources().getPolicies(NamespaceName.get("p1/ns1"))
.get().auth_policies.getTopicAuthentication().containsKey(topic));
});
}
}

0 comments on commit 3b68294

Please sign in to comment.