Search in sources :

Example 6 with Documented

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

the class SecurityRulesIT method should401WithBasicChallengeWhenASecurityRuleFails.

@Test
@Title("Enforcing Server Authorization Rules")
@Documented("In this example, a (dummy) failing security rule is registered to deny\n" + "access to all URIs to the server by listing the rules class in\n" + "'neo4j.conf':\n" + "\n" + "@@config\n" + "\n" + "with the rule source code of:\n" + "\n" + "@@failingRule\n" + "\n" + "With this rule registered, any access to the server will be\n" + "denied. In a production-quality implementation the rule\n" + "will likely lookup credentials/claims in a 3rd-party\n" + "directory service (e.g. LDAP) or in a local database of\n" + "authorized users.")
public void should401WithBasicChallengeWhenASecurityRuleFails() throws Exception {
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withSecurityRules(PermanentlyFailingSecurityRule.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    functionalTestHelper = new FunctionalTestHelper(server);
    JaxRsResponse response = gen.get().expectedStatus(401).expectedHeader("WWW-Authenticate").post(functionalTestHelper.nodeUri()).response();
    assertThat(response.getHeaders().getFirst("WWW-Authenticate"), containsString("Basic realm=\"" + PermanentlyFailingSecurityRule.REALM + "\""));
}
Also used : FunctionalTestHelper(org.neo4j.server.helpers.FunctionalTestHelper) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 7 with Documented

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

the class TransactionTest method execute_multiple_statements.

@Test
@Documented("Execute multiple statements\n" + "\n" + "You can send multiple Cypher statements in the same request.\n" + "The response will contain the result of each statement.")
public void execute_multiple_statements() throws JsonParseException {
    // Document
    ResponseEntity response = gen.get().expectedStatus(200).payload(quotedJson("{ 'statements': [ { 'statement': 'CREATE (n) RETURN id(n)' }, " + "{ 'statement': 'CREATE (n {props}) RETURN n', " + "'parameters': { 'props': { 'name': 'My Node' } } } ] }")).post(getDataUri() + "transaction/commit");
    // Then
    Map<String, Object> result = jsonToMap(response.entity());
    assertNoErrors(result);
    Integer id = resultCell(result, 0, 0);
    assertThat(GET(getNodeUri(id)).status(), is(200));
    assertThat(response.entity(), containsString("My Node"));
}
Also used : ResponseEntity(org.neo4j.server.rest.RESTRequestGenerator.ResponseEntity) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 8 with Documented

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

the class UsersIT method user_status_first_access.

@Test
@Documented("User status on first access\n" + "\n" + "On first access, and using the default password, the user status will indicate that the users password requires changing.")
public void user_status_first_access() throws JsonParseException, IOException {
    // Given
    startServer(true);
    // Document
    RESTRequestGenerator.ResponseEntity response = gen.get().expectedStatus(200).withHeader(HttpHeaders.AUTHORIZATION, challengeResponse("neo4j", "neo4j")).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(true));
    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 9 with Documented

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

the class UsersIT method user_status.

@Test
@Documented("User status\n" + "\n" + "Given that you know the current password, you can ask the server for the user status.")
public void user_status() 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 10 with Documented

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

the class TraverserIT method shouldGetExpectedHitsWhenTraversingAtDepth.

@Documented("Traversal returning nodes below a certain depth.\n" + "\n" + "Here, all nodes at a traversal depth below 3 are returned.")
@Graph({ "Root knows Mattias", "Root knows Johan", "Johan knows Emil", "Emil knows Peter", "Emil knows Tobias", "Tobias loves Sara" })
@Test
public void shouldGetExpectedHitsWhenTraversingAtDepth() throws JsonParseException {
    Node start = getNode("Root");
    String description = createJsonFrom(map("prune_evaluator", map("language", "builtin", "name", "none"), "return_filter", map("language", "javascript", "body", "position.length()<3;")));
    String entity = gen().expectedStatus(200).payload(description).post(getTraverseUriNodes(start)).entity();
    expectNodes(entity, getNodes("Root", "Mattias", "Johan", "Emil"));
}
Also used : Node(org.neo4j.graphdb.Node) Graph(org.neo4j.test.GraphDescription.Graph) 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