Search in sources :

Example 16 with FunctionalTestHelper

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

the class SecurityRulesDocIT method aComplexWildcardUriPathShould401OnAccessToProtectedSubPath.

@Test
@Title("Using complex wildcards to target security rules")
@Documented("In this example, a security rule is registered to deny 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.doc.web.service", mountPoint).withSecurityRules(PermanentlyFailingSecurityRuleWithComplexWildcardPath.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" + ".PermanentlyFailingSecurityRuleWithComplexWildcardPath\n----\n");
    gen.get().addTestSourceSnippets(PermanentlyFailingSecurityRuleWithComplexWildcardPath.class, "failingRuleWithComplexWildcardPath");
    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 17 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper 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());
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 18 with FunctionalTestHelper

use of org.neo4j.doc.server.helpers.FunctionalTestHelper 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 + "\""));
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) 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 19 with FunctionalTestHelper

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

the class SecurityRulesDocIT method shouldRespondWith201IfAllTheRulesPassWhenCreatingANode.

@Test
public void shouldRespondWith201IfAllTheRulesPassWhenCreatingANode() throws Exception {
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withSecurityRules(PermanentlyPassingSecurityRule.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    functionalTestHelper = new FunctionalTestHelper(server);
    gen.get().expectedStatus(201).expectedHeader("Location").post(functionalTestHelper.nodeUri()).response();
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Test(org.junit.Test)

Example 20 with FunctionalTestHelper

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

the class HTTPLoggingDocIT method givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess.

@Test
public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception {
    // given
    String directoryPrefix = testName.getMethodName();
    File logDirectory = testDirectory.directory(directoryPrefix + "-logdir");
    final String query = "?explicitlyEnabled=" + randomString();
    NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), "true").withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.getAbsolutePath()).usingDataDir(testDirectory.directory(directoryPrefix + "-dbdir").getAbsolutePath()).build();
    try {
        server.start();
        FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);
        // when
        JaxRsResponse response = new RestRequest().get(functionalTestHelper.managementUri() + query);
        assertThat(response.getStatus(), is(HttpStatus.SC_OK));
        response.close();
        // then
        File httpLog = new File(logDirectory, "http.log");
        assertEventually("request appears in log", fileContentSupplier(httpLog), containsString(query), 5, TimeUnit.SECONDS);
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) RestRequest(org.neo4j.doc.server.rest.RestRequest) FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) FileUtils.readTextFile(org.neo4j.io.fs.FileUtils.readTextFile) File(java.io.File) Test(org.junit.Test)

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