예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveEmptyDefaultConfigs()
        public virtual void ShouldHaveEmptyDefaultConfigs()
        {
            Config          config     = Config.defaults();
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("x"), equalTo(_empty));
        }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveConfigsWithDefaultProcedureAllowed()
        public virtual void ShouldHaveConfigsWithDefaultProcedureAllowed()
        {
            Config          config     = Config.defaults(default_allowed, "role1");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("x"), equalTo(ArrayOf("role1")));
        }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowFullAccessDefault()
        public virtual void ShouldNotAllowFullAccessDefault()
        {
            Config          config     = Config.defaults();
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.FullAccessFor("x"), equalTo(false));
        }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveConfigsWithExactMatchProcedureAllowed()
        public virtual void ShouldHaveConfigsWithExactMatchProcedureAllowed()
        {
            Config          config     = Config.defaults(stringMap(PROC_ALLOWED_SETTING_DEFAULT_NAME, "role1", PROC_ALLOWED_SETTING_ROLES, "xyz:anotherRole"));
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("xyz"), equalTo(ArrayOf("anotherRole")));
            assertThat(procConfig.RolesFor("abc"), equalTo(ArrayOf("role1")));
        }
예제 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowFullAccessForProcedures()
        public virtual void ShouldAllowFullAccessForProcedures()
        {
            Config          config     = Config.defaults(procedure_unrestricted, "test.procedure.name");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.FullAccessFor("xyzabc"), equalTo(false));
            assertThat(procConfig.FullAccessFor("test.procedure.name"), equalTo(true));
        }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveConfigsWithWildcardProcedureAllowedAndNoDefault()
        public virtual void ShouldHaveConfigsWithWildcardProcedureAllowedAndNoDefault()
        {
            Config          config     = Config.defaults(procedure_roles, "xyz*:anotherRole");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("xyzabc"), equalTo(ArrayOf("anotherRole")));
            assertThat(procConfig.RolesFor("abcxyz"), equalTo(_empty));
        }
예제 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBlockWithWhiteListingForProcedures()
        public virtual void ShouldBlockWithWhiteListingForProcedures()
        {
            Config          config     = Config.defaults(stringMap(procedure_unrestricted.name(), "test.procedure.name, test.procedure.name2", procedure_whitelist.name(), "test.procedure.name"));
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.IsWhitelisted("xyzabc"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("test.procedure.name"), equalTo(true));
            assertThat(procConfig.IsWhitelisted("test.procedure.name2"), equalTo(false));
        }
