use of com.sequenceiq.authorization.service.model.HasRightOnAll in project cloudbreak by hortonworks.
the class ResourceCrnListAuthorizationFactoryTest method testAuthorization.
@Test
public void testAuthorization() {
when(defaultResourceAuthorizationProvider.authorizeDefaultOrElseCompute(eq(RESOURCE_CRNS), eq(ACTION), any())).then(i -> ((Function) i.getArgument(2)).apply(RESOURCE_CRNS));
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(RESOURCE_CRNS);
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(ACTION, RESOURCE_CRNS));
when(environmentBasedAuthorizationProvider.getAuthorizations(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(), USER_CRN, null, null);
verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceCrnList.class), eq(Collection.class));
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.HasRightOnAll in project cloudbreak by hortonworks.
the class RequestPropertyAuthorizationFactoryTest method testOnNameList.
@Test
public void testOnNameList() {
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new SampleRequestObject(List.of(RESOURCE_NAME)));
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(EDIT_CREDENTIAL, List.of(RESOURCE_CRN)));
when(resourceNameListAuthorizationFactory.calcAuthorization(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(NAME_LIST, EDIT_CREDENTIAL, false, "field"), USER_CRN, null, null);
verify(resourceNameListAuthorizationFactory).calcAuthorization(List.of(RESOURCE_NAME), EDIT_CREDENTIAL);
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.HasRightOnAll in project cloudbreak by hortonworks.
the class RequestPropertyAuthorizationFactoryTest method testOnCrnList.
@Test
public void testOnCrnList() {
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new SampleRequestObject(List.of(RESOURCE_CRN)));
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(EDIT_CREDENTIAL, List.of(RESOURCE_CRN)));
when(resourceCrnListAuthorizationFactory.calcAuthorization(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(CRN_LIST, EDIT_CREDENTIAL, false, "field"), USER_CRN, null, null);
verify(resourceCrnListAuthorizationFactory).calcAuthorization(List.of(RESOURCE_CRN), EDIT_CREDENTIAL);
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.HasRightOnAll in project cloudbreak by hortonworks.
the class ResourceNameListAuthorizationFactoryTest method testAuthorization.
@Test
public void testAuthorization() {
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(RESOURCES);
when(resourceBasedCrnProvider.getResourceCrnListByResourceNameList(anyList())).thenReturn(RESOURCE_CRNS);
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(ACTION, RESOURCE_CRNS));
when(resourceCrnListAuthorizationFactory.calcAuthorization(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(), USER_CRN, null, null);
verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceNameList.class), eq(Collection.class));
verify(resourceCrnListAuthorizationFactory).calcAuthorization(RESOURCE_CRNS, ACTION);
assertEquals(expected, authorization);
}
Aggregations