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));
}
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();
}
}
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();
}
}
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();
}
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));
}
Aggregations