Search in sources :

Example 6 with ResourceAuthorization

use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.

the class AuthorizationValidatorTest method whenDuplicatesThenInvalidEventTypeException.

@Test
public void whenDuplicatesThenInvalidEventTypeException() throws Exception {
    final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1, attr3, attr2, attr1, attr1, attr3), ImmutableList.of(attr3, attr2, attr2), ImmutableList.of(attr3, attr4));
    when(authorizationService.isAuthorizationAttributeValid(any())).thenReturn(true);
    try {
        validator.validateAuthorization(auth);
        fail("Exception expected to be thrown");
    } catch (final UnableProcessException e) {
        assertThat(e.getMessage(), equalTo("authorization property 'admins' contains duplicated attribute(s): type1:value1, type3:value3; " + "authorization property 'readers' contains duplicated attribute(s): type2:value2"));
    }
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Test(org.junit.Test)

Example 7 with ResourceAuthorization

use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.

the class AuthorizationValidator method validateAuthorization.

public void validateAuthorization(final EventType original, final EventTypeBase newEventType) throws UnableProcessException, ServiceTemporarilyUnavailableException {
    final ResourceAuthorization originalAuth = original.getAuthorization();
    final ResourceAuthorization newAuth = newEventType.getAuthorization();
    if (originalAuth != null && newAuth == null) {
        throw new UnableProcessException("Changing authorization object to `null` is not possible due to existing one");
    }
    if (originalAuth != null && originalAuth.equals(newAuth)) {
        return;
    }
    validateAuthorization(newAuth);
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException)

Example 8 with ResourceAuthorization

use of org.zalando.nakadi.domain.ResourceAuthorization 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 9 with ResourceAuthorization

use of org.zalando.nakadi.domain.ResourceAuthorization 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 10 with ResourceAuthorization

use of org.zalando.nakadi.domain.ResourceAuthorization in project nakadi by zalando.

the class EventTypeControllerTest method whenPostAndAuthorizationInvalidThen422.

@Test
public void whenPostAndAuthorizationInvalidThen422() 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"))));
    doThrow(new UnableProcessException("dummy")).when(authorizationValidator).validateAuthorization(any());
    postETAndExpect422WithProblem(eventType, Problem.valueOf(MoreStatus.UNPROCESSABLE_ENTITY, "dummy"));
}
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) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) 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