Search in sources :

Example 6 with CallableUserFunction

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."));
    }
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Test(org.junit.Test)

Example 7 with CallableUserFunction

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")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 8 with CallableUserFunction

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));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.Test)

Example 9 with CallableUserFunction

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")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Example 10 with CallableUserFunction

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")));
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) BasicContext(org.neo4j.kernel.api.proc.BasicContext) Test(org.junit.Test)

Aggregations

CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)17 Test (org.junit.Test)12 BasicContext (org.neo4j.kernel.api.proc.BasicContext)9 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)5 UserFunctionSignature (org.neo4j.kernel.api.proc.UserFunctionSignature)5 Log (org.neo4j.logging.Log)5 NullLog (org.neo4j.logging.NullLog)4 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)3 QualifiedName (org.neo4j.kernel.api.proc.QualifiedName)3 MethodHandle (java.lang.invoke.MethodHandle)2 ComponentInjectionException (org.neo4j.kernel.api.exceptions.ComponentInjectionException)2 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)2 FailedLoadFunction (org.neo4j.kernel.api.proc.FailedLoadFunction)2 FieldSignature (org.neo4j.kernel.api.proc.FieldSignature)2 ProcedureSignature (org.neo4j.kernel.api.proc.ProcedureSignature)2 UserFunction (org.neo4j.procedure.UserFunction)2 MethodHandles (java.lang.invoke.MethodHandles)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 URL (java.net.URL)1