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