use of org.eclipse.che.multiuser.api.permission.shared.model.Permissions in project che-server by eclipse-che.
the class SetPermissionsFilterTest method shouldRespond403IfUserDoesNotHaveAnyPermissionsForInstance.
@Test
public void shouldRespond403IfUserDoesNotHaveAnyPermissionsForInstance() throws Exception {
final SetPermissionsChecker setPermissionsChecker = mock(SetPermissionsChecker.class);
when(domainsPermissionsCheckers.getSetChecker("test")).thenReturn(setPermissionsChecker);
doThrow(new ForbiddenException("ex")).when(setPermissionsChecker).check(any(Permissions.class));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoFactory.newDto(PermissionsDto.class).withDomainId("test").withInstanceId("test123").withUserId("user123").withActions(Collections.singletonList("read"))).when().post(SECURE_PATH + "/permissions");
assertEquals(response.getStatusCode(), 403);
verifyNoMoreInteractions(permissionsService);
verify(instanceValidator).validate("test", "test123");
verify(setPermissionsChecker, times(1)).check(any(Permissions.class));
}
use of org.eclipse.che.multiuser.api.permission.shared.model.Permissions in project devspaces-images by redhat-developer.
the class SetPermissionsFilterTest method shouldDoChainIfUserHasAnyPermissionsForInstance.
@Test
public void shouldDoChainIfUserHasAnyPermissionsForInstance() throws Exception {
final SetPermissionsChecker setPermissionsChecker = mock(SetPermissionsChecker.class);
when(domainsPermissionsCheckers.getSetChecker("test")).thenReturn(setPermissionsChecker);
doNothing().when(setPermissionsChecker).check(any(Permissions.class));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoFactory.newDto(PermissionsDto.class).withDomainId("test").withInstanceId("test123").withUserId("user123").withActions(Collections.singletonList("read"))).when().post(SECURE_PATH + "/permissions");
assertEquals(response.getStatusCode(), 204);
verify(permissionsService).storePermissions(any());
verify(instanceValidator).validate("test", "test123");
}
use of org.eclipse.che.multiuser.api.permission.shared.model.Permissions in project devspaces-images by redhat-developer.
the class PermissionsManagerTest method shouldNotStorePermissionsWhenItHasUnsupportedAction.
@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Domain with id 'test' doesn't support following action\\(s\\): unsupported")
public void shouldNotStorePermissionsWhenItHasUnsupportedAction() throws Exception {
final Permissions permissions = DtoFactory.newDto(PermissionsDto.class).withUserId("user").withDomainId("test").withInstanceId("test123").withActions(singletonList("unsupported"));
permissionsManager.storePermission(permissions);
}
use of org.eclipse.che.multiuser.api.permission.shared.model.Permissions in project devspaces-images by redhat-developer.
the class PermissionsManagerTest method shouldBeAbleToStorePermissions.
@Test
public void shouldBeAbleToStorePermissions() throws Exception {
final Permissions permissions = DtoFactory.newDto(PermissionsDto.class).withUserId("user").withDomainId("test").withInstanceId("test123").withActions(singletonList(SET_PERMISSIONS));
when(permissionsDao.store(any(TestPermissionsImpl.class))).thenReturn(Optional.empty());
permissionsManager.storePermission(permissions);
verify(permissionsDao).store(new TestDomain().doCreateInstance(permissions.getUserId(), permissions.getDomainId(), permissions.getActions()));
}
use of org.eclipse.che.multiuser.api.permission.shared.model.Permissions in project che-server by eclipse-che.
the class SetPermissionsFilterTest method shouldDoChainIfUserHasAnyPermissionsForInstance.
@Test
public void shouldDoChainIfUserHasAnyPermissionsForInstance() throws Exception {
final SetPermissionsChecker setPermissionsChecker = mock(SetPermissionsChecker.class);
when(domainsPermissionsCheckers.getSetChecker("test")).thenReturn(setPermissionsChecker);
doNothing().when(setPermissionsChecker).check(any(Permissions.class));
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoFactory.newDto(PermissionsDto.class).withDomainId("test").withInstanceId("test123").withUserId("user123").withActions(Collections.singletonList("read"))).when().post(SECURE_PATH + "/permissions");
assertEquals(response.getStatusCode(), 204);
verify(permissionsService).storePermissions(any());
verify(instanceValidator).validate("test", "test123");
}
Aggregations