Search in sources :

Example 66 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class SecurityRulesIT method aComplexWildcardUriPathShould401OnAccessToProtectedSubPath.

@Test
@Title("Using Complex Wildcards to Target Security Rules")
@Documented("In this example, a security rule is registered to deny\n" + "access to all URIs matching a complex pattern.\n" + "The config looks like this:\n" + "\n" + "@@config\n" + "\n" + "with the rule source code of:\n" + "\n" + "@@failingRuleWithComplexWildcardPath")
public void aComplexWildcardUriPathShould401OnAccessToProtectedSubPath() throws Exception {
    String mountPoint = "/protected/wildcard_replacement/x/y/z/something/else/more_wildcard_replacement/a/b/c" + "/final/bit";
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withThirdPartyJaxRsPackage("org.dummy.web.service", mountPoint).withSecurityRules(PermanentlyFailingSecurityRuleWithComplexWildcardPath.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    functionalTestHelper = new FunctionalTestHelper(server);
    JaxRsResponse clientResponse = gen.get().expectedStatus(401).expectedType(MediaType.APPLICATION_JSON_TYPE).expectedHeader("WWW-Authenticate").get(trimTrailingSlash(functionalTestHelper.baseUri()) + mountPoint + "/more/stuff").response();
    assertEquals(401, clientResponse.getStatus());
}
Also used : FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 67 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class AuthenticationIT method missing_authorization.

@Test
@Documented("Missing authorization\n" + "\n" + "If an +Authorization+ header is not supplied, the server will reply with an error.")
public void missing_authorization() throws JsonParseException, IOException {
    // Given
    startServerWithConfiguredUser();
    // Document
    RESTRequestGenerator.ResponseEntity response = gen.get().expectedStatus(401).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").get(dataURL());
    // Then
    JsonNode data = JsonHelper.jsonNode(response.entity());
    JsonNode firstError = data.get("errors").get(0);
    assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
    assertThat(firstError.get("message").asText(), equalTo("No authentication header supplied."));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) RESTRequestGenerator(org.neo4j.server.rest.RESTRequestGenerator) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 68 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class AuthenticationIT method successful_authentication.

@Test
@Documented("Authenticate to access the server\n" + "\n" + "Authenticate by sending a username and a password to Neo4j using HTTP Basic Auth.\n" + "Requests should include an +Authorization+ header, with a value of +Basic <payload>+,\n" + "where \"payload\" is a base64 encoded string of \"username:password\".")
public void successful_authentication() throws JsonParseException, IOException {
    // Given
    startServerWithConfiguredUser();
    // Document
    RESTRequestGenerator.ResponseEntity response = gen.get().expectedStatus(200).withHeader(HttpHeaders.AUTHORIZATION, challengeResponse("neo4j", "secret")).get(userURL("neo4j"));
    // Then
    JsonNode data = JsonHelper.jsonNode(response.entity());
    assertThat(data.get("username").asText(), equalTo("neo4j"));
    assertThat(data.get("password_change_required").asBoolean(), equalTo(false));
    assertThat(data.get("password_change").asText(), equalTo(passwordURL("neo4j")));
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) RESTRequestGenerator(org.neo4j.server.rest.RESTRequestGenerator) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 69 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest method return_results_in_graph_format.

@Test
@Documented("Return results in graph format\n" + "\n" + "If you want to understand the graph structure of nodes and relationships returned by your query,\n" + "you can specify the \"graph\" results data format. For example, this is useful when you want to visualise the\n" + "graph structure. The format collates all the nodes and relationships from all columns of the result,\n" + "and also flattens collections of nodes and relationships, including paths.")
public void return_results_in_graph_format() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{'statements':[{'statement':" + "'CREATE ( bike:Bike { weight: 10 } ) " + "CREATE ( frontWheel:Wheel { spokes: 3 } ) " + "CREATE ( backWheel:Wheel { spokes: 32 } ) " + "CREATE p1 = (bike)-[:HAS { position: 1 } ]->(frontWheel) " + "CREATE p2 = (bike)-[:HAS { position: 2 } ]->(backWheel) " + "RETURN bike, p1, p2', " + "'resultDataContents': ['row','graph']}] }")).post(getDataUri() + "transaction/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Map<String, List<Object>> row = graphRow(result, 0);
    assertEquals(3, row.get("nodes").size());
    assertEquals(2, row.get("relationships").size());
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) ArrayList(java.util.ArrayList) List(java.util.List) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 70 with Documented

use of org.neo4j.kernel.impl.annotations.Documented in project neo4j by neo4j.

the class TransactionTest method rollback_an_open_transaction.

@Test
@Documented("Rollback an open transaction\n" + "\n" + "Given that you have an open transaction, you can send a rollback request. The server will rollback the\n" + "transaction. Any further statements trying to run in this transaction will fail immediately.")
public void rollback_an_open_transaction() throws JsonParseException {
    // Given
    HTTP.Response firstReq = POST(getDataUri() + "transaction", HTTP.RawPayload.quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' } ] }"));
    String location = firstReq.location();
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).delete(location);
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Integer id = resultCell(firstReq, 0, 0);
    assertThat(GET(getNodeUri(id)).status(), is(404));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) HTTP(org.neo4j.test.server.HTTP) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Aggregations

Documented (org.neo4j.kernel.impl.annotations.Documented)71 Test (org.junit.Test)70 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 Graph (org.neo4j.test.GraphDescription.Graph)21 ResponseEntity (org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity)20 Title (org.neo4j.test.TestData.Title)19 Node (org.neo4j.graphdb.Node)14 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Transaction (org.neo4j.graphdb.Transaction)8 RelationshipRepresentationTest (org.neo4j.server.rest.repr.RelationshipRepresentationTest)7 JsonNode (org.codehaus.jackson.JsonNode)6 JaxRsResponse (org.neo4j.server.rest.JaxRsResponse)6 RESTRequestGenerator (org.neo4j.server.rest.RESTRequestGenerator)6 ArrayList (java.util.ArrayList)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 Relationship (org.neo4j.graphdb.Relationship)5 Map (java.util.Map)4 URI (java.net.URI)3 FunctionalTestHelper (org.neo4j.server.helpers.FunctionalTestHelper)3 RestRequest (org.neo4j.server.rest.RestRequest)3