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