コード例 #1
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));
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRedirectRootToBrowser()
        public virtual void ShouldRedirectRootToBrowser()
        {
            assertFalse(Server().baseUri().ToString().Contains("browser"));

            HTTP.Response res = HTTP.withHeaders(HttpHeaders.ACCEPT, MediaType.TEXT_HTML).GET(Server().baseUri().ToString());
            assertThat(res.Header("Location"), containsString("browser"));
        }
コード例 #3
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."));
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetRootWithHTTP()
        public virtual void ShouldGetRootWithHTTP()
        {
            HTTP.Response response = HTTP.withHeaders("Accept", MediaType.TEXT_HTML).GET(_functionalTestHelper.dataUri());
            assertEquals(Status.OK.StatusCode, response.Status());
            AssertValidHtml(response.RawContent());
        }