private ProcedureConfig procedureConfig() { Config config = Config.defaults( procedure_unrestricted, "org.neo4j.kernel.impl.proc.unsafeFullAccess*" ); return new ProcedureConfig( config ); } }
@Test public void shouldNotLoadNoneWhiteListedFunction() throws Throwable { // Given Log log = spy(Log.class); procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), log, new ProcedureConfig( Config.defaults( GraphDatabaseSettings.procedure_whitelist, "WrongName" ) ) ); 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 ) ); }
@Test public void shouldNotLoadNoneWhiteListedFunction() throws Throwable { // Given Log log = spy(Log.class); procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), log, new ProcedureConfig( Config.defaults( GraphDatabaseSettings.procedure_whitelist, "WrongName" ) ) ); List<CallableUserAggregationFunction> method = compile( SingleAggregationFunction.class ); verify( log ).warn( "The function 'org.neo4j.kernel.impl.proc.collectCool' is not on the whitelist and won't be loaded." ); assertThat( method.size(), equalTo( 0 ) ); }
@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( GraphDatabaseSettings.procedure_whitelist, "" ) ) ); 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 ) ); }
@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( GraphDatabaseSettings.procedure_whitelist, "" ) ) ); List<CallableUserAggregationFunction> method = compile( SingleAggregationFunction.class ); verify( log ).warn( "The function 'org.neo4j.kernel.impl.proc.collectCool' is not on the whitelist and won't be loaded." ); assertThat( method.size(), equalTo( 0 ) ); }
@Test public void shouldNotLoadNoneWhiteListedProcedure() throws Throwable { // Given ProcedureConfig config = new ProcedureConfig( Config.defaults( procedure_whitelist, "org.neo4j.kernel.impl.proc.NOTlistCoolPeople" ) ); Log log = mock(Log.class); ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, components, log, config ); // When List<CallableProcedure> proc = procedureCompiler.compileProcedure( SingleReadOnlyProcedure.class, null, false ); // Then verify( log ) .warn( "The procedure 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded." ); assertThat( proc.isEmpty(), is(true) ); }
@Test public void shouldLoadWhiteListedFunction() throws Throwable { // Given procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), NullLog.getInstance(), new ProcedureConfig( Config.defaults( GraphDatabaseSettings.procedure_whitelist, "org.neo4j.kernel.impl.proc.listCoolPeople" ) ) ); CallableUserFunction method = compile( SingleReadOnlyFunction.class ).get( 0 ); // Expect Object out = method.apply( new BasicContext(), new AnyValue[0] ); assertThat(out, equalTo( ValueUtils.of( Arrays.asList("Bonnie", "Clyde") ) ) ); }
@Test public void shouldNotLoadAnyProcedureIfConfigIsEmpty() throws Throwable { // Given ProcedureConfig config = new ProcedureConfig( Config.defaults( procedure_whitelist, "" ) ); Log log = mock(Log.class); ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, components, log, config ); // When List<CallableProcedure> proc = procedureCompiler.compileProcedure( SingleReadOnlyProcedure.class, null, false ); // Then verify( log ) .warn( "The procedure 'org.neo4j.kernel.impl.proc.listCoolPeople' is not on the whitelist and won't be loaded." ); assertThat( proc.isEmpty(), is(true) ); }
@Test public void shouldLoadWhiteListedFunction() throws Throwable { // Given procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, new ComponentRegistry(), NullLog.getInstance(), new ProcedureConfig( Config.defaults( GraphDatabaseSettings.procedure_whitelist, "org.neo4j.kernel.impl.proc.collectCool" ) ) ); CallableUserAggregationFunction method = compile( SingleAggregationFunction.class ).get( 0 ); // Expect UserAggregator created = method.create( new BasicContext() ); created.update( new Object[]{"Bonnie"} ); assertThat(created.result(), equalTo( Collections.singletonList( "Bonnie" ) ) ); }
@Test public void shouldIgnoreWhiteListingIfFullAccess() throws Throwable { // Given ProcedureConfig config = new ProcedureConfig( Config.defaults( procedure_whitelist, "empty" ) ); Log log = mock(Log.class); ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, components, log, config ); // When CallableProcedure proc = procedureCompiler.compileProcedure( SingleReadOnlyProcedure.class, null, true ).get( 0 ); // Then RawIterator<Object[],ProcedureException> result = proc.apply( new BasicContext(), new Object[0], resourceTracker ); assertEquals( result.next()[0], "Bonnie" ); }
@Test public void shouldLoadWhiteListedProcedure() throws Throwable { // Given ProcedureConfig config = new ProcedureConfig( Config.defaults( procedure_whitelist, "org.neo4j.kernel.impl.proc.listCoolPeople" ) ); Log log = mock(Log.class); ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler( new TypeMappers(), components, components, log, config ); // When CallableProcedure proc = procedureCompiler.compileProcedure( SingleReadOnlyProcedure.class, null, false ).get( 0 ); // When RawIterator<Object[],ProcedureException> result = proc.apply( new BasicContext(), new Object[0], resourceTracker ); // Then assertEquals( result.next()[0], "Bonnie" ); }
Log internalLog = platform.logging.getInternalLog( Procedures.class ); ProcedureConfig procedureConfig = new ProcedureConfig( platform.config ); Procedures procedures = new Procedures( facade, new SpecialBuiltInProcedures( Version.getNeo4jVersion(), platform.databaseInfo.edition.toString() ), pluginDir,
Log internalLog = platform.logging.getInternalLog( Procedures.class ); ProcedureConfig procedureConfig = new ProcedureConfig( platform.config ); Procedures procedures = new Procedures( facade, new SpecialBuiltInProcedures( Version.getNeo4jVersion(), platform.databaseInfo.edition.toString() ), pluginDir,