Search in sources :

Example 1 with ResourceAuthorization

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

Example 2 with ResourceAuthorization

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")));
}
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 ResourceAuthorization

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());
}
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 4 with ResourceAuthorization

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

Example 5 with ResourceAuthorization

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

Aggregations

ResourceAuthorization (org.zalando.nakadi.domain.ResourceAuthorization)15 Test (org.junit.Test)14 EventType (org.zalando.nakadi.domain.EventType)7 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)7 ResourceAuthorizationAttribute (org.zalando.nakadi.domain.ResourceAuthorizationAttribute)5 UnableProcessException (org.zalando.nakadi.exceptions.UnableProcessException)4 PluginException (org.zalando.nakadi.plugin.api.PluginException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)1