コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToStartInHAMode() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToStartInHAMode()
        {
            // Given
            int       clusterPort = PortAuthority.allocatePort();
            NeoServer server      = EnterpriseServerBuilder.serverOnRandomPorts().usingDataDir(Folder.Root.AbsolutePath).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(cluster_server.name(), ":" + clusterPort).withProperty(initial_hosts.name(), ":" + clusterPort).persistent().build();

            try
            {
                server.Start();
                server.Database;

                assertThat(server.Database.Graph, @is(instanceOf(typeof(HighlyAvailableGraphDatabase))));

                HTTP.Response haEndpoint = HTTP.GET(GetHaEndpoint(server));
                assertEquals(200, haEndpoint.Status());
                assertThat(haEndpoint.RawContent(), containsString("master"));

                HTTP.Response discovery = HTTP.GET(server.BaseUri().toASCIIString());
                assertEquals(200, discovery.Status());
            }
            finally
            {
                server.Stop();
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRedirectRootToBrowser()
        public virtual void ShouldRedirectRootToBrowser()
        {
            assertFalse(Server().baseUri().ToString().Contains("browser"));

            HTTP.Response res = HTTP.withHeaders(HttpHeaders.ACCEPT, MediaType.TEXT_HTML).GET(Server().baseUri().ToString());
            assertThat(res.Header("Location"), containsString("browser"));
        }
コード例 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReplyNicelyToTooManyFailedAuthAttempts() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReplyNicelyToTooManyFailedAuthAttempts()
        {
            // Given
            StartServerWithConfiguredUser();
            long timeout = DateTimeHelper.CurrentUnixTimeMillis() + 30_000;

            // When
            HTTP.Response response = null;
            while (DateTimeHelper.CurrentUnixTimeMillis() < timeout)
            {
                // Done in a loop because we're racing with the clock to get enough failed requests into 5 seconds
                response = HTTP.withBasicAuth("neo4j", "incorrect").POST(Server.baseUri().resolve("authentication").ToString(), HTTP.RawPayload.quotedJson("{'username':'******', 'password':'******'}"));

                if (response.Status() == 429)
                {
                    break;
                }
            }

            // Then
            assertThat(response.Status(), equalTo(429));
            JsonNode firstError = response.Get("errors").get(0);

            assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.AuthenticationRateLimit"));
            assertThat(firstError.get("message").asText(), equalTo("Too many failed authentication requests. Please wait 5 seconds and try again."));
        }
コード例 #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertAuthorizationRequired(String method, String path, Object payload, int expectedAuthorizedStatus) throws org.neo4j.server.rest.domain.JsonParseException
        private void AssertAuthorizationRequired(string method, string path, object payload, int expectedAuthorizedStatus)
        {
            // When no header
            HTTP.Response response = HTTP.request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(401));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("No authentication header supplied."));
            assertThat(response.Header(HttpHeaders.WWW_AUTHENTICATE), equalTo("Basic realm=\"Neo4j\""));

            // When malformed header
            response = HTTP.withHeaders(HttpHeaders.AUTHORIZATION, "This makes no sense").request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(400));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Request.InvalidFormat"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("Invalid authentication header."));

            // When invalid credential
            response = HTTP.withBasicAuth("neo4j", "incorrect").request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(401));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("Invalid username or password."));
            assertThat(response.Header(HttpHeaders.WWW_AUTHENTICATE), equalTo("Basic realm=\"Neo4j\""));

            // When authorized
            response = HTTP.withBasicAuth("neo4j", "secret").request(method, Server.baseUri().resolve(path).ToString(), payload);
            assertThat(response.Status(), equalTo(expectedAuthorizedStatus));
        }
