Search in sources :

Example 46 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class DataSetRepositoryTest method dataSetsWillBeTheSameAfterRestart.

@Test
public void dataSetsWillBeTheSameAfterRestart() throws Exception {
    final DataSet dataSet = dataSetRepository.createDataSet(User.create(null, "user"), "dataset");
    assertThat(dataSetRepository.dataSetExists(dataSet.getMetadata().getOwnerId(), "dataset"), is(true));
    // create a new instance to simulate a restart
    dataSetRepository = createDataSetRepo();
    dataSetRepository.start();
    assertThat(dataSetRepository.dataSetExists(dataSet.getMetadata().getOwnerId(), "dataset"), is(true));
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Test(org.junit.Test)

Example 47 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class DataSetRepositoryTest method removeDataSetRemovesTheDataSetFromTheIndex.

@Test
public void removeDataSetRemovesTheDataSetFromTheIndex() throws Exception {
    User user = User.create(null, "user");
    final DataSet dataSet = dataSetRepository.createDataSet(user, "dataset");
    given(permissionFetcher.getPermissions(user, dataSet.getMetadata())).willReturn(Sets.newHashSet(Permission.ADMIN));
    dataSetRepository.removeDataSet(dataSet.getMetadata().getOwnerId(), "dataset", user);
    assertThat(dataSetRepository.dataSetExists(dataSet.getMetadata().getOwnerId(), "dataset"), is(false));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Test(org.junit.Test)

Example 48 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class DataSetRepositoryTest method removeDataSetThrowsAnExceptionWhenTheUserHasNoAdminPermissions.

@Test(expected = NotEnoughPermissionsException.class)
public void removeDataSetThrowsAnExceptionWhenTheUserHasNoAdminPermissions() throws Exception {
    User user = User.create(null, "user");
    final DataSet dataSet = dataSetRepository.createDataSet(user, "dataset");
    User userWithOutPermissions = User.create(null, "userWithOutPermissions");
    dataSetRepository.removeDataSet(dataSet.getMetadata().getOwnerId(), "dataset", userWithOutPermissions);
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) Test(org.junit.Test)

Example 49 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class DataSetRepositoryTest method publishDataSetWillReturnDataSetMetaDataWithPublishedFlagSet.

@Test
public void publishDataSetWillReturnDataSetMetaDataWithPublishedFlagSet() throws Exception {
    User user = User.create(null, "user");
    DataSet dataSet = dataSetRepository.createDataSet(user, "dataset");
    DataSetMetaData metadata = dataSet.getMetadata();
    given(permissionFetcher.getPermissions(user, dataSet.getMetadata())).willReturn(Sets.newHashSet(Permission.ADMIN, Permission.READ));
    assertThat(metadata.isPublished(), is(false));
    dataSetRepository.publishDataSet(user, "uuser", "dataset");
    assertThat(metadata.isPublished(), is(true));
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) Test(org.junit.Test)

Example 50 with User

use of nl.knaw.huygens.timbuctoo.v5.security.dto.User in project timbuctoo by HuygensING.

the class AuthCheckTest method checkAdminAccessReturnsAForbiddenResponseIfTheUserIsNotAnAdminForTheDataSet.

@Test
public void checkAdminAccessReturnsAForbiddenResponseIfTheUserIsNotAnAdminForTheDataSet() throws Exception {
    User notOwner = User.create(null, "user");
    UserValidator userValidator = mock(UserValidator.class);
    given(userValidator.getUserFromAccessToken(anyString())).willReturn(Optional.of(notOwner));
    PermissionFetcher permissionFetcher = mock(PermissionFetcher.class);
    given(permissionFetcher.getPermissions(any(User.class), any(BasicDataSetMetaData.class))).willReturn(permissionsForNonAdmin());
    Response response = checkAdminAccess(permissionFetcher, userValidator, "auth", new BasicDataSetMetaData("ownerid", "datasetid", "http://ex.org", "http://example.org/prefix/", false, false));
    assertThat(response.getStatus(), is(FORBIDDEN.getStatusCode()));
}
Also used : Response(javax.ws.rs.core.Response) PermissionFetcher(nl.knaw.huygens.timbuctoo.v5.security.PermissionFetcher) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData) UserValidator(nl.knaw.huygens.timbuctoo.v5.security.UserValidator) Test(org.junit.Test)

Aggregations

User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)42 Test (org.junit.Test)22 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)19 IOException (java.io.IOException)11 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)9 UserValidationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException)7 PermissionFetchingException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.PermissionFetchingException)6 Path (javax.ws.rs.Path)5 Urlset (nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset)5 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)5 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 GET (javax.ws.rs.GET)4 Response (javax.ws.rs.core.Response)4 BasicDataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 GraphQLSchema (graphql.schema.GraphQLSchema)3 Optional (java.util.Optional)3 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)3 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)3