use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class UserPermissionEvaluatorImplTest method hasPermissionOnEntityTypeTrue.
@WithMockUser(username = "USER")
@Test
public void hasPermissionOnEntityTypeTrue() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
when(permissionEvaluator.hasPermission(authentication, "entityType0", "entityType", EntityTypePermission.READ)).thenReturn(true);
assertTrue(userPermissionEvaluator.hasPermission(new EntityTypeIdentity("entityType0"), EntityTypePermission.READ));
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class HasPermissionDirectiveTest method executeWithoutPermission.
@Test
public void executeWithoutPermission() throws TemplateException, IOException {
when(permissionService.hasPermission(new EntityTypeIdentity("entity"), EntityTypePermission.WRITE)).thenReturn(false);
Map<String, Object> params = Maps.newHashMap();
params.put("entityTypeId", "entity");
params.put("permission", "WRITE");
directive.execute(new Environment(fakeTemplate, null, envWriter), params, new TemplateModel[0], out -> out.write("PERMISSION"));
assertEquals(envWriter.toString(), "");
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class StaticContentServiceImplTest method submitContentExisting.
@Test
public void submitContentExisting() {
when(dataService.findOneById(STATIC_CONTENT, "home", StaticContent.class)).thenReturn(staticContent);
doReturn(true).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
assertTrue(this.staticContentService.submitContent("home", "<p>Updated Content!</p>"));
verify(staticContent).setContent("<p>Updated Content!</p>");
verify(dataService).update(STATIC_CONTENT, staticContent);
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class StaticContentServiceImplTest method submitContentNoStaticContentPermissions.
@Test(expectedExceptions = MolgenisDataAccessException.class, expectedExceptionsMessageRegExp = "No write permission on static content entity type.")
public void submitContentNoStaticContentPermissions() {
// doReturn(true).when(permissionService).hasPermission(new PluginIdentity("home"), PluginPermission.WRITE);
doReturn(false).when(permissionService).hasPermission(new EntityTypeIdentity(STATIC_CONTENT), EntityTypePermission.WRITE);
this.staticContentService.submitContent("home", "<p>Updated Content!</p>");
}
use of org.molgenis.data.security.EntityTypeIdentity in project molgenis by molgenis.
the class AppsControllerTest method testInit.
@Test(dataProvider = "testInitProvider")
public void testInit(boolean hasWriteAppPermission) throws Exception {
App app0 = mock(App.class);
when(app0.getId()).thenReturn("id0");
when(app0.getName()).thenReturn("name0");
when(app0.getDescription()).thenReturn("description0");
when(app0.isActive()).thenReturn(true);
when(app0.getIconHref()).thenReturn("/icon0.png");
App app1 = mock(App.class);
when(app1.getId()).thenReturn("id1");
when(app1.getName()).thenReturn("name1");
when(app1.isActive()).thenReturn(false);
@SuppressWarnings("unchecked") Query<App> query = mock(Query.class);
when(dataService.query(APP, App.class)).thenReturn(query);
Sort sort = mock(Sort.class);
when(query.sort()).thenReturn(sort);
when(query.findAll()).thenReturn(Stream.of(app0, app1));
when(permissionService.hasPermission(new EntityTypeIdentity(APP), EntityTypePermission.WRITE)).thenReturn(hasWriteAppPermission);
AppInfoDto appInfoDto0 = AppInfoDto.builder().setId("id0").setName("name0").setDescription("description0").setActive(true).setIconHref(new URI("/icon0.png")).build();
AppInfoDto appInfoDto1 = AppInfoDto.builder().setId("id1").setName("name1").setActive(false).build();
ResultActions resultActions = mockMvc.perform(get(AppsController.URI)).andExpect(status().isOk()).andExpect(view().name("view-apps")).andExpect(model().attribute("appEntityTypeId", APP));
verify(sort).on(AppMetaData.NAME);
if (hasWriteAppPermission) {
resultActions.andExpect(model().attribute("apps", asList(appInfoDto0, appInfoDto1)));
} else {
resultActions.andExpect(model().attribute("apps", singletonList(appInfoDto0)));
}
}
Aggregations