Search in sources :

Example 1 with Permissions

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));
}
Also used : Response(io.restassured.response.Response) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) PermissionsDto(org.eclipse.che.multiuser.api.permission.shared.dto.PermissionsDto) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions) SetPermissionsChecker(org.eclipse.che.multiuser.api.permission.server.filter.check.SetPermissionsChecker) Test(org.testng.annotations.Test)

Example 2 with Permissions

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");
}
Also used : Response(io.restassured.response.Response) PermissionsDto(org.eclipse.che.multiuser.api.permission.shared.dto.PermissionsDto) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions) SetPermissionsChecker(org.eclipse.che.multiuser.api.permission.server.filter.check.SetPermissionsChecker) Test(org.testng.annotations.Test)

Example 3 with Permissions

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);
}
Also used : AbstractPermissions(org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions) Test(org.testng.annotations.Test)

Example 4 with 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()));
}
Also used : AbstractPermissions(org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions) Test(org.testng.annotations.Test)

Example 5 with Permissions

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");
}
Also used : Response(io.restassured.response.Response) PermissionsDto(org.eclipse.che.multiuser.api.permission.shared.dto.PermissionsDto) Permissions(org.eclipse.che.multiuser.api.permission.shared.model.Permissions) SetPermissionsChecker(org.eclipse.che.multiuser.api.permission.server.filter.check.SetPermissionsChecker) Test(org.testng.annotations.Test)

Aggregations

Permissions (org.eclipse.che.multiuser.api.permission.shared.model.Permissions)12 Test (org.testng.annotations.Test)10 AbstractPermissions (org.eclipse.che.multiuser.api.permission.server.model.impl.AbstractPermissions)8 Response (io.restassured.response.Response)4 SetPermissionsChecker (org.eclipse.che.multiuser.api.permission.server.filter.check.SetPermissionsChecker)4 PermissionsDto (org.eclipse.che.multiuser.api.permission.shared.dto.PermissionsDto)4 ConflictException (org.eclipse.che.api.core.ConflictException)2 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)2 PermissionsRemovedEvent (org.eclipse.che.multiuser.api.permission.server.event.PermissionsRemovedEvent)2