예제 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSupportSeveralRolesPerPattern()
        public virtual void ShouldSupportSeveralRolesPerPattern()
        {
            Config          config     = Config.defaults(procedure_roles, "xyz*:role1,role2,  role3  ,    role4   ;    abc:  role3   ,role1");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("xyzabc"), equalTo(ArrayOf("role1", "role2", "role3", "role4")));
            assertThat(procConfig.RolesFor("abc"), equalTo(ArrayOf("role3", "role1")));
            assertThat(procConfig.RolesFor("abcxyz"), equalTo(_empty));
        }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreOddRegex()
        public virtual void ShouldIgnoreOddRegex()
        {
            Config          config     = Config.defaults(procedure_whitelist, "[\\db^a]*");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.IsWhitelisted("123"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("b"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("a"), equalTo(false));

            config     = Config.defaults(procedure_whitelist, "(abc)");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("(abc)"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "^$");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("^$"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "\\");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("\\"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "&&");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("&&"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "\\p{Lower}");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("a"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("\\p{Lower}"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "a+");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("aaaaaa"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("a+"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "a|b");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("a"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("b"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("|"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("a|b"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "[a-c]");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("a"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("b"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("c"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("-"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("[a-c]"), equalTo(true));

            config     = Config.defaults(procedure_whitelist, "a\tb");
            procConfig = new ProcedureConfig(config);
            assertThat(procConfig.IsWhitelisted("a    b"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("a\tb"), equalTo(true));
        }
예제 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowWhiteListsWildcardProceduresNames()
        public virtual void ShouldAllowWhiteListsWildcardProceduresNames()
        {
            Config          config     = Config.defaults(procedure_whitelist, " test.procedure.* ,  test.*.otherName");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.IsWhitelisted("xyzabc"), equalTo(false));
            assertThat(procConfig.IsWhitelisted("test.procedure.name"), equalTo(true));
            assertThat(procConfig.IsWhitelisted("test.procedure.otherName"), equalTo(true));
            assertThat(procConfig.IsWhitelisted("test.other.otherName"), equalTo(true));
            assertThat(procConfig.IsWhitelisted("test.other.cool.otherName"), equalTo(true));
            assertThat(procConfig.IsWhitelisted("test.other.name"), equalTo(false));
        }
예제 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveConfigsWithOverlappingMatchingWildcards()
        public virtual void ShouldHaveConfigsWithOverlappingMatchingWildcards()
        {
            Config          config     = Config.defaults(stringMap(PROC_ALLOWED_SETTING_DEFAULT_NAME, "default", PROC_ALLOWED_SETTING_ROLES, "apoc.*:apoc;apoc.load.*:loader;apoc.trigger.*:trigger;apoc.trigger.add:TriggerHappy"));
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("xyz"), equalTo(ArrayOf("default")));
            assertThat(procConfig.RolesFor("apoc.convert.xml"), equalTo(ArrayOf("apoc")));
            assertThat(procConfig.RolesFor("apoc.load.xml"), equalTo(ArrayOf("apoc", "loader")));
            assertThat(procConfig.RolesFor("apoc.trigger.add"), equalTo(ArrayOf("apoc", "trigger", "TriggerHappy")));
            assertThat(procConfig.RolesFor("apoc.trigger.remove"), equalTo(ArrayOf("apoc", "trigger")));
            assertThat(procConfig.RolesFor("apoc.load-xml"), equalTo(ArrayOf("apoc")));
        }
예제 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotLoadAnyProcedureIfConfigIsEmpty() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotLoadAnyProcedureIfConfigIsEmpty()
        {
            // Given
            ProcedureConfig             config            = new ProcedureConfig(Config.defaults(procedure_whitelist, ""));
            Log                         log               = mock(typeof(Log));
            ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), _components, _components, log, config);

            // When
            IList <CallableProcedure> proc = procedureCompiler.CompileProcedure(typeof(SingleReadOnlyProcedure), 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.Count == 0, @is(true));
        }
예제 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreWhiteListingIfFullAccess() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIgnoreWhiteListingIfFullAccess()
        {
            // Given
            ProcedureConfig             config            = new ProcedureConfig(Config.defaults(procedure_whitelist, "empty"));
            Log                         log               = mock(typeof(Log));
            ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), _components, _components, log, config);

            // When
            CallableProcedure proc = procedureCompiler.CompileProcedure(typeof(SingleReadOnlyProcedure), null, true)[0];
            // Then
            RawIterator <object[], ProcedureException> result = proc.Apply(new BasicContext(), new object[0], _resourceTracker);

            assertEquals(result.Next()[0], "Bonnie");
        }
예제 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLoadWhiteListedProcedure() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLoadWhiteListedProcedure()
        {
            // Given
            ProcedureConfig config = new ProcedureConfig(Config.defaults(procedure_whitelist, "org.neo4j.kernel.impl.proc.listCoolPeople"));

            Log log = mock(typeof(Log));
            ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), _components, _components, log, config);

            // When
            CallableProcedure proc = procedureCompiler.CompileProcedure(typeof(SingleReadOnlyProcedure), null, false)[0];
            // When
            RawIterator <object[], ProcedureException> result = proc.Apply(new BasicContext(), new object[0], _resourceTracker);

            // Then
            assertEquals(result.Next()[0], "Bonnie");
        }
예제 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveConfigsWithMultipleWildcardProcedureAllowedAndNoDefault()
        public virtual void ShouldHaveConfigsWithMultipleWildcardProcedureAllowedAndNoDefault()
        {
            Config          config     = Config.defaults(procedure_roles, "apoc.convert.*:apoc_reader;apoc.load.json:apoc_writer;apoc.trigger.add:TriggerHappy");
            ProcedureConfig procConfig = new ProcedureConfig(config);

            assertThat(procConfig.RolesFor("xyz"), equalTo(_empty));
            assertThat(procConfig.RolesFor("apoc.convert.xml"), equalTo(ArrayOf("apoc_reader")));
            assertThat(procConfig.RolesFor("apoc.convert.json"), equalTo(ArrayOf("apoc_reader")));
            assertThat(procConfig.RolesFor("apoc.load.xml"), equalTo(_empty));
            assertThat(procConfig.RolesFor("apoc.load.json"), equalTo(ArrayOf("apoc_writer")));
            assertThat(procConfig.RolesFor("apoc.trigger.add"), equalTo(ArrayOf("TriggerHappy")));
            assertThat(procConfig.RolesFor("apoc.convert-json"), equalTo(_empty));
            assertThat(procConfig.RolesFor("apoc.load-xml"), equalTo(_empty));
            assertThat(procConfig.RolesFor("apoc.load-json"), equalTo(_empty));
            assertThat(procConfig.RolesFor("apoc.trigger-add"), equalTo(_empty));
        }
예제 #16
0
 public Procedures(EmbeddedProxySPI proxySPI, ThrowingConsumer <Procedures, ProcedureException> builtin, File pluginDir, Log log, ProcedureConfig config)
 {
     this._builtin     = builtin;
     this._pluginDir   = pluginDir;
     this._log         = log;
     this._typeMappers = new TypeMappers(proxySPI);
     this._compiler    = new ReflectiveProcedureCompiler(_typeMappers, _safeComponents, _allComponents, log, config);
 }