use of org.zalando.nakadi.domain.ResourceAuthorizationAttribute 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.ResourceAuthorizationAttribute 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.ResourceAuthorizationAttribute in project nakadi by zalando.
the class EventTypeAT method whenUpdateETAuthObjectThen422.
@Test
public void whenUpdateETAuthObjectThen422() throws Exception {
final ResourceAuthorization auth = new ResourceAuthorization(Collections.singletonList(new ResourceAuthorizationAttribute("type1", "value1")), Collections.singletonList(new ResourceAuthorizationAttribute("type2", "value2")), Collections.singletonList(new ResourceAuthorizationAttribute("type3", "value3")));
final EventType eventType = EventTypeTestBuilder.builder().authorization(auth).build();
NakadiTestUtils.createEventTypeInNakadi(eventType);
eventType.setAuthorization(null);
given().body(MAPPER.writeValueAsString(eventType)).contentType(JSON).put("/event-types/" + eventType.getName()).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY).body(equalTo(MAPPER.writer().writeValueAsString(Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, "Changing authorization object to `null` is not possible due to existing one"))));
}
use of org.zalando.nakadi.domain.ResourceAuthorizationAttribute in project nakadi by zalando.
the class EventTypeAT method whenPOSTEventTypeWithAuthorizationThenOk.
@Test
public void whenPOSTEventTypeWithAuthorizationThenOk() throws JsonProcessingException {
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"))));
final String body = MAPPER.writer().writeValueAsString(eventType);
given().body(body).header("accept", "application/json").contentType(JSON).when().post(ENDPOINT).then().statusCode(HttpStatus.SC_CREATED);
when().get(String.format("%s/%s", ENDPOINT, eventType.getName())).then().body("authorization.admins[0].data_type", equalTo("type1")).body("authorization.admins[0].value", equalTo("value1")).body("authorization.readers[0].data_type", equalTo("type2")).body("authorization.readers[0].value", equalTo("value2")).body("authorization.writers[0].data_type", equalTo("type3")).body("authorization.writers[0].value", equalTo("value3"));
}
use of org.zalando.nakadi.domain.ResourceAuthorizationAttribute in project nakadi by zalando.
the class AdminServiceTest method whenAddNewAdminCallCreatePermission.
@Test
public void whenAddNewAdminCallCreatePermission() {
when(nakadiSettings.getDefaultAdmin()).thenReturn(defaultAdmin);
when(authorizationDbRepository.listAdmins()).thenReturn(adminList);
doNothing().when(authorizationDbRepository).update(any(), any());
final ArgumentCaptor<List> addCaptor = ArgumentCaptor.forClass(List.class);
final ArgumentCaptor<List> deleteCaptor = ArgumentCaptor.forClass(List.class);
final List<Permission> newList = new ArrayList<>(adminList);
newList.add(new Permission("nakadi", AuthorizationService.Operation.READ, new ResourceAuthorizationAttribute("user", "user42")));
adminService.updateAdmins(newList);
verify(authorizationDbRepository).update(addCaptor.capture(), deleteCaptor.capture());
assertEquals(1, addCaptor.getValue().size());
assertEquals(0, deleteCaptor.getValue().size());
}
Aggregations