use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class EventTypeControllerTest method whenPostWithNullAuthorizationListThen422.
@Test
public void whenPostWithNullAuthorizationListThen422() throws Exception {
final EventType eventType = buildDefaultEventType();
eventType.setAuthorization(new ResourceAuthorization(null, null, null));
postEventType(eventType).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(containsString("Field \\\"authorization.admins\\\" may not be null"))).andExpect(content().string(containsString("Field \\\"authorization.readers\\\" may not be null"))).andExpect(content().string(containsString("Field \\\"authorization.writers\\\" may not be null")));
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class EventTypeControllerTest method whenPostWithNullAuthAttributesFieldsThen422.
@Test
public void whenPostWithNullAuthAttributesFieldsThen422() throws Exception {
final EventType eventType = buildDefaultEventType();
eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(new ResourceAuthorizationAttribute("type1", "value1")), ImmutableList.of(new ResourceAuthorizationAttribute(null, "value2")), ImmutableList.of(new ResourceAuthorizationAttribute("type3", null))));
postEventType(eventType).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(containsString("Field \\\"authorization.readers[0].data_type\\\" may not be null"))).andExpect(content().string(containsString("Field \\\"authorization.writers[0].value\\\" may not be null")));
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class EventTypeControllerTest method whenPostWithValidAuthorizationThenCreated.
@Test
public void whenPostWithValidAuthorizationThenCreated() throws Exception {
final EventType eventType = buildDefaultEventType();
eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(new ResourceAuthorizationAttribute("type1", "value1")), ImmutableList.of(new ResourceAuthorizationAttribute("type2", "value2")), ImmutableList.of(new ResourceAuthorizationAttribute("type3", "value3"))));
doReturn(eventType).when(eventTypeRepository).saveEventType(any(EventType.class));
when(topicRepository.createTopic(anyInt(), any())).thenReturn(randomUUID.toString());
postEventType(eventType).andExpect(status().isCreated());
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class EventTypeControllerTest method whenPostWithEmptyAuthorizationListThen422.
@Test
public void whenPostWithEmptyAuthorizationListThen422() throws Exception {
final EventType eventType = buildDefaultEventType();
eventType.setAuthorization(new ResourceAuthorization(ImmutableList.of(), ImmutableList.of(), ImmutableList.of()));
postEventType(eventType).andExpect(status().isUnprocessableEntity()).andExpect(content().contentType("application/problem+json")).andExpect(content().string(containsString("Field \\\"authorization.admins\\\" must contain at least one attribute"))).andExpect(content().string(containsString("Field \\\"authorization.readers\\\" must contain at least one attribute"))).andExpect(content().string(containsString("Field \\\"authorization.writers\\\" must contain at least one attribute")));
}
use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.
the class AuthorizationValidatorTest method whenNotAuthorizedThenForbiddenAccessException.
@Test(expected = AccessDeniedException.class)
public void whenNotAuthorizedThenForbiddenAccessException() throws Exception {
when(authorizationService.isAuthorized(any(), any())).thenReturn(false);
validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
Aggregations