use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeFunction.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable {
//When
List<CallableUserFunction> procList = compiler.compileFunction(FunctionWithUnsafeAPI.class);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldLoadWhiteListedFunction.
@Test
public void shouldLoadWhiteListedFunction() throws Throwable {
// Given
procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), NullLog.getInstance(), new ProcedureConfig(Config.defaults().with(MapUtil.stringMap(GraphDatabaseSettings.procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.listCoolPeople"))));
CallableUserFunction method = compile(SingleReadOnlyFunction.class).get(0);
// Expect
Object out = method.apply(new BasicContext(), new Object[0]);
assertThat(out, equalTo(Arrays.asList("Bonnie", "Clyde")));
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldNotLoadAnyFunctionIfConfigIsEmpty.
@Test
public void shouldNotLoadAnyFunctionIfConfigIsEmpty() throws Throwable {
// Given
Log log = spy(Log.class);
procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, new ComponentRegistry(), log, new ProcedureConfig(Config.defaults().with(MapUtil.stringMap(GraphDatabaseSettings.procedure_whitelist.name(), ""))));
List<CallableUserFunction> method = compile(SingleReadOnlyFunction.class);
verify(log).warn("The function 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded.");
assertThat(method.size(), equalTo(0));
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldRunSimpleReadOnlyFunction.
@Test
public void shouldRunSimpleReadOnlyFunction() throws Throwable {
// Given
CallableUserFunction func = compile(SingleReadOnlyFunction.class).get(0);
// When
Object out = func.apply(new BasicContext(), new Object[0]);
// Then
assertThat(out, equalTo(Arrays.asList("Bonnie", "Clyde")));
}
use of org.neo4j.kernel.api.proc.CallableUserFunction in project neo4j by neo4j.
the class ReflectiveUserFunctionTest method shouldRunClassWithMultipleFunctionsDeclared.
@Test
public void shouldRunClassWithMultipleFunctionsDeclared() throws Throwable {
// Given
List<CallableUserFunction> compiled = compile(ReflectiveUserFunctionTest.MultiFunction.class);
CallableUserFunction bananaPeople = compiled.get(0);
CallableUserFunction coolPeople = compiled.get(1);
// When
Object coolOut = coolPeople.apply(new BasicContext(), new Object[0]);
Object bananaOut = bananaPeople.apply(new BasicContext(), new Object[0]);
// Then
assertThat(coolOut, equalTo(Arrays.asList("Bonnie", "Clyde")));
assertThat(((Map) bananaOut).get("foo"), equalTo(Arrays.asList("bar", "baz")));
}
Aggregations