diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 940f8c3d4..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "neokit"] - path = neokit - url = https://github.com/neo-technology/neokit.git diff --git a/README.md b/README.md index cccce62cb..421538a01 100644 --- a/README.md +++ b/README.md @@ -224,10 +224,19 @@ See files under `examples/` on how to use. ## Testing +Tests **require** latest [Boltkit](https://github.com/neo4j-contrib/boltkit) to be installed in the system. It is needed to start, stop and configure local test database. Boltkit can be installed with the following command: + + pip install --upgrade boltkit + +To run tests against "default" Neo4j version: + ./runTests.sh + +To run tests against specified Neo4j version (latest enterprise 3.2 snapshot in this case): + + ./runTests.sh '-e 3.2' -This runs the test suite against a fresh download of Neo4j. -Or `npm test` if you already have a running version of a compatible Neo4j server. +Simple `npm test` can also be used if you already have a running version of a compatible Neo4j server. For development, you can have the build tool rerun the tests each time you change the source code: diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 728f216e2..8f5b0cc57 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -22,7 +22,6 @@ var source = require('vinyl-source-stream'); var buffer = require('vinyl-buffer'); var gulp = require('gulp'); var through = require('through2'); -var gulpif = require('gulp-if'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); var gutil = require('gulp-util'); @@ -40,7 +39,6 @@ var decompress = require('gulp-decompress'); var fs = require("fs-extra"); var runSequence = require('run-sequence'); var path = require('path'); -var childProcess = require("child_process"); var minimist = require('minimist'); var cucumber = require('gulp-cucumber'); var merge = require('merge-stream'); @@ -48,6 +46,7 @@ var install = require("gulp-install"); var os = require('os'); var file = require('gulp-file'); var semver = require('semver'); +var sharedNeo4j = require('./test/internal/shared-neo4j').default; gulp.task('default', ["test"]); @@ -232,43 +231,12 @@ gulp.task('set', function() { }); -var neo4jHome = path.resolve('./build/neo4j'); -var neorunPath = path.resolve('./neokit/neorun.py'); -var neorunStartArgsName = "--neorun.start.args"; // use this args to provide additional args for running neorun.start +var neo4jHome = path.resolve('./build/neo4j'); -gulp.task('start-neo4j', function() { - - var neorunStartArgs = '-p neo4j'; // default args to neorun.start: change the default password to neo4j - process.argv.slice(2).forEach(function (val) { - if(val.startsWith(neorunStartArgsName)) - { - neorunStartArgs = val.split("=")[1]; - } - }); - - neorunStartArgs = neorunStartArgs.match(/\S+/g) || ''; - - return runScript([ - neorunPath, '--start=' + neo4jHome - ].concat( neorunStartArgs ) ); +gulp.task('start-neo4j', function () { + sharedNeo4j.start(neo4jHome, process.env.NEOCTRL_ARGS); }); -gulp.task('stop-neo4j', function() { - return runScript([ - neorunPath, '--stop=' + neo4jHome - ]); +gulp.task('stop-neo4j', function () { + sharedNeo4j.stop(neo4jHome); }); - -var runScript = function(cmd) { - var spawnSync = childProcess.spawnSync, child, code; - child = spawnSync('python', cmd); - console.log("Script Outputs:\n" + child.stdout.toString()); - var error = child.stderr.toString(); - if (error.trim() !== "") - console.log("Script Errors:\n"+ error); - code = child.status; - if( code !==0 ) - { - throw "Script finished with code " + code - } -}; diff --git a/neokit b/neokit deleted file mode 160000 index 6d5d053c8..000000000 --- a/neokit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6d5d053c822eede032f25a68dbf8055e71f3f4c9 diff --git a/runTests.ps1 b/runTests.ps1 index c9b2bc07b..07d0b65a5 100644 --- a/runTests.ps1 +++ b/runTests.ps1 @@ -10,7 +10,7 @@ try } else { - $env:NEORUN_START_ARGS="$args" + $env:NEOCTRL_ARGS="$args" npm run start-neo4j } diff --git a/runTests.sh b/runTests.sh index 41879af35..f16222b2e 100755 --- a/runTests.sh +++ b/runTests.sh @@ -10,10 +10,9 @@ npm install if [ "$1" == "" ]; then npm run start-neo4j else - # Example: ./runTests.sh '-v 3.0.1 -p neo4j' - # Example: npm run start-neo4j -- --neorun.start.args='-v 3.0.1 -p neo4j' - NEORUN_START_ARGS="$1" npm run start-neo4j + # Example: ./runTests.sh '-e 3.1.3' + NEOCTRL_ARGS="$1" npm run start-neo4j fi sleep 2 -npm test \ No newline at end of file +npm test diff --git a/test/internal/connector.test.js b/test/internal/connector.test.js index 746375075..3610a0b56 100644 --- a/test/internal/connector.test.js +++ b/test/internal/connector.test.js @@ -23,6 +23,7 @@ import {Packer} from '../../src/v1/internal/packstream'; import {Chunker} from '../../src/v1/internal/chunking'; import {alloc} from '../../src/v1/internal/buf'; import {Neo4jError} from '../../src/v1/error'; +import sharedNeo4j from '../internal/shared-neo4j'; describe('connector', () => { @@ -31,7 +32,7 @@ describe('connector', () => { const conn = connect("bolt://localhost"); // When - conn.initialize("mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}, { + conn.initialize("mydriver/0.0.0", basicAuthToken(), { onCompleted: msg => { expect(msg).not.toBeNull(); conn.close(); @@ -49,7 +50,7 @@ describe('connector', () => { // When const records = []; - conn.initialize("mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}); + conn.initialize("mydriver/0.0.0", basicAuthToken()); conn.run("RETURN 1.0", {}); conn.pullAll({ onNext: record => { @@ -70,10 +71,10 @@ describe('connector', () => { const conn = connect("bolt://localhost", {channel: DummyChannel.channel}); // When - conn.initialize("mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}); + conn.initialize("mydriver/0.0.0", basicAuthToken()); conn.run("RETURN 1", {}); conn.sync(); - expect(observer.instance.toHex()).toBe('60 60 b0 17 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 41 b2 01 8e 6d 79 64 72 69 76 65 72 2f 30 2e 30 2e 30 a3 86 73 63 68 65 6d 65 85 62 61 73 69 63 89 70 72 69 6e 63 69 70 61 6c 85 6e 65 6f 34 6a 8b 63 72 65 64 65 6e 74 69 61 6c 73 85 6e 65 6f 34 6a 00 00 00 0c b2 10 88 52 45 54 55 52 4e 20 31 a0 00 00 '); + expect(observer.instance.toHex()).toBe('60 60 b0 17 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 44 b2 01 8e 6d 79 64 72 69 76 65 72 2f 30 2e 30 2e 30 a3 86 73 63 68 65 6d 65 85 62 61 73 69 63 89 70 72 69 6e 63 69 70 61 6c 85 6e 65 6f 34 6a 8b 63 72 65 64 65 6e 74 69 61 6c 73 88 70 61 73 73 77 6f 72 64 00 00 00 0c b2 10 88 52 45 54 55 52 4e 20 31 a0 00 00 '); done(); }); @@ -82,7 +83,7 @@ describe('connector', () => { const conn = connect("bolt://localhost:7474", {encrypted: false}); // When - conn.initialize("mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}, { + conn.initialize("mydriver/0.0.0", basicAuthToken(), { onCompleted: msg => { }, onError: err => { @@ -142,4 +143,12 @@ describe('connector', () => { }).toThrow(new Neo4jError(expectedMessage, expectedCode)); } + function basicAuthToken() { + return { + scheme: 'basic', + principal: sharedNeo4j.username, + credentials: sharedNeo4j.password + }; + } + }); diff --git a/test/internal/shared-neo4j.js b/test/internal/shared-neo4j.js new file mode 100644 index 000000000..61af9596a --- /dev/null +++ b/test/internal/shared-neo4j.js @@ -0,0 +1,258 @@ +/** + * Copyright (c) 2002-2017 "Neo Technology,"," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import neo4j from '../../src/v1'; + +class UnsupportedPlatform { + + pathJoin() { + throw new Error('Module \'path\' is not available on this platform'); + } + + spawn(command, args) { + throw new Error('Module \'child_process\' is not available on this platform'); + } + + listDir(path) { + throw new Error('Module \'fs\' is not available on this platform'); + } + + removeDir(path) { + throw new Error('Module \'fs\' is not available on this platform'); + } + + isDirectory(path) { + throw new Error('Module \'fs\' is not available on this platform'); + } +} + +class SupportedPlatform extends UnsupportedPlatform { + + constructor() { + super(); + this._path = require('path'); + this._childProcess = require('child_process'); + this._fs = require('fs-extra'); + } + + static create() { + try { + return new SupportedPlatform(); + } catch (e) { + return null; + } + } + + pathJoin() { + return this._path.join(...Array.from(arguments)); + } + + spawn(command, args) { + return this._childProcess.spawnSync(command, args); + } + + listDir(path) { + return this._fs.readdirSync(path); + } + + removeDir(path) { + if (this.isDirectory(path)) { + this._fs.removeSync(path); + } + } + + isDirectory(path) { + try { + this._fs.accessSync(path); + const stat = this._fs.statSync(path); + return stat.isDirectory(); + } catch (e) { + return false; + } + } +} + +const platform = SupportedPlatform.create() || new UnsupportedPlatform(); + +const username = 'neo4j'; +const password = 'password'; +const authToken = neo4j.auth.basic(username, password); + +const neoCtrlVersionParam = '-e'; +const defaultNeo4jVersion = '3.1.2'; +const defaultNeoCtrlArgs = `${neoCtrlVersionParam} ${defaultNeo4jVersion}`; + +function neo4jCertPath(dir) { + const neo4jDir = findExistingNeo4jDirStrict(dir); + return platform.pathJoin(neo4jDir, 'certificates', 'neo4j.cert'); +} + +function neo4jKeyPath(dir) { + const neo4jDir = findExistingNeo4jDirStrict(dir); + return platform.pathJoin(neo4jDir, 'certificates', 'neo4j.key'); +} + +function start(dir, givenNeoCtrlArgs) { + const boltKitCheckResult = runCommand('neoctrl-install', ['-h']); + + if (boltKitCheckResult.successful) { + const neo4jDir = installNeo4j(dir, givenNeoCtrlArgs); + createDefaultUser(neo4jDir); + startNeo4j(neo4jDir); + } else { + console.log('Boltkit unavailable. Please install it by running \'pip install --upgrade boltkit.'); + console.log('Integration tests will be skipped.'); + console.log('Command \'neoctrl-install -h\' resulted in\n' + boltKitCheckResult.fullOutput); + } +} + +function stop(dir) { + const neo4jDir = findExistingNeo4jDirStrict(dir); + stopNeo4j(neo4jDir); +} + +function restart(dir) { + const neo4jDir = findExistingNeo4jDirStrict(dir); + stopNeo4j(neo4jDir); + startNeo4j(neo4jDir); +} + +function installNeo4j(dir, givenNeoCtrlArgs) { + const neoCtrlArgs = givenNeoCtrlArgs || defaultNeoCtrlArgs; + const argsArray = neoCtrlArgs.split(' ').map(value => value.trim()); + argsArray.push(dir); + + const neo4jVersion = extractNeo4jVersion(argsArray); + const existingNeo4jDir = findExistingNeo4jDir(dir, neo4jVersion); + if (existingNeo4jDir) { + console.log('Found existing Neo4j ' + neo4jVersion + ' installation at: \'' + existingNeo4jDir + '\''); + return existingNeo4jDir; + } else { + platform.removeDir(dir); + + console.log('Installing Neo4j with neoctrl arguments: \'' + neoCtrlArgs + '\''); + const result = runCommand('neoctrl-install', argsArray); + if (!result.successful) { + throw new Error('Unable to install Neo4j.\n' + result.fullOutput); + } + + const installedNeo4jDir = result.stdout; + console.log('Installed Neo4j to: \'' + installedNeo4jDir + '\''); + return installedNeo4jDir; + } +} + +function createDefaultUser(neo4jDir) { + console.log('Creating user \'' + username + '\' for Neo4j at: \'' + neo4jDir + '\''); + const result = runCommand('neoctrl-create-user', [neo4jDir, username, password]); + if (!result.successful) { + throw new Error('Unable to create user: \'' + username + '\' for Neo4j at: ' + neo4jDir + '\'\n' + result.fullOutput); + } + console.log('Created user \'' + username + '\' for Neo4j at: \'' + neo4jDir + '\''); +} + +function startNeo4j(neo4jDir) { + console.log('Starting Neo4j at: \'' + neo4jDir + '\''); + const result = runCommand('neoctrl-start', [neo4jDir]); + if (!result.successful) { + throw new Error('Unable to start Neo4j.\n' + result.fullOutput); + } + console.log('Started Neo4j at: \'' + neo4jDir + '\''); +} + +function stopNeo4j(neo4jDir) { + console.log('Stopping Neo4j at: \'' + neo4jDir + '\''); + const result = runCommand('neoctrl-stop', [neo4jDir]); + if (!result.successful) { + throw new Error('Unable to stop Neo4j at: \'' + neo4jDir + '\'\n' + result.fullOutput); + } +} + +function findExistingNeo4jDirStrict(dir) { + const neo4jDir = findExistingNeo4jDir(dir, null); + if (!neo4jDir) { + throw new Error(`Unable to find Neo4j dir in: '${dir}'`); + } + return neo4jDir; +} + +function findExistingNeo4jDir(dir, neo4jVersion) { + if (!platform.isDirectory(dir)) { + return null; + } + + const dirs = platform.listDir(dir).filter(entry => isNeo4jDir(entry, neo4jVersion)) + .map(entry => platform.pathJoin(dir, entry)) + .filter(entry => platform.isDirectory(entry)); + + return dirs.length === 1 ? dirs[0] : null; +} + +function isNeo4jDir(name, version) { + if (!name.startsWith('neo4j')) { + return false; + } + if (version && name.indexOf(version) === -1) { + return false; + } + return true; +} + +function extractNeo4jVersion(neoCtrlArgs) { + const index = neoCtrlArgs.indexOf(neoCtrlVersionParam); + if (index === -1) { + throw new Error(`No '${neoCtrlVersionParam}' parameter`); + } + + const version = neoCtrlArgs[index + 1]; + if (!version) { + throw new Error(`Version is undefined in: ${neoCtrlArgs}`); + } + + return version.trim(); +} + +function runCommand(command, args) { + const spawnResult = platform.spawn(command, args); + return new RunCommandResult(spawnResult); +} + +class RunCommandResult { + + constructor(spawnResult) { + this.successful = spawnResult.status === 0; + this.stdout = (spawnResult.stdout.toString() || '').trim(); + this.stderr = (spawnResult.stderr.toString() || '').trim(); + this.fullOutput = 'STDOUT:\n\t' + this.stdout + '\n' + + 'STDERR:\n\t' + this.stderr + '\n' + + 'EXIT CODE:\n\t' + spawnResult.status + '\n' + + 'ERROR:\n\t' + spawnResult.error + '\n'; + } +} + +export default { + start: start, + stop: stop, + restart: restart, + neo4jCertPath: neo4jCertPath, + neo4jKeyPath: neo4jKeyPath, + username: username, + password: password, + authToken: authToken +}; diff --git a/test/internal/tls.test.js b/test/internal/tls.test.js index dc58f4b09..b259b7f80 100644 --- a/test/internal/tls.test.js +++ b/test/internal/tls.test.js @@ -21,6 +21,7 @@ var neo4j = require("../../lib/v1"); var fs = require("fs"); var path = require('path'); var hasFeature = require("../../lib/v1/internal/features").default; +var sharedNeo4j = require("../internal/shared-neo4j").default; describe('trust-signed-certificates', function() { @@ -37,7 +38,7 @@ describe('trust-signed-certificates', function() { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: "ENCRYPTION_ON", trust: "TRUST_SIGNED_CERTIFICATES", trustedCertificates: ["test/resources/random.certificate"] @@ -58,10 +59,10 @@ describe('trust-signed-certificates', function() { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: "ENCRYPTION_ON", trust: "TRUST_SIGNED_CERTIFICATES", - trustedCertificates: ["build/neo4j/certificates/neo4j.cert"] + trustedCertificates: [neo4jCertPath()] }); // When @@ -76,10 +77,10 @@ describe('trust-signed-certificates', function() { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_SIGNED_CERTIFICATES", - trustedCertificates: ["build/neo4j/certificates/neo4j.cert", "build/neo4j/certificates/neo4j.cert"] + trustedCertificates: [neo4jCertPath(), neo4jCertPath()] }); // When @@ -105,7 +106,7 @@ describe('trust-all-certificates', function () { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: "ENCRYPTION_ON", trust: "TRUST_ALL_CERTIFICATES" }); @@ -135,7 +136,7 @@ describe('trust-custom-ca-signed-certificates', function() { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES", trustedCertificates: ["test/resources/random.certificate"] @@ -156,10 +157,10 @@ describe('trust-custom-ca-signed-certificates', function() { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES", - trustedCertificates: ["build/neo4j/certificates/neo4j.cert"] + trustedCertificates: [neo4jCertPath()] }); // When @@ -185,7 +186,7 @@ describe('trust-system-ca-signed-certificates', function() { } // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES" }); @@ -229,7 +230,7 @@ describe('trust-on-first-use', function() { fs.rmdirSync(knownHostsDir); } catch (_) { } - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_ON_FIRST_USE", knownHosts: knownHostsPath @@ -263,7 +264,7 @@ describe('trust-on-first-use', function() { fs.unlinkSync(knownHostsPath); } - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_ON_FIRST_USE", knownHosts: knownHostsPath @@ -302,7 +303,7 @@ describe('trust-on-first-use', function() { fs.unlinkSync(knownHostsPath); } - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: "ENCRYPTION_ON", trust: "TRUST_ON_FIRST_USE", knownHosts: knownHostsPath @@ -331,7 +332,7 @@ describe('trust-on-first-use', function() { } fs.writeFileSync(knownHostsPath, ''); - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: true, trust: "TRUST_ON_FIRST_USE", knownHosts: knownHostsPath @@ -381,7 +382,7 @@ describe('trust-on-first-use', function() { // Given var knownHostsPath = "test/resources/random_known_hosts"; - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken, { encrypted: "ENCRYPTION_ON", trust: "TRUST_ON_FIRST_USE", knownHosts: knownHostsPath @@ -412,3 +413,7 @@ function muteConsoleLog() { function unMuteConsoleLog(originalLog) { console.log = originalLog; } + +function neo4jCertPath() { + return sharedNeo4j.neo4jCertPath(path.join('build', 'neo4j')); +} diff --git a/test/v1/direct.driver.boltkit.it.js b/test/v1/direct.driver.boltkit.it.js index ff0b0337e..781f78df3 100644 --- a/test/v1/direct.driver.boltkit.it.js +++ b/test/v1/direct.driver.boltkit.it.js @@ -20,6 +20,7 @@ import neo4j from '../../lib/v1'; import {READ, WRITE} from '../../lib/v1/driver'; import boltkit from './boltkit'; +import sharedNeo4j from '../internal/shared-neo4j'; describe('direct driver', () => { @@ -277,5 +278,5 @@ function createDriver() { const config = { encrypted: 'ENCRYPTION_OFF' }; - return neo4j.driver('bolt://localhost:9001', neo4j.auth.basic('neo4j', 'neo4j'), config); + return neo4j.driver('bolt://localhost:9001', sharedNeo4j.authToken, config); } diff --git a/test/v1/driver.test.js b/test/v1/driver.test.js index 9fa7bfb1e..6795af7cf 100644 --- a/test/v1/driver.test.js +++ b/test/v1/driver.test.js @@ -18,6 +18,7 @@ */ import neo4j from '../../src/v1'; +import sharedNeo4j from '../internal/shared-neo4j'; describe('driver', () => { @@ -35,7 +36,7 @@ describe('driver', () => { it('should expose sessions', () => { // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); // When const session = driver.session(); @@ -47,7 +48,7 @@ describe('driver', () => { it('should handle connection errors', done => { // Given - driver = neo4j.driver("bolt://localhoste", neo4j.auth.basic("neo4j", "neo4j")); + driver = neo4j.driver("bolt://localhoste", sharedNeo4j.authToken); // Expect driver.onError = error => { @@ -62,7 +63,7 @@ describe('driver', () => { }); it('should handle wrong scheme', () => { - expect(() => neo4j.driver("tank://localhost", neo4j.auth.basic("neo4j", "neo4j"))) + expect(() => neo4j.driver("tank://localhost", sharedNeo4j.authToken)) .toThrow(new Error("Unknown scheme: tank://")); }); @@ -72,7 +73,7 @@ describe('driver', () => { expect(() => neo4j.driver(['bolt:localhost'])).toThrowError(TypeError); expect(() => { - const driver = neo4j.driver(String('bolt://localhost', neo4j.auth.basic("neo4j", "neo4j"))); + const driver = neo4j.driver(String('bolt://localhost'), sharedNeo4j.authToken); return driver.session(); }).toBeDefined(); }); @@ -94,7 +95,7 @@ describe('driver', () => { it('should indicate success early on correct credentials', done => { // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); // Expect driver.onCompleted = meta => { @@ -107,7 +108,7 @@ describe('driver', () => { it('should be possible to pass a realm with basic auth tokens', done => { // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j", "native")); + driver = neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password, "native")); // Expect driver.onCompleted = meta => { @@ -120,7 +121,7 @@ describe('driver', () => { it('should be possible to create custom auth tokens', done => { // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic")); + driver = neo4j.driver("bolt://localhost", neo4j.auth.custom(sharedNeo4j.username, sharedNeo4j.password, "native", "basic")); // Expect driver.onCompleted = meta => { @@ -133,7 +134,7 @@ describe('driver', () => { it('should be possible to create custom auth tokens with additional parameters', done => { // Given - driver = neo4j.driver("bolt://localhost", neo4j.auth.custom("neo4j", "neo4j", "native", "basic", {secret: 42})); + driver = neo4j.driver("bolt://localhost", neo4j.auth.custom(sharedNeo4j.username, sharedNeo4j.password, "native", "basic", {secret: 42})); // Expect driver.onCompleted = () => { @@ -146,7 +147,7 @@ describe('driver', () => { it('should fail nicely when connecting with routing to standalone server', done => { // Given - driver = neo4j.driver("bolt+routing://localhost", neo4j.auth.basic("neo4j", "neo4j")); + driver = neo4j.driver("bolt+routing://localhost", sharedNeo4j.authToken); // Expect driver.onError = error => { @@ -171,7 +172,7 @@ describe('driver', () => { it('should fail when TRUST_ON_FIRST_USE is used with routing', () => { const createRoutingDriverWithTOFU = () => { - driver = neo4j.driver('bolt+routing://localhost', neo4j.auth.basic('neo4j', 'neo4j'), { + driver = neo4j.driver('bolt+routing://localhost', sharedNeo4j.username, { encrypted: "ENCRYPTION_ON", trust: 'TRUST_ON_FIRST_USE' }); diff --git a/test/v1/examples.test.js b/test/v1/examples.test.js index 513d9a2cf..833d50f8d 100644 --- a/test/v1/examples.test.js +++ b/test/v1/examples.test.js @@ -18,6 +18,7 @@ */ import neo4j from '../../src/v1'; +import sharedNeo4j from '../internal/shared-neo4j'; /** * The tests below are examples that get pulled into the Driver Manual using the tags inside the tests. @@ -34,15 +35,15 @@ describe('examples', () => { let testResultPromise; let resolveTestResultPromise; - const user = 'neo4j'; - const password = 'neo4j'; + const user = sharedNeo4j.username; + const password = sharedNeo4j.password; const uri = 'bolt://localhost:7687'; beforeAll(() => { originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; - driverGlobal = neo4j.driver(uri, neo4j.auth.basic('neo4j', 'neo4j')); + driverGlobal = neo4j.driver(uri, sharedNeo4j.authToken); }); beforeEach(done => { diff --git a/test/v1/package.test.js b/test/v1/package.test.js index c70e8a756..0c84cd701 100644 --- a/test/v1/package.test.js +++ b/test/v1/package.test.js @@ -20,6 +20,7 @@ var path = require('path'); var os = require('os'); var NodeChannel = require('../../lib/v1/internal/ch-node').default; +var sharedNeo4j = require('../../test/internal/shared-neo4j').default; describe('Package', function() { var driverGlobal = {close: function() {}}; @@ -41,7 +42,7 @@ describe('Package', function() { done.fail('Could not load sandbox package') } - driverGlobal = neo4jReq.v1.driver("bolt://localhost", neo4jReq.v1.auth.basic("neo4j", "neo4j")); + driverGlobal = neo4jReq.v1.driver("bolt://localhost", neo4jReq.v1.auth.basic(sharedNeo4j.username, sharedNeo4j.password)); var session = driverGlobal.session(); session.run('RETURN 1 AS answer').then(function(result) { expect(result.records.length).toBe(1); diff --git a/test/v1/result.test.js b/test/v1/result.test.js index bc68108ee..758f666c5 100644 --- a/test/v1/result.test.js +++ b/test/v1/result.test.js @@ -17,46 +17,45 @@ * limitations under the License. */ -var neo4j = require("../../lib/v1"); +import neo4j from '../../src/v1'; +import sharedNeo4j from '../internal/shared-neo4j'; -describe('result stream', function() { +describe('result stream', () => { - var driver, session; + let driver, session; - beforeEach(function(done) { - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + beforeEach(done => { + driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); session = driver.session(); session.run("MATCH (n) DETACH DELETE n").then(done); }); - afterEach(function() { + afterEach(() => { driver.close(); }); - it('should allow chaining `then`, returning a new thing in each', function(done) { + it('should allow chaining `then`, returning a new thing in each', done => { // When & Then session.run( "RETURN 1") - .then( function() { - return "first"; - }) - .then( function(arg) { + .then(() => 'first') + .then(arg => { expect(arg).toBe( "first" ); return "second"; }) - .then( function(arg) { + .then(arg => { expect(arg).toBe( "second" ); }) .then(done); }); - it('should allow catching exception thrown in `then`', function(done) { + it('should allow catching exception thrown in `then`', done => { // When & Then session.run( "RETURN 1") - .then( function() { + .then(() => { throw new Error("Away with you!"); }) - .catch( function(err) { + .catch(err => { expect(err.message).toBe( "Away with you!" ); done() }); diff --git a/test/v1/session.test.js b/test/v1/session.test.js index 8fa0d30aa..e139390fc 100644 --- a/test/v1/session.test.js +++ b/test/v1/session.test.js @@ -23,6 +23,7 @@ import Session from '../../src/v1/session'; import {READ} from '../../src/v1/driver'; import {SingleConnectionProvider} from '../../src/v1/internal/connection-providers'; import FakeConnection from '../internal/fake-connection'; +import sharedNeo4j from '../internal/shared-neo4j'; describe('session', () => { @@ -32,7 +33,7 @@ describe('session', () => { let originalTimeout; beforeEach(done => { - driver = neo4j.driver('bolt://localhost', neo4j.auth.basic('neo4j', 'neo4j')); + driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); driver.onCompleted = meta => { serverMetadata = meta['server']; }; @@ -104,7 +105,7 @@ describe('session', () => { }); it('should be possible to close driver after closing session with failed tx ', done => { - const driver = neo4j.driver('bolt://localhost', neo4j.auth.basic('neo4j', 'neo4j')); + const driver = neo4j.driver('bolt://localhost', sharedNeo4j.authToken); const session = driver.session(); const tx = session.beginTransaction(); tx.run('INVALID QUERY').catch(() => { diff --git a/test/v1/tck/steps/authsteps.js b/test/v1/tck/steps/authsteps.js index 23149cb71..3f7e0aa61 100644 --- a/test/v1/tck/steps/authsteps.js +++ b/test/v1/tck/steps/authsteps.js @@ -19,17 +19,15 @@ var neo4j = require("../../../../lib/v1"); var util = require("./util"); +var sharedNeo4j = require("../../../internal/shared-neo4j").default; module.exports = function () { - var username = "user"; - var password = "password"; - this.Given(/^a driver is configured with auth enabled and correct password is provided$/, function () { if (this.driver) { this.driver.close(); } - this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password)); }); this.Then(/^reading and writing to the database should be possible$/, function (callback) { @@ -43,7 +41,7 @@ module.exports = function () { if (this.driver) { this.driver.close(); } - this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "wrong")); + this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, "wrong")); this.driver.session(); }); diff --git a/test/v1/tck/steps/environment.js b/test/v1/tck/steps/environment.js index 3f4611f50..071a15603 100644 --- a/test/v1/tck/steps/environment.js +++ b/test/v1/tck/steps/environment.js @@ -19,6 +19,7 @@ var neo4j = require("../../../../lib/v1"); var fs = require("fs"); +var sharedNeo4j = require("../../../internal/shared-neo4j").default; module.exports = function () { @@ -27,7 +28,7 @@ module.exports = function () { var failedScenarios = []; this.registerHandler("BeforeFeatures", function(event, next) { - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + driver = neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password)); return next() }); diff --git a/test/v1/tck/steps/erroreportingsteps.js b/test/v1/tck/steps/erroreportingsteps.js index 54d2306fa..46136c474 100644 --- a/test/v1/tck/steps/erroreportingsteps.js +++ b/test/v1/tck/steps/erroreportingsteps.js @@ -19,6 +19,7 @@ var neo4j = require("../../../../lib/v1"); var util = require("./util"); +var sharedNeo4j = require("../../../internal/shared-neo4j").default; module.exports = function () { @@ -63,7 +64,7 @@ module.exports = function () { this.When(/^I set up a driver to an incorrect port$/, function (callback) { var self = this; - var driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://localhost:7777", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password)); driver.onError = function (error) { self.error = error; callback()}; driver.session().beginTransaction(); setTimeout(callback, 1000); @@ -71,7 +72,7 @@ module.exports = function () { this.When(/^I set up a driver with wrong scheme$/, function (callback) { try { - neo4j.driver("wrong://localhost:7474", neo4j.auth.basic("neo4j", "neo4j")); + neo4j.driver("wrong://localhost:7474", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password)); } catch (e){ this.error = e; callback(); diff --git a/test/v1/tck/steps/tlssteps.js b/test/v1/tck/steps/tlssteps.js index 6387a1b7e..38152a175 100644 --- a/test/v1/tck/steps/tlssteps.js +++ b/test/v1/tck/steps/tlssteps.js @@ -1,5 +1,6 @@ var neo4j = require("../../../../lib/v1"); var util = require("./util"); +var sharedNeo4j = require("../../../internal/shared-neo4j").default; var CALLBACK_TIMEOUT = 60 * 1000; @@ -124,7 +125,7 @@ module.exports = function () { }); this.When(/^I connect via a TLS\-enabled transport$/, function (callback) { - this.driver1 = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), this.config); + this.driver1 = neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password), this.config); callback(); }); @@ -164,7 +165,7 @@ module.exports = function () { }); function _connectWithHostFile(hostFile) { - return neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { + return neo4j.driver("bolt://localhost", neo4j.auth.basic(sharedNeo4j.username, sharedNeo4j.password), { trust: "TRUST_ON_FIRST_USE", knownHosts: hostFile, encrypted: "ENCRYPTION_ON" diff --git a/test/v1/tck/steps/util.js b/test/v1/tck/steps/util.js index f68aabe39..517f9a759 100644 --- a/test/v1/tck/steps/util.js +++ b/test/v1/tck/steps/util.js @@ -18,6 +18,7 @@ */ var neo4j = require("../../../../lib/v1"); +var sharedNeo4j = require("../../../internal/shared-neo4j").default; const INT = 'integer'; const FLOAT = 'float'; @@ -28,12 +29,12 @@ const RELATIONSHIP = 'relationship'; const NODE = 'node'; const PATH = 'path'; -var neorunPath = './neokit/neorun.py'; -var neo4jHome = './build/neo4j'; -var neo4jCert = neo4jHome + '/certificates/neo4j.cert'; -var neo4jKey = neo4jHome + '/certificates/neo4j.key'; -var childProcess = require("child_process"); var fs = require('fs'); +var path = require('path'); + +var neo4jHome = path.join('build', 'neo4j'); +var neo4jCert = sharedNeo4j.neo4jCertPath(neo4jHome); +var neo4jKey = sharedNeo4j.neo4jKeyPath(neo4jHome); function literalTableToTestObject(literalResults) { var resultValues = []; @@ -343,35 +344,9 @@ function changeCertificates(keyFile, certFile) { } function restart() { - stopDatabase(); - startDatabase(); -} - -function startDatabase() { - return runScript([ - neorunPath, '--start=' + neo4jHome - ]); -} - -function stopDatabase() { - return runScript([ - neorunPath, '--stop=' + neo4jHome - ]); + sharedNeo4j.restart(neo4jHome); } -var runScript = function(cmd) { - var spawnSync = childProcess.spawnSync, child, code; - child = spawnSync('python', cmd); - var error = child.stderr.toString(); - if (error.trim() !== "") - console.log("Script Errors:\n"+ error); - code = child.status; - if( code !==0 ) - { - throw "Script finished with code " + code - } -}; - module.exports = { literalTableToTestObject: literalTableToTestObject, literalValueToTestValueNormalIntegers : literalValueToTestValueNormalIntegers, diff --git a/test/v1/transaction.test.js b/test/v1/transaction.test.js index 80091ca98..0a52b67e5 100644 --- a/test/v1/transaction.test.js +++ b/test/v1/transaction.test.js @@ -16,7 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import neo4j from '../../lib/v1'; +import neo4j from '../../src/v1'; +import sharedNeo4j from '../internal/shared-neo4j'; describe('transaction', () => { @@ -30,7 +31,7 @@ describe('transaction', () => { originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; - driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); driver.onCompleted = meta => { server = meta['server']; }; diff --git a/test/v1/types.test.js b/test/v1/types.test.js index 87b802ee7..4d6461b57 100644 --- a/test/v1/types.test.js +++ b/test/v1/types.test.js @@ -18,6 +18,7 @@ */ var neo4j = require("../../lib/v1"); +var sharedNeo4j = require("../internal/shared-neo4j").default; describe('floating point values', function() { it('should support float 1.0 ', testVal( 1 ) ); @@ -66,7 +67,7 @@ describe('map values', function() { describe('node values', function() { it('should support returning nodes ', function(done) { // Given - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); var session = driver.session(); // When @@ -86,7 +87,7 @@ describe('node values', function() { describe('relationship values', function() { it('should support returning relationships', function(done) { // Given - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); var session = driver.session(); // When @@ -106,7 +107,7 @@ describe('relationship values', function() { describe('path values', function() { it('should support returning paths', function(done) { // Given - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); var session = driver.session(); // When @@ -135,7 +136,7 @@ describe('path values', function() { function testVal( val, expected ) { return function( done ) { - var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); + var driver = neo4j.driver("bolt://localhost", sharedNeo4j.authToken); var session = driver.session(); session.run("RETURN {val} as v", {val: val})