protected String txCommitURL() { return server.baseUri().resolve( "db/data/transaction/commit" ).toString(); } }
private String dataURL() { return server.baseUri().resolve( "db/data/" ).toString(); }
protected String dataURL() { return server.baseUri().resolve( "db/data/" ).toString(); }
protected String passwordURL( String username ) { return server.baseUri().resolve( "user/" + username + "/password" ).toString(); }
@Test public void shouldAllowAllAccessIfAuthenticationIsDisabled() throws Exception { // Given startServer( false ); // When & then assertEquals( 201, HTTP.POST( server.baseUri().resolve( "db/data/node" ).toString(), RawPayload.quotedJson( "{'name':'jake'}" ) ).status() ); assertEquals( 404, HTTP.GET( server.baseUri().resolve( "db/data/node/1234" ).toString() ).status() ); assertEquals( 200, HTTP.POST( server.baseUri().resolve( "db/data/transaction/commit" ).toString(), RawPayload.quotedJson( "{'statements':[{'statement':'MATCH (n) RETURN n'}]}" ) ).status() ); }
@Test public void cantChangeToCurrentPassword() throws Exception { // Given startServer( true ); // When HTTP.Response res = HTTP.withBasicAuth( "neo4j", "neo4j" ).POST( server.baseUri().resolve( "/user/neo4j/password" ).toString(), HTTP.RawPayload.quotedJson( "{'password':'neo4j'}" ) ); // Then assertThat( res.status(), equalTo( 422 ) ); }
public void startServerWithConfiguredUser() throws IOException { startServer( true ); // Set the password HTTP.Response post = HTTP.withBasicAuth( "neo4j", "neo4j" ).POST( server.baseUri().resolve( "/user/neo4j/password" ).toString(), HTTP.RawPayload.quotedJson( "{'password':'secret'}" ) ); assertEquals( 200, post.status() ); }
public void startServerWithConfiguredUser() throws IOException { startServer( true ); // Set the password HTTP.Response post = HTTP.withBasicAuth( "neo4j", "neo4j" ).POST( server.baseUri().resolve( "/user/neo4j/password" ).toString(), RawPayload.quotedJson( "{'password':'secret'}" ) ); assertEquals( 200, post.status() ); } }
@Test public void shouldExposeBaseUriWhenHttpDisabledAndHttpsEnabled() throws Exception { startServer( false, true ); URI uri = server.baseUri(); assertEquals( "https", uri.getScheme() ); HostnamePort expectedHostPort = addressForConnector( "https" ); assertEquals( expectedHostPort.getHost(), uri.getHost() ); assertEquals( expectedHostPort.getPort(), uri.getPort() ); }
@Test public void shouldExposeBaseUriWhenHttpEnabledAndHttpsDisabled() throws Exception { startServer( true, false ); URI uri = server.baseUri(); assertEquals( "http", uri.getScheme() ); HostnamePort expectedHostPort = addressForConnector( "http" ); assertEquals( expectedHostPort.getHost(), uri.getHost() ); assertEquals( expectedHostPort.getPort(), uri.getPort() ); }
@Test public void serverShouldSupportSsl() throws Exception { startServer(); assertThat( GET( httpsUri() ).status(), is( 200 ) ); assertThat( GET(server.baseUri().toString()).status(), is( 200 ) ); }
@Test public void shouldNotWhitelistConsoleService() throws Exception { // Given server = CommunityServerBuilder.serverOnRandomPorts() .withProperty( GraphDatabaseSettings.auth_enabled.name(), "true" ).build(); // When server.start(); // Then I should be able to access the console service HTTP.Response response = HTTP.GET( server.baseUri().resolve( "db/manage/server/console" ).toString() ); assertThat( response.status(), equalTo( 401 ) ); }
@Test public void shouldNotWhitelistDB() throws Exception { // Given server = CommunityServerBuilder.serverOnRandomPorts() .withProperty( GraphDatabaseSettings.auth_enabled.name(), "true" ).build(); // When server.start(); // Then I should get a unauthorized response for access to the DB HTTP.Response response = HTTP.GET(HTTP.GET( server.baseUri().resolve( "db/data" ).toString()).location() ); assertThat( response.status(), equalTo( 401 ) ); }
@Test public void serverShouldNotHangWithThreadPoolSizeSmallerThanCpuCount() throws Exception { server = serverOnRandomPorts().withMaxJettyThreads( 3 ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); assertThat( GET(server.baseUri().toString()).status(), is( 200 ) ); } }
@Test public void shouldAllowDataAccess() throws Exception { // Given startServerWithConfiguredUser(); // When & then assertAuthorizationRequired( "POST", "db/data/node", RawPayload.quotedJson( "{'name':'jake'}" ), 201 ); assertAuthorizationRequired( "GET", "db/data/node/1234", 404 ); assertAuthorizationRequired( "POST", "db/data/transaction/commit", RawPayload.quotedJson( "{'statements':[{'statement':'MATCH (n) RETURN n'}]}" ), 200 ); assertEquals(200, HTTP.GET( server.baseUri().resolve( "" ).toString() ).status() ); }
@Test public void shouldEnableConsoleServiceByDefault() throws IOException { // Given server = serverOnRandomPorts() .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); // When & then assertEquals( 200, new RestRequest().get( server.baseUri().toString() + "db/manage/server/console" ).getStatus() ); }
@Test public void shouldNotGenerateWADLWhenNotExplicitlyEnabledInConfig() throws IOException { server = serverOnRandomPorts() .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); JaxRsResponse response = new RestRequest().get( server.baseUri().toString() + "application.wadl", MediaType.WILDCARD_TYPE ); assertEquals( 404, response.getStatus() ); }
@Test public void shouldDisableConsoleServiceWhenAskedTo() throws IOException { // Given server = serverOnRandomPorts().withProperty( ServerSettings.console_module_enabled.name(), "false" ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); // When & then assertEquals( 404, new RestRequest().get( server.baseUri().toString() + "db/manage/server/console" ).getStatus() ); }
@Test public void shouldNotGenerateWADLWhenExplicitlyDisabledInConfig() throws IOException { server = serverOnRandomPorts().withProperty( ServerSettings.wadl_enabled.name(), "false" ) .usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ) .build(); server.start(); JaxRsResponse response = new RestRequest().get( server.baseUri().toString() + "application.wadl", MediaType.WILDCARD_TYPE ); assertEquals( 404, response.getStatus() ); }
@Test public void txEndpointShouldReplyWithHttpsWhenItReturnsURLs() throws Exception { startServer(); String baseUri = server.baseUri().toString(); HTTP.Response response = POST( baseUri + "db/data/transaction", quotedJson( "{'statements':[]}" ) ); assertThat( response.location(), startsWith( baseUri ) ); assertThat( response.get( "commit" ).asText(), startsWith( baseUri ) ); }