Search in sources :

Example 1 with ResourceAuthorizationAttribute

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")));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) Test(org.junit.Test)

Example 2 with ResourceAuthorizationAttribute

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());
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) Test(org.junit.Test)

Example 3 with ResourceAuthorizationAttribute

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"))));
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) Test(org.junit.Test)

Example 4 with ResourceAuthorizationAttribute

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"));
}
Also used : TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) TestUtils.resourceAsString(org.zalando.nakadi.utils.TestUtils.resourceAsString) Matchers.containsString(org.hamcrest.Matchers.containsString) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) Test(org.junit.Test)

Example 5 with ResourceAuthorizationAttribute

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());
}
Also used : Permission(org.zalando.nakadi.domain.Permission) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ResourceAuthorizationAttribute(org.zalando.nakadi.domain.ResourceAuthorizationAttribute) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ResourceAuthorizationAttribute (org.zalando.nakadi.domain.ResourceAuthorizationAttribute)6 EventType (org.zalando.nakadi.domain.EventType)5 ResourceAuthorization (org.zalando.nakadi.domain.ResourceAuthorization)5 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Permission (org.zalando.nakadi.domain.Permission)1 UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)1 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)1