Search in sources :

Example 1 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper in project neo4j-documentation by neo4j.

the class NeoServerDefaultPortAndHostnameDocIT method shouldDefaultToSensiblePortIfNoneSpecifiedInConfig.

@Test
public void shouldDefaultToSensiblePortIfNoneSpecifiedInConfig() throws Exception {
    FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server());
    JaxRsResponse response = functionalTestHelper.get(functionalTestHelper.managementUri());
    assertThat(response.getStatus(), is(200));
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 2 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper in project neo4j-documentation by neo4j.

the class SecurityRulesDocIT method shouldInvokeAllSecurityRules.

@Test
public void shouldInvokeAllSecurityRules() throws Exception {
    // given
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withSecurityRules(NoAccessToDatabaseSecurityRule.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    functionalTestHelper = new FunctionalTestHelper(server);
    // when
    gen.get().expectedStatus(401).get(functionalTestHelper.dataUri()).response();
    // then
    assertTrue(NoAccessToDatabaseSecurityRule.wasInvoked());
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Test(org.junit.Test)

Example 3 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper 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 4 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper 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 5 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper in project neo4j-documentation by neo4j.

the class ManageNodeDocIT method setupServer.

@BeforeClass
public static void setupServer() throws IOException {
    functionalTestHelper = new FunctionalTestHelper(server());
    helper = functionalTestHelper.getGraphDbHelper();
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) BeforeClass(org.junit.BeforeClass)

Aggregations

FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)23 BeforeClass (org.junit.BeforeClass)12 Test (org.junit.Test)11 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)9 Matchers.containsString (org.hamcrest.Matchers.containsString)4 RestRequest (org.neo4j.doc.server.rest.RestRequest)3 Documented (org.neo4j.kernel.impl.annotations.Documented)3 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 CommunityWebContainerBuilder (org.neo4j.doc.server.helpers.CommunityWebContainerBuilder)1