Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportEnterpriseEdition() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReportEnterpriseEdition()
        {
            // Given
            string releaseVersion = Server.Database.Graph.DependencyResolver.resolveDependency(typeof(KernelData)).version().ReleaseVersion;

            // When
            HTTP.Response res = HTTP.GET(FunctionalTestHelper.managementUri() + "/" + VersionAndEditionService.SERVER_PATH);

            // Then
            assertEquals(200, res.Status());
            assertThat(res.Get("edition").asText(), equalTo("enterprise"));
            assertThat(res.Get("version").asText(), equalTo(releaseVersion));
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSayMalformedHeaderIfMalformedAuthorization() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSayMalformedHeaderIfMalformedAuthorization()
        {
            // Given
            StartServerWithConfiguredUser();

            // When
            HTTP.Response response = HTTP.withHeaders(HttpHeaders.AUTHORIZATION, "This makes no sense").GET(DataURL());

            // Then
            assertThat(response.Status(), equalTo(400));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Request.InvalidFormat"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("Invalid authentication header."));
        }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReplyNicelyToTooManyFailedAuthAttempts() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReplyNicelyToTooManyFailedAuthAttempts()
        {
            // Given
            StartServerWithConfiguredUser();
            long timeout = DateTimeHelper.CurrentUnixTimeMillis() + 30_000;

            // When
            HTTP.Response response = null;
            while (DateTimeHelper.CurrentUnixTimeMillis() < timeout)
            {
                // Done in a loop because we're racing with the clock to get enough failed requests into 5 seconds
                response = HTTP.withBasicAuth("neo4j", "incorrect").POST(Server.baseUri().resolve("authentication").ToString(), HTTP.RawPayload.quotedJson("{'username':'******', 'password':'******'}"));

                if (response.Status() == 429)
                {
                    break;
                }
            }

            // Then
            assertThat(response.Status(), equalTo(429));
            JsonNode firstError = response.Get("errors").get(0);

            assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.AuthenticationRateLimit"));
            assertThat(firstError.get("message").asText(), equalTo("Too many failed authentication requests. Please wait 5 seconds and try again."));
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.codehaus.jackson.JsonNode getSingleData(org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException
        private static JsonNode GetSingleData(HTTP.Response response)
        {
            JsonNode data = response.Get("results").get(0).get("data");

            assertEquals(1, data.size());
            return(data.get(0));
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleArrayOfPointsUsingGraphResultDataContent() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleArrayOfPointsUsingGraphResultDataContent()
        {
            //Given
            GraphDatabaseFacade db = Server().Database.Graph;

            using (Transaction tx = Db.beginTx())
            {
                Node node = Db.createNode(label("N"));
                node.SetProperty("coordinates", new Point[] { pointValue(WGS84, 30.655691, 104.081602) });
                tx.Success();
            }

            //When
            HTTP.Response response = RunQuery("MATCH (n:N) RETURN n", "graph");

            assertEquals(200, response.Status());
            AssertNoErrors(response);

            //Then
            JsonNode row = response.Get("results").get(0).get("data").get(0).get("graph").get("nodes").get(0).get("properties").get("coordinates").get(0);

            AssertGeometryTypeEqual(GeometryType.GEOMETRY_POINT, row);
            AssertCoordinatesEqual(new double[] { 30.655691, 104.081602 }, row);
            AssertCrsEqual(WGS84, row);
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void assertTypeEqual(String expectedType, org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException
        private static void AssertTypeEqual(string expectedType, HTTP.Response response)
        {
            JsonNode data = response.Get("results").get(0).get("data");
            JsonNode meta = data.get(0).get("meta");

            assertEquals(1, meta.size());
            assertEquals(expectedType, meta.get(0).get("type").asText());
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.codehaus.jackson.JsonNode extractSingleElement(org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException
        private static JsonNode ExtractSingleElement(HTTP.Response response)
        {
            JsonNode data = response.Get("results").get(0).get("data");

            assertEquals(1, data.size());
            JsonNode row = data.get(0).get("row");

            assertEquals(1, row.size());
            return(row.get(0));
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void txEndpointShouldReplyWithHttpsWhenItReturnsURLs() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TxEndpointShouldReplyWithHttpsWhenItReturnsURLs()
        {
            StartServer();

            string baseUri = _server.baseUri().ToString();

            HTTP.Response response = POST(baseUri + "db/data/transaction", quotedJson("{'statements':[]}"));

            assertThat(response.Location(), startsWith(baseUri));
            assertThat(response.Get("commit").asText(), startsWith(baseUri));
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertAuthorizationRequired(String method, String path, Object payload, int expectedAuthorizedStatus) throws org.neo4j.server.rest.domain.JsonParseException
        private void AssertAuthorizationRequired(string method, string path, object payload, int expectedAuthorizedStatus)
        {
            // When no header
            HTTP.Response response = HTTP.request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(401));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("No authentication header supplied."));
            assertThat(response.Header(HttpHeaders.WWW_AUTHENTICATE), equalTo("Basic realm=\"Neo4j\""));

            // When malformed header
            response = HTTP.withHeaders(HttpHeaders.AUTHORIZATION, "This makes no sense").request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(400));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Request.InvalidFormat"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("Invalid authentication header."));

            // When invalid credential
            response = HTTP.withBasicAuth("neo4j", "incorrect").request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(401));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("Invalid username or password."));
            assertThat(response.Header(HttpHeaders.WWW_AUTHENTICATE), equalTo("Basic realm=\"Neo4j\""));

            // When authorized
            response = HTTP.withBasicAuth("neo4j", "secret").request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(expectedAuthorizedStatus));
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnReadOnlyStatusWhenCreatingNodes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnReadOnlyStatusWhenCreatingNodes()
        {
            // Given
            HTTP.Response response = _http.POST("db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': 'CREATE (node)' } ] }"));

            // Then
            JsonNode error   = response.Get("errors").get(0);
            string   code    = error.get("code").asText();
            string   message = error.get("message").asText();

            assertEquals("Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code);
            assertThat(message, containsString("This is a read only Neo4j instance"));
        }
Exemplo n.º 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static boolean containsError(org.neo4j.test.server.HTTP.Response response) throws org.neo4j.server.rest.domain.JsonParseException
        private static bool ContainsError(HTTP.Response response)
        {
            return(response.Get("errors").GetEnumerator().hasNext());
        }