Search in sources :

Example 1 with Resource

use of io.lumeer.api.model.Resource in project engine by Lumeer.

the class PermissionsCheckerTest method testCheckDifferentRole.

@Test
public void testCheckDifferentRole() {
    Resource resource = prepareResource(Collections.singleton(Role.WRITE), Collections.singleton(Role.READ));
    assertThatThrownBy(() -> permissionsChecker.checkRole(resource, Role.MANAGE)).isInstanceOf(NoPermissionException.class).hasFieldOrPropertyWithValue("resource", resource);
}
Also used : Resource(io.lumeer.api.model.Resource) NoPermissionException(io.lumeer.core.exception.NoPermissionException) Test(org.junit.Test)

Example 2 with Resource

use of io.lumeer.api.model.Resource in project engine by Lumeer.

the class PermissionsCheckerTest method testGetActualRolesIntersection.

@Test
public void testGetActualRolesIntersection() {
    Resource resource = prepareResource(Sets.newLinkedHashSet(Role.READ, Role.WRITE), Sets.newLinkedHashSet(Role.READ, Role.SHARE));
    Set<Role> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).containsOnly(Role.READ, Role.WRITE, Role.SHARE);
}
Also used : Role(io.lumeer.api.model.Role) Resource(io.lumeer.api.model.Resource) Test(org.junit.Test)

Example 3 with Resource

use of io.lumeer.api.model.Resource in project engine by Lumeer.

the class PermissionsCheckerTest method testGetActualRolesEmpty.

@Test
public void testGetActualRolesEmpty() {
    Resource resource = prepareResource(Collections.emptySet(), Collections.emptySet());
    Set<Role> roles = permissionsChecker.getActualRoles(resource);
    assertThat(roles).isEmpty();
}
Also used : Role(io.lumeer.api.model.Role) Resource(io.lumeer.api.model.Resource) Test(org.junit.Test)

Example 4 with Resource

use of io.lumeer.api.model.Resource in project engine by Lumeer.

the class PermissionsCheckerTest method prepareResource.

private Resource prepareResource(Set<Role> userRoles, Set<Role> groupRoles) {
    Permission userPermission = Mockito.mock(Permission.class);
    Mockito.when(userPermission.getName()).thenReturn(USER);
    Mockito.when(userPermission.getRoles()).thenReturn(userRoles);
    Permission groupPermission = Mockito.mock(Permission.class);
    Mockito.when(groupPermission.getName()).thenReturn(GROUP);
    Mockito.when(groupPermission.getRoles()).thenReturn(groupRoles);
    Permissions permissions = Mockito.mock(Permissions.class);
    Mockito.when(permissions.getUserPermissions()).thenReturn(Collections.singleton(userPermission));
    Mockito.when(permissions.getGroupPermissions()).thenReturn(Collections.singleton(groupPermission));
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.getPermissions()).thenReturn(permissions);
    Mockito.when(resource.getType()).thenReturn(ResourceType.PROJECT);
    return resource;
}
Also used : Permission(io.lumeer.api.model.Permission) Permissions(io.lumeer.api.model.Permissions) Resource(io.lumeer.api.model.Resource)

Example 5 with Resource

use of io.lumeer.api.model.Resource in project engine by Lumeer.

the class OrganizationServiceIT method testGetOrganizations.

@Test
public void testGetOrganizations() {
    createOrganization(CODE1);
    createOrganization(CODE2);
    Response response = client.target(ORGANIZATION_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonOrganization> organizations = response.readEntity(new GenericType<List<JsonOrganization>>() {
    });
    assertThat(organizations).extracting(Resource::getCode).containsOnly(CODE1, CODE2);
    Permissions permissions1 = organizations.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = organizations.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) PaymentGatewayFacade(io.lumeer.core.facade.PaymentGatewayFacade) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) Arquillian(org.jboss.arquillian.junit.Arquillian) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) JsonPermission(io.lumeer.api.dto.JsonPermission) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) OrganizationFacade(io.lumeer.core.facade.OrganizationFacade) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) CompanyContact(io.lumeer.api.model.CompanyContact) ServiceLimits(io.lumeer.api.model.ServiceLimits) Organization(io.lumeer.api.model.Organization) Permission(io.lumeer.api.model.Permission) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Entity(javax.ws.rs.client.Entity) ZoneId(java.time.ZoneId) Payment(io.lumeer.api.model.Payment) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Response(javax.ws.rs.core.Response) Collections(java.util.Collections) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) List(java.util.List) Test(org.junit.Test)

Aggregations

Resource (io.lumeer.api.model.Resource)13 Test (org.junit.Test)12 Role (io.lumeer.api.model.Role)8 Permission (io.lumeer.api.model.Permission)5 Permissions (io.lumeer.api.model.Permissions)5 JsonPermission (io.lumeer.api.dto.JsonPermission)4 JsonPermissions (io.lumeer.api.dto.JsonPermissions)4 Organization (io.lumeer.api.model.Organization)4 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)4 SimplePermission (io.lumeer.core.model.SimplePermission)4 OrganizationDao (io.lumeer.storage.api.dao.OrganizationDao)4 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)4 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Inject (javax.inject.Inject)4 Entity (javax.ws.rs.client.Entity)4