Search in sources :

Example 11 with ResourceAuthorization

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

the class AuthorizationValidatorTest method whenPluginExceptionInIsAuthorizationAttributeValidThenServiceUnavailableException.

@Test(expected = ServiceTemporarilyUnavailableException.class)
public void whenPluginExceptionInIsAuthorizationAttributeValidThenServiceUnavailableException() throws Exception {
    final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1), ImmutableList.of(attr2), ImmutableList.of(attr3));
    when(authorizationService.isAuthorizationAttributeValid(any())).thenThrow(new PluginException("blah"));
    validator.validateAuthorization(auth);
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) PluginException(org.zalando.nakadi.plugin.api.PluginException) Test(org.junit.Test)

Example 12 with ResourceAuthorization

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

the class AuthorizationValidatorTest method whenAuthorizedThenOk.

@Test
public void whenAuthorizedThenOk() throws Exception {
    when(authorizationService.isAuthorized(any(), any())).thenReturn(true);
    validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) Test(org.junit.Test)

Example 13 with ResourceAuthorization

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

the class AuthorizationValidatorTest method whenETAdminNotAuthorizedButAdminThenOk.

@Test
public void whenETAdminNotAuthorizedButAdminThenOk() throws Exception {
    when(authorizationService.isAuthorized(any(), any())).thenReturn(false);
    when(adminService.isAdmin(any())).thenReturn(true);
    validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) Test(org.junit.Test)

Example 14 with ResourceAuthorization

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

the class AuthorizationValidatorTest method whenInvalidAuthAttributesThenInvalidEventTypeException.

@Test
public void whenInvalidAuthAttributesThenInvalidEventTypeException() throws Exception {
    final ResourceAuthorization auth = new ResourceAuthorization(ImmutableList.of(attr1), ImmutableList.of(attr2), ImmutableList.of(attr3, attr4));
    when(authorizationService.isAuthorizationAttributeValid(attr1)).thenReturn(false);
    when(authorizationService.isAuthorizationAttributeValid(attr2)).thenReturn(true);
    when(authorizationService.isAuthorizationAttributeValid(attr3)).thenReturn(true);
    when(authorizationService.isAuthorizationAttributeValid(attr4)).thenReturn(false);
    try {
        validator.validateAuthorization(auth);
        fail("Exception expected to be thrown");
    } catch (final UnableProcessException e) {
        assertThat(e.getMessage(), equalTo("authorization attribute type1:value1 is invalid, " + "authorization attribute type4:value4 is invalid"));
    }
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) UnableProcessException(org.zalando.nakadi.exceptions.UnableProcessException) Test(org.junit.Test)

Example 15 with ResourceAuthorization

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

the class AuthorizationValidatorTest method whenPluginExceptionInAuthorizeEventTypeUpdateThenServiceTemporaryUnavailableException.

@Test(expected = ServiceTemporarilyUnavailableException.class)
public void whenPluginExceptionInAuthorizeEventTypeUpdateThenServiceTemporaryUnavailableException() throws Exception {
    when(authorizationService.isAuthorized(any(), any())).thenThrow(new PluginException("blah"));
    validator.authorizeEventTypeAdmin(EventTypeTestBuilder.builder().authorization(new ResourceAuthorization(null, null, null)).build());
}
Also used : ResourceAuthorization(org.zalando.nakadi.domain.ResourceAuthorization) PluginException(org.zalando.nakadi.plugin.api.PluginException) 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