Search in sources :

Example 1 with ResourceFilteringService

use of com.sequenceiq.authorization.service.list.ResourceFilteringService in project cloudbreak by hortonworks.

the class UtilAuthorizationServiceTest method testHasRightsOnResources.

@Test
public void testHasRightsOnResources() {
    CheckRightOnResourcesV4Request request = new CheckRightOnResourcesV4Request();
    request.setRight(RightV4.DH_DESCRIBE);
    request.setResourceCrns(List.of(DATAHUB_CRN));
    when(entitlementService.listFilteringEnabled(eq("1234"))).thenReturn(true);
    doAnswer(invocation -> ((List<String>) invocation.getArgument(1)).stream().map(crn -> new Resource(crn, Optional.empty())).collect(Collectors.toList())).when(authorizationResourceProvider).findResources(anyString(), anyList());
    doAnswer(invocation -> ((Function<Predicate<String>, List<CheckResourceRightV4Response>>) invocation.getArgument(3)).apply(crn -> true)).when(resourceFilteringService).filter(any(), any(), anyList(), any());
    CheckRightOnResourcesV4Response response = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRightOnResources(request));
    assertEquals(RightV4.DH_DESCRIBE, response.getRight());
    assertEquals(1, response.getResponses().size());
    CheckResourceRightV4Response checkResourceRightV4Response = response.getResponses().get(0);
    assertTrue(checkResourceRightV4Response.isResult());
    assertEquals(DATAHUB_CRN, checkResourceRightV4Response.getResourceCrn());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CheckRightOnResourcesV4Response(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response) CheckRightV4Request(com.sequenceiq.authorization.info.model.CheckRightV4Request) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) ResourceRightsV4(com.sequenceiq.authorization.info.model.ResourceRightsV4) ResourceFilteringService(com.sequenceiq.authorization.service.list.ResourceFilteringService) Mockito.lenient(org.mockito.Mockito.lenient) Function(java.util.function.Function) RightV4(com.sequenceiq.authorization.info.model.RightV4) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Lists(com.google.common.collect.Lists) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Resource(com.sequenceiq.authorization.service.list.Resource) CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AuthorizationProto(com.cloudera.thunderhead.service.authorization.AuthorizationProto) CheckResourceRightsV4Request(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request) ResourceListProvider(com.sequenceiq.authorization.service.list.ResourceListProvider) LinkedList(java.util.LinkedList) CheckResourceRightsV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response) CheckRightOnResourcesV4Request(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request) InjectMocks(org.mockito.InjectMocks) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Predicate(java.util.function.Predicate) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Collectors(java.util.stream.Collectors) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) HasRightOnAny(com.sequenceiq.authorization.service.model.HasRightOnAny) List(java.util.List) Stream(java.util.stream.Stream) CheckResourceRightV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightV4Response) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckRightOnResourcesV4Response(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response) Resource(com.sequenceiq.authorization.service.list.Resource) LinkedList(java.util.LinkedList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) CheckRightOnResourcesV4Request(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CheckResourceRightV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightV4Response) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test)

Aggregations

AuthorizationProto (com.cloudera.thunderhead.service.authorization.AuthorizationProto)1 Lists (com.google.common.collect.Lists)1 CheckResourceRightV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightV4Response)1 CheckResourceRightsV4Request (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request)1 CheckResourceRightsV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response)1 CheckRightOnResourcesV4Request (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request)1 CheckRightOnResourcesV4Response (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response)1 CheckRightV4Request (com.sequenceiq.authorization.info.model.CheckRightV4Request)1 CheckRightV4Response (com.sequenceiq.authorization.info.model.CheckRightV4Response)1 ResourceRightsV4 (com.sequenceiq.authorization.info.model.ResourceRightsV4)1 RightV4 (com.sequenceiq.authorization.info.model.RightV4)1 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)1 Resource (com.sequenceiq.authorization.service.list.Resource)1 ResourceFilteringService (com.sequenceiq.authorization.service.list.ResourceFilteringService)1 ResourceListProvider (com.sequenceiq.authorization.service.list.ResourceListProvider)1 HasRightOnAny (com.sequenceiq.authorization.service.model.HasRightOnAny)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 GrpcUmsClient (com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1