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());
}
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."));
}
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")));
}
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());
}
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));
}
Aggregations