Search in sources :

Example 1 with FunctionAuthoriser

use of uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser in project Gaffer by gchq.

the class GraphTest method shouldNotAddDefaultSecurityHooksIfAlreadyAdded.

@Test
public void shouldNotAddDefaultSecurityHooksIfAlreadyAdded() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStore.class.getName());
    TestStore.mockStore = mock(Store.class);
    given(TestStore.mockStore.isSupported(NamedOperation.class)).willReturn(true);
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId("test").addHook(new FunctionAuthoriser(Lists.newArrayList(Identity.class))).build();
    final Graph graph = new Graph.Builder().addSchemas(StreamUtil.schemas(getClass())).storeProperties(storeProperties).config(config).build();
    // Then
    assertEquals(Arrays.asList(NamedOperationResolver.class, NamedViewResolver.class, FunctionAuthoriser.class), graph.getGraphHooks());
    assertEquals(Identity.class, ((FunctionAuthoriser) graph.getConfig().getHooks().get(2)).getUnauthorisedFunctions().get(0));
}
Also used : NamedOperationResolver(uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Identity(uk.gov.gchq.koryphe.impl.function.Identity) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 2 with FunctionAuthoriser

use of uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser in project Gaffer by gchq.

the class GraphTest method shouldCloseAllOperationInputsWhenExceptionIsThrownWhenExecuted.

@Test
public void shouldCloseAllOperationInputsWhenExceptionIsThrownWhenExecuted() throws OperationException, IOException {
    // Given
    final Exception exception = mock(RuntimeException.class);
    final Store store = mock(Store.class);
    given(store.execute(clonedOpChain, clonedContext)).willThrow(exception);
    final Schema schema = new Schema();
    given(store.getSchema()).willReturn(schema);
    given(store.getProperties()).willReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(// skips json serialisation in default hook
    new FunctionAuthoriser()).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(new Schema.Builder().build()).build();
    // When / Then
    try {
        graph.execute(opChain, context);
        fail("Exception expected");
    } catch (final Exception e) {
        assertSame(exception, e);
        verify(clonedOpChain).close();
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) IOException(java.io.IOException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) URISyntaxException(java.net.URISyntaxException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 3 with FunctionAuthoriser

use of uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser in project Gaffer by gchq.

the class GraphTest method shouldCloseAllOperationInputsWhenExceptionIsThrownWhenJobExecuted.

@Test
public void shouldCloseAllOperationInputsWhenExceptionIsThrownWhenJobExecuted() throws OperationException, IOException {
    // Given
    final Exception exception = mock(RuntimeException.class);
    final Store store = mock(Store.class);
    given(store.executeJob(clonedOpChain, clonedContext)).willThrow(exception);
    final Schema schema = new Schema();
    given(store.getSchema()).willReturn(schema);
    given(store.getProperties()).willReturn(new StoreProperties());
    final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(// skips json serialisation in default hook
    new FunctionAuthoriser()).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(new Schema.Builder().build()).build();
    // When / Then
    try {
        graph.executeJob(opChain, context);
        fail("Exception expected");
    } catch (final Exception e) {
        assertSame(exception, e);
        verify(clonedOpChain).close();
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) IOException(java.io.IOException) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) URISyntaxException(java.net.URISyntaxException) OperationException(uk.gov.gchq.gaffer.operation.OperationException) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Example 4 with FunctionAuthoriser

use of uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser in project Gaffer by gchq.

the class GraphSerialisableTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    config = new GraphConfig.Builder().graphId("testGraphId").addHook(new NamedViewResolver()).addHook(new FunctionAuthoriser(FunctionAuthoriserUtil.DEFAULT_UNAUTHORISED_FUNCTIONS)).view(new View.Builder().entity("e1").build()).build();
    schema = new Schema.Builder().entity("e1", new SchemaEntityDefinition.Builder().vertex("string").build()).type("string", String.class).build();
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStore.class);
    properties = storeProperties.getProperties();
    expected = new GraphSerialisable.Builder().schema(schema).properties(properties).config(config).build();
}
Also used : Builder(uk.gov.gchq.gaffer.graph.GraphSerialisable.Builder) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Builder(uk.gov.gchq.gaffer.graph.GraphSerialisable.Builder) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with FunctionAuthoriser

use of uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser in project Gaffer by gchq.

the class GraphTest method shouldAddDefaultSecurityHooksIfNotAddedToHooks.

@Test
public void shouldAddDefaultSecurityHooksIfNotAddedToHooks() {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStore.class.getName());
    TestStore.mockStore = mock(Store.class);
    given(TestStore.mockStore.isSupported(NamedOperation.class)).willReturn(true);
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId("test").build();
    final Graph graph = new Graph.Builder().addSchemas(StreamUtil.schemas(getClass())).storeProperties(storeProperties).config(config).build();
    // Then
    assertEquals(Arrays.asList(NamedOperationResolver.class, NamedViewResolver.class, FunctionAuthoriser.class), graph.getGraphHooks());
    assertEquals(CreateObject.class, ((FunctionAuthoriser) graph.getConfig().getHooks().get(2)).getUnauthorisedFunctions().get(0));
}
Also used : NamedOperationResolver(uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) Test(org.junit.jupiter.api.Test)

Aggregations

FunctionAuthoriser (uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser)6 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)5 Test (org.junit.jupiter.api.Test)4 NamedViewResolver (uk.gov.gchq.gaffer.graph.hook.NamedViewResolver)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 Store (uk.gov.gchq.gaffer.store.Store)4 IOException (java.io.IOException)2 URISyntaxException (java.net.URISyntaxException)2 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 NamedOperationResolver (uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)2 Builder (uk.gov.gchq.gaffer.graph.GraphSerialisable.Builder)1 Identity (uk.gov.gchq.koryphe.impl.function.Identity)1