Esempio n. 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));
        }