use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.
the class BasicPermissionFetcherTest method getPermissionsReturnsAdminAndReadPermissionsForAdminUserAndDataSet.
@Test
public void getPermissionsReturnsAdminAndReadPermissionsForAdminUserAndDataSet() throws Exception {
VreAuthorization vreAuthorization = mock(VreAuthorization.class);
given(vreAuthorization.hasAdminAccess()).willReturn(true);
given(vreAuthorizationCrud.getAuthorization(anyString(), any(User.class))).willReturn(Optional.of(vreAuthorization));
Set<Permission> permissions = permissionFetcher.getPermissions(mock(User.class), dataSetMetaData);
assertThat(permissions, containsInAnyOrder(Permission.ADMIN, Permission.READ));
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.
the class BasicPermissionFetcherTest method getPermissionsReturnsPermissionsForUserWithWriteAccessInPrivateDataset.
@Test
public void getPermissionsReturnsPermissionsForUserWithWriteAccessInPrivateDataset() throws Exception {
VreAuthorization vreAuthorization = mock(VreAuthorization.class);
given(vreAuthorization.isAllowedToWrite()).willReturn(true);
given(vreAuthorizationCrud.getAuthorization(anyString(), any(User.class))).willReturn(Optional.of(vreAuthorization));
DataSetMetaData dataSetMetaData2 = mock(BasicDataSetMetaData.class);
given(dataSetMetaData2.getDataSetId()).willReturn("testdatasetid");
given(dataSetMetaData2.getOwnerId()).willReturn("testownerid");
given(dataSetMetaData2.isPublished()).willReturn(false);
Set<Permission> permissions = permissionFetcher.getPermissions(userWithId("testWriterId"), dataSetMetaData2);
assertThat(permissions, containsInAnyOrder(Permission.READ, Permission.WRITE));
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.
the class BasicPermissionFetcherTest method getPermissionsDoesNotReturnReadPermissionForUnauthorizedUserInPrivateDataset.
@Test
public void getPermissionsDoesNotReturnReadPermissionForUnauthorizedUserInPrivateDataset() throws Exception {
DataSetMetaData dataSetMetaData2 = mock(BasicDataSetMetaData.class);
given(dataSetMetaData2.getDataSetId()).willReturn("testdatasetid");
given(dataSetMetaData2.getOwnerId()).willReturn("testownerid");
given(dataSetMetaData2.isPublished()).willReturn(false);
Set<Permission> permissions = permissionFetcher.getPermissions(mock(User.class), dataSetMetaData2);
assertThat(permissions, is(empty()));
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.
the class PermissionBasedFieldVisibilityTest method createDataSetWithUserPermissions.
private DataSet createDataSetWithUserPermissions(String combinedId, Set<Permission> permissions) {
DataSetMetaData dataSetMetaData = createDataSetMetadata(combinedId);
given(userPermissionCheck.getPermissions(dataSetMetaData)).willReturn(permissions);
return createDataSet(dataSetMetaData);
}
use of nl.knaw.huygens.timbuctoo.v5.security.dto.Permission in project timbuctoo by HuygensING.
the class UserPermissionCheckTest method getPermissionsReturnsNoPermissionsForEmptyUserIfPublicDataSet.
@Test
public void getPermissionsReturnsNoPermissionsForEmptyUserIfPublicDataSet() {
PermissionFetcher permissionFetcher = mock(PermissionFetcher.class);
Set<Permission> defaultPermissions = Sets.newHashSet(Permission.READ);
UserPermissionCheck userPermissionCheck = new UserPermissionCheck(Optional.empty(), permissionFetcher, defaultPermissions);
DataSetMetaData dataSetMetaData = mock(BasicDataSetMetaData.class);
given(dataSetMetaData.isPublished()).willReturn(true);
Set<Permission> permissions = userPermissionCheck.getPermissions(dataSetMetaData);
assertEquals(Sets.newHashSet(Permission.READ), permissions);
}
Aggregations