コード例 #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void startServerWithConfiguredUser() throws java.io.IOException
        public virtual void StartServerWithConfiguredUser()
        {
            StartServer(true);
            // Set the password
            HTTP.Response post = HTTP.withBasicAuth("neo4j", "neo4j").POST(Server.baseUri().resolve("/user/neo4j/password").ToString(), HTTP.RawPayload.quotedJson("{'password':'******'}"));
            assertEquals(200, post.Status());
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowAllAccessIfAuthenticationIsDisabled() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowAllAccessIfAuthenticationIsDisabled()
        {
            // Given
            StartServer(false);

            // When & then
            assertEquals(201, HTTP.POST(Server.baseUri().resolve("db/data/node").ToString(), HTTP.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(), HTTP.RawPayload.quotedJson("{'statements':[{'statement':'MATCH (n) RETURN n'}]}")).status());
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testPropertyExistenceConstraintCanBeCreated()
        public virtual void TestPropertyExistenceConstraintCanBeCreated()
        {
            // Given running enterprise server
            string createConstraintUri = Neo4j.httpURI().resolve("test/myExtension/createConstraint").ToString();

            // When I run this server

            // Then constraint should be created
            HTTP.Response response = HTTP.GET(createConstraintUri);
            assertThat(response.Status(), equalTo(HttpStatus.CREATED_201));
        }
コード例 #8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExtensionWork()
        public virtual void ShouldExtensionWork()
        {
            // Given running enterprise server
            string doSomethingUri = Neo4j.httpURI().resolve("test/myExtension/doSomething").ToString();

            // When I run this test

            // Then
            HTTP.Response response = HTTP.GET(doSomethingUri);
            assertThat(response.Status(), equalTo(234));
        }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnEmptyMapForEmptyProperties()
        public virtual void ShouldReturnEmptyMapForEmptyProperties()
        {
            // Given
            string location = HTTP.POST(Server().baseUri().resolve("db/data/node").ToString()).location();

            // When
            HTTP.Response res = HTTP.GET(location + "/properties");

            // Then
            assertThat(res.RawContent(), equalTo("{ }"));
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotWhitelistDB() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotWhitelistDB()
        {
            // 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));
        }
コード例 #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotWhitelistConsoleService() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotWhitelistConsoleService()
        {
            // 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));
        }
コード例 #12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowDataAccess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowDataAccess()
        {
            // Given
            StartServerWithConfiguredUser();

            // When & then
            AssertAuthorizationRequired("POST", "db/data/node", HTTP.RawPayload.quotedJson("{'name':'jake'}"), 201);
            AssertAuthorizationRequired("GET", "db/data/node/1234", 404);
            AssertAuthorizationRequired("POST", "db/data/transaction/commit", HTTP.RawPayload.quotedJson("{'statements':[{'statement':'MATCH (n) RETURN n'}]}"), 200);

            assertEquals(200, HTTP.GET(Server.baseUri().resolve("").ToString()).status());
        }
コード例 #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void runningInCompiledRuntime()
        public virtual void RunningInCompiledRuntime()
        {
            // Given
            string uri     = FunctionalTestHelper.dataUri() + "transaction/commit";
            string payload = "{ 'statements': [ { 'statement': 'CYPHER runtime=compiled MATCH (n) RETURN n' } ] }";

            // When
            HTTP.Response res = HTTP.POST(uri, payload.replaceAll("'", "\""));

            // Then
            assertEquals(200, res.Status());
        }
コード例 #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowDataAccessForUnauthorizedUser() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowDataAccessForUnauthorizedUser()
        {
            // Given
            StartServer(true);                 // The user should not have read access before changing the password

            // When
            HTTP.Response response = HTTP.withBasicAuth("neo4j", "neo4j").POST(Server.baseUri().resolve("authentication").ToString(), HTTP.RawPayload.quotedJson("{'username':'******', 'password':'******'}"));

            // When & then
            assertEquals(403, HTTP.withBasicAuth("neo4j", "neo4j").POST(Server.baseUri().resolve("db/data/node").ToString(), HTTP.RawPayload.quotedJson("{'name':'jake'}")).status());
            assertEquals(403, HTTP.withBasicAuth("neo4j", "neo4j").GET(Server.baseUri().resolve("db/data/node/1234").ToString()).status());
            assertEquals(403, HTTP.withBasicAuth("neo4j", "neo4j").POST(Server.baseUri().resolve("db/data/transaction/commit").ToString(), HTTP.RawPayload.quotedJson("{'statements':[{'statement':'MATCH (n) RETURN n'}]}")).status());
        }
コード例 #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSayMalformedHeaderIfMalformedAuthorization() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSayMalformedHeaderIfMalformedAuthorization()
        {
            // Given
            StartServerWithConfiguredUser();

            // When
            HTTP.Response response = HTTP.withHeaders(HttpHeaders.AUTHORIZATION, "This makes no sense").GET(DataURL());

            // Then
            assertThat(response.Status(), equalTo(400));
            assertThat(response.Get("errors").get(0).get("code").asText(), equalTo("Neo.ClientError.Request.InvalidFormat"));
            assertThat(response.Get("errors").get(0).get("message").asText(), equalTo("Invalid authentication header."));
        }
コード例 #16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportEnterpriseEdition() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReportEnterpriseEdition()
        {
            // Given
            string releaseVersion = Server.Database.Graph.DependencyResolver.resolveDependency(typeof(KernelData)).version().ReleaseVersion;

            // When
            HTTP.Response res = HTTP.GET(FunctionalTestHelper.managementUri() + "/" + VersionAndEditionService.SERVER_PATH);

            // Then
            assertEquals(200, res.Status());
            assertThat(res.Get("edition").asText(), equalTo("enterprise"));
            assertThat(res.Get("version").asText(), equalTo(releaseVersion));
        }
コード例 #17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWhitelistBrowser() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWhitelistBrowser()
        {
            // Given
            assumeTrue(BrowserIsLoaded());
            _server = CommunityServerBuilder.serverOnRandomPorts().withProperty(GraphDatabaseSettings.auth_enabled.name(), "true").build();

            // When
            _server.start();

            // Then I should be able to access the browser
            HTTP.Response response = HTTP.GET(_server.baseUri().resolve("browser/index.html").ToString());
            assertThat(response.Status(), equalTo(200));
        }
コード例 #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldParseHappyPath()
        public virtual void ShouldParseHappyPath()
        {
            // Given
            string username = "******";
            string password = "******";
            string header   = HTTP.basicAuthHeader(username, password);

            // When
            string[] parsed = decode(header);

            // Then
            assertEquals(username, parsed[0]);
            assertEquals(password, parsed[1]);
        }
コード例 #19
0
        /*
         * The default jetty behaviour serves an index page for static resources. The 'directories' exposed through this
         * behaviour are not file system directories, but only a list of resources present on the classpath, so there is no
         * security vulnerability. However, it might seem like a vulnerability to somebody without the context of how the
         * whole stack works, so to avoid confusion we disable the jetty behaviour.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDisallowDirectoryListings() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDisallowDirectoryListings()
        {
            // Given
            _server = CommunityServerBuilder.serverOnRandomPorts().build();
            _server.start();

            // When
            HTTP.Response okResource      = HTTP.GET(_server.baseUri().resolve("/browser/index.html").ToString());
            HTTP.Response illegalResource = HTTP.GET(_server.baseUri().resolve("/browser/assets/").ToString());

            // Then
            // Depends on specific resources exposed by the browser module; if this test starts to fail,
            // check whether the structure of the browser module has changed and adjust accordingly.
            assertEquals(200, okResource.Status());
            assertEquals(403, illegalResource.Status());
        }
コード例 #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowDisablingAuthorization() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldAllowDisablingAuthorization()
        {
            // Given
            _server = CommunityServerBuilder.serverOnRandomPorts().withProperty(GraphDatabaseSettings.auth_enabled.name(), "false").build();

            // When
            _server.start();

            // Then I should have write access
            HTTP.Response response = HTTP.POST(_server.baseUri().resolve("db/data/node").ToString(), quotedJson("{'name':'My Node'}"));
            assertThat(response.Status(), equalTo(201));
            string node = response.Location();

            // Then I should have read access
            assertThat(HTTP.GET(node).status(), equalTo(200));
        }
コード例 #21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLaunchAServerInSpecifiedDirectory()
        public virtual void ShouldLaunchAServerInSpecifiedDirectory()
        {
            // Given
            File workDir = new File(TestDir.directory(), "specific");

            workDir.mkdir();

            // When
            using (ServerControls server = GetTestServerBuilder(workDir).newServer())
            {
                // Then
                assertThat(HTTP.GET(server.HttpURI().ToString()).status(), equalTo(200));
                assertThat(workDir.list().length, equalTo(1));
            }

            // And after it's been closed, it should've cleaned up after itself.
            assertThat(Arrays.ToString(workDir.list()), workDir.list().length, equalTo(0));
        }
コード例 #22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void executeQueryWithSnapshotEngine()
        public virtual void ExecuteQueryWithSnapshotEngine()
        {
            Database            database = _server.Database;
            GraphDatabaseFacade graph    = database.Graph;

            using (Transaction transaction = graph.BeginTx())
            {
                for (int i = 0; i < 10; i++)
                {
                    Node node = graph.CreateNode();
                    node.SetProperty("a", "b");
                }
                transaction.Success();
            }

            HTTP.Builder  httpClientBuilder = HTTP.withBaseUri(_server.baseUri());
            HTTP.Response transactionStart  = httpClientBuilder.Post(TransactionURI());
            assertThat(transactionStart.Status(), equalTo(201));
            HTTP.Response response = httpClientBuilder.POST(transactionStart.Location(), quotedJson("{ 'statements': [ { 'statement': 'MATCH (n) RETURN n' } ] }"));
            assertThat(response.Status(), equalTo(200));
        }
コード例 #23
0
        public virtual void PasswordChangeRequired()
        {
            // Given
            StartServer(true);

            // Document
            RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(403).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "neo4j")).get(DataURL());

            // Then
            JsonNode data       = JsonHelper.jsonNode(response.Entity());
            JsonNode firstError = data.get("errors").get(0);

            assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Forbidden"));
            assertThat(firstError.get("message").asText(), equalTo("User is required to change their password."));
            assertThat(data.get("password_change").asText(), equalTo(PasswordURL("neo4j")));
        }
コード例 #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGetRootWithHTTP()
        public virtual void ShouldGetRootWithHTTP()
        {
            HTTP.Response response = HTTP.withHeaders("Accept", MediaType.TEXT_HTML).GET(_functionalTestHelper.dataUri());
            assertEquals(Status.OK.StatusCode, response.Status());
            AssertValidHtml(response.RawContent());
        }
コード例 #25
0
 private static HTTP.Builder RequestWithHeaders(string username, string password)
 {
     return(HTTP.withBasicAuth(username, password).withHeaders(HttpHeaders.ACCEPT, "application/json; charset=UTF-8", HttpHeaders.CONTENT_TYPE, "application/json"));
 }
コード例 #26
0
        public virtual void SuccessfulAuthentication()
        {
            // Given
            StartServerWithConfiguredUser();

            // Document
            RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(200).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "secret")).get(UserURL("neo4j"));

            // Then
            JsonNode data = JsonHelper.jsonNode(response.Entity());

            assertThat(data.get("username").asText(), equalTo("neo4j"));
            assertThat(data.get("password_change_required").asBoolean(), equalTo(false));
            assertThat(data.get("password_change").asText(), equalTo(PasswordURL("neo4j")));
        }
コード例 #27
0
        public virtual void IncorrectAuthentication()
        {
            // Given
            StartServerWithConfiguredUser();

            // Document
            RESTRequestGenerator.ResponseEntity response = Gen.get().expectedStatus(401).withHeader(HttpHeaders.AUTHORIZATION, HTTP.basicAuthHeader("neo4j", "incorrect")).expectedHeader("WWW-Authenticate", "Basic realm=\"Neo4j\"").post(DataURL());

            // Then
            JsonNode data       = JsonHelper.jsonNode(response.Entity());
            JsonNode firstError = data.get("errors").get(0);

            assertThat(firstError.get("code").asText(), equalTo("Neo.ClientError.Security.Unauthorized"));
            assertThat(firstError.get("message").asText(), equalTo("Invalid username or password."));
        }
コード例 #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            ServerHelper.cleanTheDatabase(_readOnlyServer);
            _readOnlyServer = ServerHelper.createReadOnlyServer(Dir.storeDir());
            _http           = HTTP.withBaseUri(_readOnlyServer.baseUri());
        }