Search in sources :

Example 6 with PermissionBasedFieldVisibility

use of nl.knaw.huygens.timbuctoo.v5.graphql.security.PermissionBasedFieldVisibility in project timbuctoo by HuygensING.

the class PermissionBasedFieldVisibilityTest method getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo.

@Test
public void getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo() throws Exception {
    final DataSetRepository dataSetRepository = mock(DataSetRepository.class);
    DataSet dataSet = createDataSetWithUserPermissions("user__dataSetUserHasAccessTo", Sets.newHashSet(Permission.READ));
    DataSet dataSet2 = createDataSetWithUserPermissions("user__dataSetUserDoesNotHasAccessTo", Sets.newHashSet());
    Collection<DataSet> dataSetCollection = Sets.newHashSet(dataSet, dataSet2);
    given(dataSetRepository.getDataSets()).willReturn(dataSetCollection);
    final PermissionBasedFieldVisibility permissionBasedFieldVisibility = new PermissionBasedFieldVisibility(userPermissionCheck, dataSetRepository);
    final GraphQLFieldsContainer graphQlFieldsContainer = createGraphQlFieldsContainer("user__dataSetUserHasAccessTo", "user__dataSetUserDoesNotHasAccessTo");
    List<GraphQLFieldDefinition> retrievedGraphQlFieldDefinitions = permissionBasedFieldVisibility.getFieldDefinitions(graphQlFieldsContainer);
    assertThat(retrievedGraphQlFieldDefinitions, contains(hasProperty("name", is("user__dataSetUserHasAccessTo"))));
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) Test(org.junit.Test)

Aggregations

GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)5 GraphQLFieldsContainer (graphql.schema.GraphQLFieldsContainer)5 DataSetRepository (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository)5 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)5 Test (org.junit.Test)5 ExecutionResult (graphql.ExecutionResult)1 GraphQL (graphql.GraphQL)1 GraphQLSchema (graphql.schema.GraphQLSchema)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 SerializerWriter (nl.knaw.huygens.timbuctoo.v5.dropwizard.contenttypes.SerializerWriter)1 RootData (nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.RootData)1 PermissionBasedFieldVisibility (nl.knaw.huygens.timbuctoo.v5.graphql.security.PermissionBasedFieldVisibility)1 UserPermissionCheck (nl.knaw.huygens.timbuctoo.v5.graphql.security.UserPermissionCheck)1 SerializerExecutionStrategy (nl.knaw.huygens.timbuctoo.v5.graphql.serializable.SerializerExecutionStrategy)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1 UserValidationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException)1 SerializableResult (nl.knaw.huygens.timbuctoo.v5.serializable.SerializableResult)1