Search in sources :

Example 11 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldBeAbleToTraverseAllThePagesWithNonDefaultPageSize.

@Documented("Paged traverser page size.\n\n" + "The default page size is 50 items, but\n" + "depending on the application larger or smaller pages sizes might be\n" + "appropriate. This can be set by adding a +pageSize+ query parameter.")
@Test
public void shouldBeAbleToTraverseAllThePagesWithNonDefaultPageSize() {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    URI traverserLocation = createPagedTraverserWithPageSize(1).getLocation();
    int enoughPagesToExpireTheTraverser = 12;
    for (int i = 0; i < enoughPagesToExpireTheTraverser; i++) {
        JaxRsResponse response = new RestRequest(traverserLocation).get();
        assertEquals(200, response.getStatus());
    }
    JaxRsResponse response = new RestRequest(traverserLocation).get();
    assertEquals(404, response.getStatus());
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) URI(java.net.URI) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 12 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldBeAbleToTraverseAllThePagesWithDefaultPageSize.

@Documented("Paging through the results of a paged traverser.\n\n" + "Paged traversers hold state on the server, and allow clients to page through the results of a traversal.\n" + "To progress to the next page of traversal results, the client issues a HTTP `GET` request on the paged traversal URI which causes the traversal to fill the next page (or partially fill it if insufficient results are available).\n \n" + "Note that if a traverser expires through inactivity it will cause a 404 response on the next `GET` request.\n" + "Traversers' leases are renewed on every successful access for the same amount of time as originally specified.\n\n" + "When the paged traverser reaches the end of its results, the client can expect a 404 response as the traverser is disposed by the server.")
@Test
public void shouldBeAbleToTraverseAllThePagesWithDefaultPageSize() {
    theStartNode = createLinkedList(LONG_LIST_LENGTH, server.getDatabase());
    URI traverserLocation = createPagedTraverser().getLocation();
    int enoughPagesToExpireTheTraverser = 3;
    for (int i = 0; i < enoughPagesToExpireTheTraverser; i++) {
        gen.get().expectedType(MediaType.APPLICATION_JSON_TYPE).expectedStatus(200).payload(traverserDescription()).get(traverserLocation.toString());
    }
    JaxRsResponse response = new RestRequest(traverserLocation).get();
    assertEquals(404, response.getStatus());
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) URI(java.net.URI) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 13 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class SecurityRulesDocIT method should401WithBasicChallengeIfAnyOneOfTheRulesFails.

@Test
public void should401WithBasicChallengeIfAnyOneOfTheRulesFails() throws Exception {
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withSecurityRules(PermanentlyFailingSecurityRule.class.getCanonicalName(), PermanentlyPassingSecurityRule.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.doc.server.helpers.FunctionalTestHelper) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 14 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class SecurityRulesDocIT method aSimpleWildcardUriPathShould401OnAccessToProtectedSubPath.

@Test
@Title("Using wildcards to target security rules")
@Documented("In this example, a security rule is registered to deny access to all URIs to the server by listing the rule(s) class(es) in _neo4j.conf_.\n" + "In this case, the rule is registered using a wildcard URI path (where `*` characters can be used to signify any part of the path).\n" + "For example `/users*` means the rule will be bound to any resources under the `/users` root path.\n" + "Similarly `/users*type*` will bind the rule to resources matching URIs like `/users/fred/type/premium`.\n" + "\n" + "@@config\n" + "\n" + "with the rule source code of:\n" + "\n" + "@@failingRuleWithWildcardPath\n" + "\n" + "With this rule registered, any access to URIs under /protected/ will be denied by the server.\n" + "Using wildcards allows flexible targeting of security rules to arbitrary parts of the server's API, including any unmanaged extensions or managed plugins that have been registered.")
public void aSimpleWildcardUriPathShould401OnAccessToProtectedSubPath() throws Exception {
    String mountPoint = "/protected/tree/starts/here" + DummyThirdPartyWebService.DUMMY_WEB_SERVICE_MOUNT_POINT;
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withThirdPartyJaxRsPackage("org.dummy.doc.web.service", mountPoint).withSecurityRules(PermanentlyFailingSecurityRuleWithWildcardPath.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" + ".PermanentlyFailingSecurityRuleWithWildcardPath\n----\n");
    gen.get().addTestSourceSnippets(PermanentlyFailingSecurityRuleWithWildcardPath.class, "failingRuleWithWildcardPath");
    gen.get().setSection("ops");
    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.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Example 15 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class StreamingBatchOperationDocIT method shouldForwardUnderlyingErrors.

@Test
public void shouldForwardUnderlyingErrors() throws Exception {
    JaxRsResponse response = RestRequest.req().accept(APPLICATION_JSON_TYPE).header(StreamingFormat.STREAM_HEADER, "true").post(batchUri(), new PrettyJSON().array().object().key("method").value("POST").key("to").value("/node").key("body").object().key("age").array().value(true).value("hello").endArray().endObject().endObject().endArray().toString());
    Map<String, Object> res = singleResult(response, 0);
    assertTrue(((String) res.get("message")).startsWith("Invalid JSON array in POST body"));
    assertEquals(400, res.get("status"));
}
Also used : PrettyJSON(org.neo4j.doc.server.rest.PrettyJSON) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)38 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)38 RestRequest (org.neo4j.doc.server.rest.RestRequest)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)9 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)8 Documented (org.neo4j.kernel.impl.annotations.Documented)6 URI (java.net.URI)4 Map (java.util.Map)4 Title (org.neo4j.test.TestData.Title)3 File (java.io.File)2 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)2 NeoServer (org.neo4j.server.NeoServer)2 Client (com.sun.jersey.api.client.Client)1 CommunityWebContainerBuilder (org.neo4j.doc.server.helpers.CommunityWebContainerBuilder)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1