Search in sources :

Example 76 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class UserAggregationFunctionTest method shouldNotLoadNoneWhiteListedFunction.

@Test
void shouldNotLoadNoneWhiteListedFunction() throws Throwable {
    // Given
    Log log = spy(Log.class);
    procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, new ComponentRegistry(), log, new ProcedureConfig(Config.defaults(GraphDatabaseSettings.procedure_allowlist, List.of("WrongName"))));
    List<CallableUserAggregationFunction> method = compile(SingleAggregationFunction.class);
    verify(log).warn("The function 'org.neo4j.procedure.impl.collectCool' is not on the allowlist and won't be loaded.");
    assertThat(method.size()).isEqualTo(0);
}
Also used : CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.jupiter.api.Test)

Example 77 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class UserFunctionTest method shouldNotLoadNoneWhiteListedFunction.

@Test
void shouldNotLoadNoneWhiteListedFunction() throws Throwable {
    // Given
    Log log = spy(Log.class);
    procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, new ComponentRegistry(), log, new ProcedureConfig(Config.defaults(GraphDatabaseSettings.procedure_allowlist, List.of("WrongName"))));
    List<CallableUserFunction> method = compile(SingleReadOnlyFunction.class);
    verify(log).warn("The function 'org.neo4j.procedure.impl.listCoolPeople' is not on the allowlist and won't be loaded.");
    assertThat(method.size()).isEqualTo(0);
}
Also used : CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) Test(org.junit.jupiter.api.Test)

Example 78 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class ProcedureTest method shouldInjectLogging.

@Test
void shouldInjectLogging() throws KernelException {
    // Given
    Log log = spy(Log.class);
    components.register(Log.class, ctx -> log);
    CallableProcedure procedure = procedureCompiler.compileProcedure(LoggingProcedure.class, null, true).get(0);
    // When
    procedure.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    // Then
    verify(log).debug("1");
    verify(log).info("2");
    verify(log).warn("3");
    verify(log).error("4");
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 79 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class ProcedureTest method shouldNotLoadAnyProcedureIfConfigIsEmpty.

@Test
void shouldNotLoadAnyProcedureIfConfigIsEmpty() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_allowlist, List.of("")));
    Log log = mock(Log.class);
    ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, config);
    // When
    List<CallableProcedure> proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, null, false);
    // Then
    verify(log).warn("The procedure 'org.neo4j.procedure.impl.listCoolPeople' is not on the allowlist and won't be loaded.");
    assertThat(proc.isEmpty()).isTrue();
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Test(org.junit.jupiter.api.Test)

Example 80 with Log

use of org.neo4j.logging.Log in project neo4j by neo4j.

the class ProcedureTest method shouldIgnoreWhiteListingIfFullAccess.

@Test
void shouldIgnoreWhiteListingIfFullAccess() throws Throwable {
    // Given
    ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_allowlist, List.of("empty")));
    Log log = mock(Log.class);
    ProcedureCompiler procedureCompiler = new ProcedureCompiler(new TypeCheckers(), components, components, log, config);
    // When
    CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, null, true).get(0);
    // Then
    RawIterator<AnyValue[], ProcedureException> result = proc.apply(prepareContext(), new AnyValue[0], EMPTY_RESOURCE_TRACKER);
    assertEquals(result.next()[0], stringValue("Bonnie"));
}
Also used : Log(org.neo4j.logging.Log) NullLog(org.neo4j.logging.NullLog) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Aggregations

Log (org.neo4j.logging.Log)164 Test (org.junit.Test)60 NullLog (org.neo4j.logging.NullLog)53 Test (org.junit.jupiter.api.Test)50 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)24 Path (java.nio.file.Path)20 LogProvider (org.neo4j.logging.LogProvider)15 File (java.io.File)13 IOException (java.io.IOException)12 Map (java.util.Map)12 Config (org.neo4j.kernel.configuration.Config)10 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)10 PageCache (org.neo4j.io.pagecache.PageCache)9 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)8 NullLogProvider (org.neo4j.logging.NullLogProvider)7 HashMap (java.util.HashMap)6 Config (org.neo4j.configuration.Config)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)6 BasicContext (org.neo4j.kernel.api.proc.BasicContext)6 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)6