use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class AuthorizationValidatorTest method whenPluginExceptionInIsAuthorizationAttributeValidThenServiceUnavailableException.
@Test(expected = ServiceTemporarilyUnavailableException.class)
public void whenPluginExceptionInIsAuthorizationAttributeValidThenServiceUnavailableException() throws Exception {
final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1), ImmutableList.of(attr2), ImmutableList.of(attr3));
when(authorizationService.isAuthorizationAttributeValid(any())).thenThrow(new PluginException("blah"));
validator.validateAuthorization(auth);
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class AuthorizationValidatorTest method whenAuthorizedThenOk.
@Test
public void whenAuthorizedThenOk() throws Exception {
when(authorizationService.isAuthorized(any(), any())).thenReturn(true);
validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class AuthorizationValidatorTest method whenETAdminNotAuthorizedButAdminThenOk.
@Test
public void whenETAdminNotAuthorizedButAdminThenOk() throws Exception {
when(authorizationService.isAuthorized(any(), any())).thenReturn(false);
when(adminService.isAdmin(any())).thenReturn(true);
validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class AuthorizationValidatorTest method whenInvalidAuthAttributesThenInvalidEventTypeException.
@Test
public void whenInvalidAuthAttributesThenInvalidEventTypeException() throws Exception {
final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1), ImmutableList.of(attr2), ImmutableList.of(attr3, attr4));
when(authorizationService.isAuthorizationAttributeValid(attr1)).thenReturn(false);
when(authorizationService.isAuthorizationAttributeValid(attr2)).thenReturn(true);
when(authorizationService.isAuthorizationAttributeValid(attr3)).thenReturn(true);
when(authorizationService.isAuthorizationAttributeValid(attr4)).thenReturn(false);
try {
validator.validateAuthorization(auth);
fail("Exception expected to be thrown");
} catch (final UnableProcessException e) {
assertThat(e.getMessage(), equalTo("authorization attribute type1:value1 is invalid, " + "authorization attribute type4:value4 is invalid"));
}
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class AuthorizationValidatorTest method whenPluginExceptionInAuthorizeEventTypeUpdateThenServiceTemporaryUnavailableException.
@Test(expected = ServiceTemporarilyUnavailableException.class)
public void whenPluginExceptionInAuthorizeEventTypeUpdateThenServiceTemporaryUnavailableException() throws Exception {
when(authorizationService.isAuthorized(any(), any())).thenThrow(new PluginException("blah"));
validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
Aggregations