Search in sources :

Example 1 with DeleteAclsResponse

use of io.confluent.kafkarest.entities.v3.DeleteAclsResponse in project kafka-rest by confluentinc.

the class AclsResourceIntegrationTest method testCreateSearchAndMultiDelete.

@Test
public void testCreateSearchAndMultiDelete() {
    createAliceAndBobAcls();
    DeleteAclsResponse expectedMultiDeleteResponse = DeleteAclsResponse.create(ImmutableList.of(ALICE_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedAliceUrl).build()).setClusterId(clusterId).build(), BOB_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedBobUrl).build()).setClusterId(clusterId).build()));
    Client webClient = getClient();
    restApp.configureBaseApplication(webClient);
    // KREST-4113 First ensure that a DELETE request without any parameters specified doesn't
    // delete all ACLs, but throws an HTTP 400 Bad Request instead.
    Response multiDeleteNoParamsResponse = webClient.target(restConnect + baseAclUrl).request().accept(MediaType.APPLICATION_JSON).delete();
    assertEquals(Status.BAD_REQUEST.getStatusCode(), multiDeleteNoParamsResponse.getStatus());
    // Then ensure that a DELETE request with the parameters needed to search for and match both
    // ACLs does delete both ACLs at once.
    Response multiDeleteResourceTypeAll = webClient.target(expectedSearchUrl).request().accept(MediaType.APPLICATION_JSON).delete();
    assertEquals(Status.OK.getStatusCode(), multiDeleteResourceTypeAll.getStatus());
    assertEquals(expectedMultiDeleteResponse, multiDeleteResourceTypeAll.readEntity(DeleteAclsResponse.class));
}
Also used : DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Response(javax.ws.rs.core.Response) SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Client(javax.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Example 2 with DeleteAclsResponse

use of io.confluent.kafkarest.entities.v3.DeleteAclsResponse in project kafka-rest by confluentinc.

the class AclsResourceIntegrationTest method testCreateSearchAndSeparateDelete.

@Test
public void testCreateSearchAndSeparateDelete() {
    createAliceAndBobAcls();
    DeleteAclsResponse expectedDeleteAliceResponse = DeleteAclsResponse.create(singletonList(ALICE_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedAliceUrl).build()).setClusterId(clusterId).build()));
    Client webClient = getClient();
    restApp.configureBaseApplication(webClient);
    Response actualDeleteAliceResponse = webClient.target(expectedAliceUrl).request().accept(MediaType.APPLICATION_JSON).delete();
    assertEquals(Status.OK.getStatusCode(), actualDeleteAliceResponse.getStatus());
    assertEquals(expectedDeleteAliceResponse, actualDeleteAliceResponse.readEntity(DeleteAclsResponse.class));
    DeleteAclsResponse expectedDeleteBobResponse = DeleteAclsResponse.create(singletonList(BOB_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedBobUrl).build()).setClusterId(clusterId).build()));
    Response actualDeleteBobResponse = webClient.target(expectedBobUrl).request().accept(MediaType.APPLICATION_JSON).delete();
    assertEquals(Status.OK.getStatusCode(), actualDeleteBobResponse.getStatus());
    assertEquals(expectedDeleteBobResponse, actualDeleteBobResponse.readEntity(DeleteAclsResponse.class));
    SearchAclsResponse expectedPostDeleteSearchResponse = SearchAclsResponse.create(AclDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(expectedSearchUrl).build()).setData(emptyList()).build());
    Response actualPostDeleteSearchResponse = request(baseAclUrl, ImmutableMap.of("resource_type", "topic", "resource_name", "topic-1", "pattern_type", "match")).accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), actualPostDeleteSearchResponse.getStatus());
    assertEquals(expectedPostDeleteSearchResponse, actualPostDeleteSearchResponse.readEntity(SearchAclsResponse.class));
}
Also used : DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Response(javax.ws.rs.core.Response) SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Client(javax.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Example 3 with DeleteAclsResponse

use of io.confluent.kafkarest.entities.v3.DeleteAclsResponse in project kafka-rest by confluentinc.

the class AclsResourceTest method deleteAcl_deletesAndReturnsMatchedAcls.

@Test
public void deleteAcl_deletesAndReturnsMatchedAcls() {
    expect(aclManager.deleteAcls(CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    null, /* host= */
    null, Acl.Operation.ANY, Acl.Permission.ALLOW)).andReturn(completedFuture(Arrays.asList(ACL_1, ACL_2)));
    replay(aclManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    aclsResource.deleteAcls(response, CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    "", /* host= */
    "", Acl.Operation.ANY, Acl.Permission.ALLOW);
    DeleteAclsResponse expected = DeleteAclsResponse.create(Arrays.asList(AclData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=*" + "&pattern_type=LITERAL" + "&principal=User%3Aalice" + "&host=*" + "&operation=READ" + "&permission=ALLOW").build()).setClusterId(CLUSTER_ID).setResourceType(Acl.ResourceType.TOPIC).setResourceName("*").setPatternType(Acl.PatternType.LITERAL).setPrincipal("User:alice").setHost("*").setOperation(Acl.Operation.READ).setPermission(Acl.Permission.ALLOW).build(), AclData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=topic-" + "&pattern_type=PREFIXED" + "&principal=User%3Abob" + "&host=1.2.3.4" + "&operation=WRITE" + "&permission=ALLOW").build()).setClusterId(CLUSTER_ID).setResourceType(Acl.ResourceType.TOPIC).setResourceName("topic-").setPatternType(Acl.PatternType.PREFIXED).setPrincipal("User:bob").setHost("1.2.3.4").setOperation(Acl.Operation.WRITE).setPermission(Acl.Permission.ALLOW).build()));
    assertEquals(expected, response.getValue());
}
Also used : DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Aggregations

DeleteAclsResponse (io.confluent.kafkarest.entities.v3.DeleteAclsResponse)3 Test (org.junit.jupiter.api.Test)3 SearchAclsResponse (io.confluent.kafkarest.entities.v3.SearchAclsResponse)2 Client (javax.ws.rs.client.Client)2 Response (javax.ws.rs.core.Response)2 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1