use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.
the class SecurityRulesDocIT method should403WhenAuthenticatedButForbidden.
@Test
public void should403WhenAuthenticatedButForbidden() throws Exception {
server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withSecurityRules(PermanentlyForbiddenSecurityRule.class.getCanonicalName(), PermanentlyPassingSecurityRule.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
server.start();
functionalTestHelper = new FunctionalTestHelper(server);
JaxRsResponse clientResponse = gen.get().expectedStatus(403).expectedType(MediaType.APPLICATION_JSON_TYPE).get(trimTrailingSlash(functionalTestHelper.baseUri())).response();
assertEquals(403, clientResponse.getStatus());
}
use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.
the class SecurityRulesDocIT method should401WithBasicChallengeWhenASecurityRuleFails.
@Test
@Title("Enforcing server authorization rules")
@Documented("In this example, a (dummy) failing security rule is registered to deny access to all URIs to the server by listing the rules class in _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 denied.\n" + "In a production-quality implementation the rule will likely lookup credentials/claims in a 3rd-party directory service (e.g. LDAP) or in a local database of authorized users.")
public void should401WithBasicChallengeWhenASecurityRuleFails() throws Exception {
server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withSecurityRules(PermanentlyFailingSecurityRule.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
server.start();
gen.get().docHeadingLevel(1);
gen.get().addSnippet("config", "\n[source,properties]\n----\ndbms.security.http_authorization_classes=my.rules" + ".PermanentlyFailingSecurityRule\n----\n");
gen.get().addTestSourceSnippets(PermanentlyFailingSecurityRule.class, "failingRule");
functionalTestHelper = new FunctionalTestHelper(server);
gen.get().setSection("ops");
JaxRsResponse response = gen.get().expectedStatus(401).expectedHeader("WWW-Authenticate").post(functionalTestHelper.nodeUri()).response();
assertThat(response.getHeaders().getFirst("WWW-Authenticate"), containsString("Basic realm=\"" + PermanentlyFailingSecurityRule.REALM + "\""));
}
use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.
the class StreamingBatchOperationDocIT method shouldBeAbleToReferToNotCreatedUniqueEntities.
// It has to be possible to create relationships among created and not-created nodes
// in batch operation. Tests the fix for issue #690.
@Test
public void shouldBeAbleToReferToNotCreatedUniqueEntities() throws Exception {
String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("name").key("value").value("tobias").key("properties").object().key("name").value("Tobias Tester").endObject().endObject().key("id").value(0).endObject().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("name").key("value").value("andres").key("properties").object().key("name").value("Andres Tester").endObject().endObject().key("id").value(1).endObject().object().key("method").value("POST").key("to").value("/index/node/Cultures?unique").key("body").object().key("key").value("name").key("value").value("andres").key("properties").object().key("name").value("Andres Tester").endObject().endObject().key("id").value(2).endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels/?unique").key("body").object().key("key").value("name").key("value").value("tobias-andres").key("start").value("{0}").key("end").value("{1}").key("type").value("FRIENDS").endObject().key("id").value(3).endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels/?unique").key("body").object().key("key").value("name").key("value").value("andres-tobias").key("start").value(// Not-created entity here
"{2}").key("end").value("{0}").key("type").value("FRIENDS").endObject().key("id").value(4).endObject().object().key("method").value("POST").key("to").value("/index/relationship/my_rels/?unique").key("body").object().key("key").value("name").key("value").value("andres-tobias").key("start").value(// Relationship should not be created
"{1}").key("end").value("{0}").key("type").value("FRIENDS").endObject().key("id").value(5).endObject().endArray().toString();
JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
assertEquals(200, response.getStatus());
final String entity = response.getEntity();
List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
assertEquals(6, results.size());
Map<String, Object> andresResult1 = results.get(1);
Map<String, Object> andresResult2 = results.get(2);
Map<String, Object> secondRelationship = results.get(4);
Map<String, Object> thirdRelationship = results.get(5);
// Same people
Map<String, Object> body1 = (Map<String, Object>) andresResult1.get("body");
Map<String, Object> body2 = (Map<String, Object>) andresResult2.get("body");
assertEquals(body1.get("id"), body2.get("id"));
// Same relationship
body1 = (Map<String, Object>) secondRelationship.get("body");
body2 = (Map<String, Object>) thirdRelationship.get("body");
assertEquals(body1.get("self"), body2.get("self"));
// Created for {2} {0}
assertTrue(((String) secondRelationship.get("location")).length() > 0);
// {2} = {1} = Andres
body1 = (Map<String, Object>) secondRelationship.get("body");
body2 = (Map<String, Object>) andresResult1.get("body");
assertEquals(body1.get("start"), body2.get("self"));
}
use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.
the class StreamingBatchOperationDocIT method shouldRollbackAllWhenInsertingIllegalData.
@Test
public void shouldRollbackAllWhenInsertingIllegalData() throws JsonParseException, ClientHandlerException, UniformInterfaceException, JSONException {
String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value(1).endObject().endObject().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").object().key("age").value(1).endObject().endObject().endObject().endArray().toString();
long originalNodeCount = countNodes();
JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
assertEquals(200, response.getStatus());
assertEquals(400, singleResult(response, 1).get("status"));
assertEquals(originalNodeCount, countNodes());
}
use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.
the class StreamingBatchOperationDocIT method shouldGetLocationHeadersWhenCreatingThings.
@Test
public void shouldGetLocationHeadersWhenCreatingThings() throws Exception {
long originalNodeCount = countNodes();
final String jsonString = new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").value(1).endObject().endObject().endArray().toString();
JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), jsonString);
assertEquals(200, response.getStatus());
final String entity = response.getEntity();
List<Map<String, Object>> results = JsonHelper.jsonToList(entity);
assertEquals(originalNodeCount + 1, countNodes());
assertEquals(1, results.size());
Map<String, Object> result = results.get(0);
assertTrue(((String) result.get("location")).length() > 0);
}
Aggregations