Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotKillQueryIfNotAuthenticated() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotKillQueryIfNotAuthenticated()
        {
            EnterpriseLoginContext unAuthSubject = CreateFakeAnonymousEnterpriseLoginContext();

            GraphDatabaseFacade graph = Neo.LocalGraph;
            DoubleLatch         latch = new DoubleLatch(2);
            ThreadedTransaction <EnterpriseLoginContext> read = new ThreadedTransaction <EnterpriseLoginContext>(Neo, latch);
            string query = read.Execute(ThreadingConflict, ReadSubject, "UNWIND [1,2,3] AS x RETURN x");

            latch.StartAndWaitForAllToStart();

            string id = ExtractQueryId(query);

            try
            {
                using (InternalTransaction tx = graph.BeginTransaction(KernelTransaction.Type.@explicit, unAuthSubject))
                {
                    graph.execute(tx, "CALL dbms.killQuery('" + id + "')", EMPTY_MAP);
                    throw new AssertionError("Expected exception to be thrown");
                }
            }
            catch (QueryExecutionException e)
            {
                assertThat(e.Message, containsString(PERMISSION_DENIED));
            }

            latch.FinishAndWaitForAllToFinish();
            read.CloseAndAssertSuccess();
        }
Example #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertKeepAuthorizationForLifetimeOfTransaction(String username, System.Action<org.neo4j.driver.v1.Transaction> assertion) throws Throwable
        private void AssertKeepAuthorizationForLifetimeOfTransaction(string username, System.Action <Transaction> assertion)
        {
            DoubleLatch latch = new DoubleLatch(2);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Throwable[] threadFail = {null};
            Exception[] threadFail = new Exception[] { null };

            Thread readerThread = new Thread(() =>
            {
                try
                {
                    using (Driver driver = ConnectDriver(username, "abc123"), Session session = driver.session(), Transaction tx = session.beginTransaction())
                    {
                        assertion(tx);
                        latch.StartAndWaitForAllToStart();
                        latch.FinishAndWaitForAllToFinish();
                        assertion(tx);
                        tx.success();
                    }
                }
                catch (Exception t)
                {
                    threadFail[0] = t;
                    // Always release the latch so we get the failure in the main thread
                    latch.Start();
                    latch.Finish();
                }
            });

            readerThread.Start();
            latch.StartAndWaitForAllToStart();

            ClearAuthCacheFromDifferentConnection();

            latch.FinishAndWaitForAllToFinish();

            readerThread.Join();
            if (threadFail[0] != null)
            {
                throw threadFail[0];
            }
        }
Example #3
0
        // --------------------- helpers -----------------------
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void shouldTerminateTransactionsForUser(S subject, String procedure) throws Throwable
        internal virtual void ShouldTerminateTransactionsForUser(S subject, string procedure)
        {
            DoubleLatch             latch      = new DoubleLatch(2);
            ThreadedTransaction <S> userThread = new ThreadedTransaction <S>(Neo, latch);

            userThread.ExecuteCreateNode(Threading(), subject);
            latch.StartAndWaitForAllToStart();

            AssertEmpty(AdminSubject, "CALL " + format(procedure, Neo.nameOf(subject)));

            IDictionary <string, long> transactionsByUser = CountTransactionsByUsername();

            assertThat(transactionsByUser[Neo.nameOf(subject)], equalTo(null));

            latch.FinishAndWaitForAllToFinish();

            userThread.CloseAndAssertExplicitTermination();

            AssertEmpty(AdminSubject, "MATCH (n:Test) RETURN n.name AS name");
        }
Example #4
0
        /*
         * Admin creates user Henrik with password bar
         * Admin adds user Henrik to role Publisher
         * Henrik logs in with correct password
         * Henrik starts transaction with long running writing query Q
         * Admin removes user Henrik from role Publisher (while Q still running)
         * Q finishes and transaction is committed → ok
         * Henrik starts new transaction with write query → permission denied
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void roleManagement5() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RoleManagement5()
        {
            AssertEmpty(AdminSubject, "CALL dbms.security.createUser('Henrik', 'bar', false)");
            AssertEmpty(AdminSubject, "CALL dbms.security.addRoleToUser('" + PUBLISHER + "', 'Henrik')");
            S henrik = Neo.login("Henrik", "bar");

            Neo.assertAuthenticated(henrik);

            DoubleLatch             latch = new DoubleLatch(2);
            ThreadedTransaction <S> write = new ThreadedTransaction <S>(Neo, latch);

            write.ExecuteCreateNode(ThreadingConflict, henrik);
            latch.StartAndWaitForAllToStart();

            AssertEmpty(AdminSubject, "CALL dbms.security.removeRoleFromUser('" + PUBLISHER + "', 'Henrik')");

            latch.FinishAndWaitForAllToFinish();

            write.CloseAndAssertSuccess();
            TestFailWrite(henrik);
        }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTerminateQueriesEvenIfUsingPeriodicCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTerminateQueriesEvenIfUsingPeriodicCommit()
        {
            // Spawns a throttled HTTP server, runs a PERIODIC COMMIT that fetches data from this server,
            // and checks that the query able to be terminated

            // We start with 3, because that is how many actors we have -
            // 1. the http server
            // 2. the running query
            // 3. the one terminating 2
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.DoubleLatch latch = new org.neo4j.test.DoubleLatch(3, true);
            DoubleLatch latch = new DoubleLatch(3, true);

            // This is used to block the http server between the first and second batch
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control();
            Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control();

            // Serve CSV via local web server, let Jetty find a random port for us
            Server server = CreateHttpServer(latch, barrier, 20, 30);

            server.start();
            int localPort = GetLocalPort(server);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.bolt.runtime.BoltStateMachine[] machine = {null};
            BoltStateMachine[] machine = new BoltStateMachine[] { null };

            Thread thread = new Thread(() =>
            {
                try
                {
                    using (BoltStateMachine stateMachine = Env.newMachine(_boltChannel))
                    {
                        machine[0] = stateMachine;
                        stateMachine.process(new InitMessage(USER_AGENT, emptyMap()), nullResponseHandler());
                        string query = format("USING PERIODIC COMMIT 10 LOAD CSV FROM 'http://localhost:%d' AS line " + "CREATE (n:A {id: line[0], square: line[1]}) " + "WITH count(*) as number " + "CREATE (n:ShouldNotExist)", localPort);
                        try
                        {
                            latch.Start();
                            stateMachine.process(new RunMessage(query, EMPTY_MAP), nullResponseHandler());
                            stateMachine.process(PullAllMessage.INSTANCE, nullResponseHandler());
                        }
                        finally
                        {
                            latch.Finish();
                        }
                    }
                }
                catch (BoltConnectionFatality connectionFatality)
                {
                    throw new Exception(connectionFatality);
                }
            });

            thread.Name = "query runner";
            thread.Start();

            // We block this thread here, waiting for the http server to spin up and the running query to get started
            latch.StartAndWaitForAllToStart();
            Thread.Sleep(1000);

            // This is the call that RESETs the Bolt connection and will terminate the running query
            machine[0].Process(ResetMessage.INSTANCE, nullResponseHandler());

            barrier.Release();

            // We block again here, waiting for the running query to have been terminated, and for the server to have
            // wrapped up and finished streaming http results
            latch.FinishAndWaitForAllToFinish();

            // And now we check that the last node did not get created
            using (Transaction ignored = Env.graph().beginTx())
            {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse("Query was not terminated in time - nodes were created!", Env.graph().findNodes(Label.label("ShouldNotExist")).hasNext());
            }
        }