Search in sources :

Example 51 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method count.

@WithMockUser(username = USERNAME)
@Test
public void count() {
    String entityType0Name = "entity0";
    EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
    String entityType1Name = "entity1";
    EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
    when(delegateRepository.findAll(new QueryImpl<>().setOffset(0).setPageSize(Integer.MAX_VALUE))).thenReturn(asList(entityType0, entityType1).stream());
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
    assertEquals(repo.count(), 1L);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 52 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method findAllQueryUser.

@WithMockUser(username = USERNAME)
@Test
public void findAllQueryUser() {
    String entityType0Name = "entity0";
    EntityType entityType0 = when(mock(EntityType.class).getId()).thenReturn(entityType0Name).getMock();
    String entityType1Name = "entity1";
    EntityType entityType1 = when(mock(EntityType.class).getId()).thenReturn(entityType1Name).getMock();
    String entityType2Name = "entity2";
    EntityType entityType2 = when(mock(EntityType.class).getId()).thenReturn(entityType2Name).getMock();
    @SuppressWarnings("unchecked") Query q = mock(Query.class);
    @SuppressWarnings("unchecked") ArgumentCaptor<Query> queryCaptor = forClass(Query.class);
    when(delegateRepository.findAll(queryCaptor.capture())).thenReturn(Stream.of(entityType0, entityType1, entityType2));
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType0Name), EntityTypePermission.COUNT);
    doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(entityType1Name), EntityTypePermission.COUNT);
    doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(entityType2Name), EntityTypePermission.COUNT);
    assertEquals(repo.findAll(q).collect(toList()), asList(entityType0, entityType2));
    Query<EntityType> decoratedQ = queryCaptor.getValue();
    assertEquals(decoratedQ.getOffset(), 0);
    assertEquals(decoratedQ.getPageSize(), Integer.MAX_VALUE);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 53 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method deleteSystemEntityType.

@WithMockUser(username = USERNAME)
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "No \\[WRITEMETA\\] permission on EntityType \\[entityTypeId\\]")
public void deleteSystemEntityType() {
    String entityTypeId = "entityTypeId";
    when(systemEntityTypeRegistry.hasSystemEntityType("entityTypeId")).thenReturn(true);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)).thenReturn(true);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn("entityTypeId").getMock();
    repo.delete(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 54 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method add.

@WithMockUser(username = USERNAME)
@Test
public void add() {
    String entityTypeId = "entityTypeId";
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn(entityTypeId).getMock();
    repo.add(entityType);
    verify(delegateRepository).add(entityType);
    verify(mutableAclService).createAcl(new EntityTypeIdentity(entityTypeId));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Example 55 with EntityTypeIdentity

use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.

the class EntityTypeRepositorySecurityDecoratorTest method updateSystemEntityType.

@WithMockUser(username = USERNAME)
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "No \\[WRITEMETA\\] permission on EntityType \\[entityTypeId\\]")
public void updateSystemEntityType() {
    String entityTypeId = "entityTypeId";
    when(systemEntityTypeRegistry.hasSystemEntityType(entityTypeId)).thenReturn(true);
    when(permissionService.hasPermission(new EntityTypeIdentity(entityTypeId), EntityTypePermission.WRITEMETA)).thenReturn(true);
    EntityType entityType = mock(EntityType.class);
    when(entityType.getId()).thenReturn(entityTypeId).getMock();
    repo.update(entityType);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.testng.annotations.Test)

Aggregations

EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)75 Test (org.testng.annotations.Test)57 EntityType (org.molgenis.data.meta.model.EntityType)40 WithMockUser (org.springframework.security.test.context.support.WithMockUser)39 Attribute (org.molgenis.data.meta.model.Attribute)16 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)8 MutableAcl (org.springframework.security.acls.model.MutableAcl)8 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)6 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)6 PrincipalSid (org.springframework.security.acls.domain.PrincipalSid)6 Sid (org.springframework.security.acls.model.Sid)6 Entity (org.molgenis.data.Entity)5 Package (org.molgenis.data.meta.model.Package)5 EntityTypePermissionUtils.getCumulativePermission (org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission)4 QueryImpl (org.molgenis.data.support.QueryImpl)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 File (java.io.File)3 Map (java.util.Map)3 ADD (org.molgenis.data.DatabaseAction.ADD)3 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)3