//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)); }
//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")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void testCorsAllowMethods(org.neo4j.server.web.HttpMethod method, String origin) throws Exception private void TestCorsAllowMethods(HttpMethod method, string origin) { HTTP.Builder requestBuilder = RequestWithHeaders("authDisabled", "authDisabled").withHeaders(ACCESS_CONTROL_REQUEST_METHOD, method.ToString()); HTTP.Response response = RunQuery(requestBuilder); assertEquals(OK.StatusCode, response.Status()); AssertCorsHeaderEquals(response, origin); assertEquals(method, HttpMethod.valueOf(response.Header(ACCESS_CONTROL_ALLOW_METHODS))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAddCorsRequestHeaders() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAddCorsRequestHeaders() { StartServer(false); HTTP.Builder requestBuilder = RequestWithHeaders("authDisabled", "authDisabled").withHeaders(ACCESS_CONTROL_REQUEST_HEADERS, "Accept, X-Not-Accept"); HTTP.Response response = RunQuery(requestBuilder); assertEquals(OK.StatusCode, response.Status()); AssertCorsHeaderPresent(response); assertEquals("Accept, X-Not-Accept", response.Header(ACCESS_CONTROL_ALLOW_HEADERS)); }
private static void AssertCorsHeaderEquals(HTTP.Response response, string origin) { assertEquals(origin, response.Header(ACCESS_CONTROL_ALLOW_ORIGIN)); }