Search in sources :

Example 31 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class AuthenticationIT method password_change_required.

@Test
@Documented("Required password changes\n" + "\n" + "In some cases, like the very first time Neo4j is accessed, the user will be required to choose\n" + "a new password. The database will signal that a new password is required and deny access.\n" + "\n" + "See <<rest-api-security-user-status-and-password-changing>> for how to set a new password.")
public void password_change_required() throws JsonParseException, IOException {
    // Given
    startServer(true);
    // Document
    RESTRequestGenerator.ResponseEntity response = gen.get().expectedStatus(403).withHeader(HttpHeaders.AUTHORIZATION, challengeResponse("neo4j", "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.Forbidden"));
    assertThat(firstError.get("message").asText(), equalTo("User is required to change their password."));
    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 32 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class GraphExtractionWriterTest method assertNode.

// Helpers
private static void assertNode(String id, JsonNode nodes, List<String> labels, Property... properties) {
    JsonNode node = get(nodes, id);
    assertListEquals("Node[" + id + "].labels", labels, node.get("labels"));
    JsonNode props = node.get("properties");
    assertEquals("length( Node[" + id + "].properties )", properties.length, props.size());
    for (Property property : properties) {
        assertJsonEquals("Node[" + id + "].properties[" + property.key() + "]", property.value(), props.get(property.key()));
    }
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) Property(org.neo4j.test.Property)

Example 33 with JsonNode

use of org.codehaus.jackson.JsonNode 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 34 with JsonNode

use of org.codehaus.jackson.JsonNode 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 35 with JsonNode

use of org.codehaus.jackson.JsonNode in project neo4j by neo4j.

the class RestRepresentationWriterTests method shouldWriteNestedMaps.

@Test
public void shouldWriteNestedMaps() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JsonGenerator json = new JsonFactory(new Neo4jJsonCodec()).createJsonGenerator(out);
    JsonNode rest = serialize(out, json, new RestRepresentationWriter(URI.create("localhost")));
    MatcherAssert.assertThat(rest.size(), equalTo(1));
    JsonNode firstCell = rest.get(0);
    MatcherAssert.assertThat(firstCell.get("one").get("two").size(), is(2));
    MatcherAssert.assertThat(firstCell.get("one").get("two").get(0).asBoolean(), is(true));
    MatcherAssert.assertThat(firstCell.get("one").get("two").get(1).get("three").asInt(), is(42));
}
Also used : JsonFactory(org.codehaus.jackson.JsonFactory) JsonGenerator(org.codehaus.jackson.JsonGenerator) JsonNode(org.codehaus.jackson.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

JsonNode (org.codehaus.jackson.JsonNode)200 Test (org.junit.Test)55 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)50 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 HTTP (org.neo4j.test.server.HTTP)18 Resource (com.netflix.simianarmy.Resource)17 AWSResource (com.netflix.simianarmy.aws.AWSResource)17 ObjectNode (org.codehaus.jackson.node.ObjectNode)15 Response (org.neo4j.test.server.HTTP.Response)12 Map (java.util.Map)9 ArrayNode (org.codehaus.jackson.node.ArrayNode)9 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)7 Date (java.util.Date)6 List (java.util.List)6 Description (org.hamcrest.Description)6 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)6