Skip to content

Commit

Permalink
fix incorrect rbac resource name for subjects and connectors (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
purbon authored Nov 21, 2021
1 parent dbb21dc commit c6ce5de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ClusterLevelRoleBuilder forSchemaSubject(String subject, String patternTy

scope = new RequestScope();
scope.setClusters(clusters);
scope.addResource("Subject", "Subject:" + subject, patternType);
scope.addResource("Subject", subject, patternType);
scope.build();

return this;
Expand All @@ -59,7 +59,7 @@ public ClusterLevelRoleBuilder forAKafkaConnector(String connector) {

scope = new RequestScope();
scope.setClusters(clusters);
scope.addResource("Connector", "Connector:" + connector, patternType);
scope.addResource("Connector", connector, patternType);
scope.build();

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void testBindSubjectRole() {
assertThat(mdsRequest.getUrl()).isEqualTo("User:foo/roles/DeveloperRead/bindings");
assertThat(mdsRequest.getJsonEntity())
.isEqualTo(
"{\"resourcePatterns\":[{\"name\":\"Subject:topic-value\",\"patternType\":\"LITERAL\",\"resourceType\":\"Subject\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"schema-registry-cluster\":\"\"}}}");
"{\"resourcePatterns\":[{\"name\":\"topic-value\",\"patternType\":\"LITERAL\",\"resourceType\":\"Subject\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"schema-registry-cluster\":\"\"}}}");
}

@Test
Expand All @@ -41,6 +41,25 @@ public void testBindSubjectRoleWithoutResourceType() {
assertThat(mdsRequest.getUrl()).isEqualTo("User:foo/roles/DeveloperRead/bindings");
assertThat(mdsRequest.getJsonEntity())
.isEqualTo(
"{\"resourcePatterns\":[{\"name\":\"Subject:topic-value\",\"patternType\":\"LITERAL\",\"resourceType\":\"Subject\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"schema-registry-cluster\":\"\"}}}");
"{\"resourcePatterns\":[{\"name\":\"topic-value\",\"patternType\":\"LITERAL\",\"resourceType\":\"Subject\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"schema-registry-cluster\":\"\"}}}");
}

@Test
public void testBindConnectRole() {
String principal = "User:foo";
String connectorName = "jdbc-sink";

TopologyAclBinding binding =
apiClient
.bind(principal, DEVELOPER_READ)
.forAKafkaConnector(connectorName)
.apply("Connector", connectorName);

MDSRequest mdsRequest = apiClient.buildRequest(binding);

assertThat(mdsRequest.getUrl()).isEqualTo("User:foo/roles/DeveloperRead/bindings");
assertThat(mdsRequest.getJsonEntity())
.isEqualTo(
"{\"resourcePatterns\":[{\"name\":\"jdbc-sink\",\"patternType\":\"LITERAL\",\"resourceType\":\"Connector\"}],\"scope\":{\"clusters\":{\"kafka-cluster\":\"\",\"connect-cluster\":\"\"}}}");
}
}

0 comments on commit c6ce5de

Please sign in to comment.