diff --git a/README.md b/README.md index 8c075597c..d9af21305 100644 --- a/README.md +++ b/README.md @@ -27,15 +27,15 @@ We build a special browser version of the driver, which supports connecting to N This will make a global `neo4j` object available, where you can access the `v1` API at `neo4j.v1`: ```javascript -var driver = neo4j.v1.driver("bolt://localhost"); +var driver = neo4j.v1.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); ``` ## Usage examples ```javascript -// Create a driver instance -var driver = neo4j.driver("bolt://localhost"); +// Create a driver instance, for the user neo4j with password neo4j. +var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); // Create a session to run Cypher statements in. // Note: Always make sure to close sessions when you are done using them! diff --git a/gulpfile.js b/gulpfile.js index 793ac8fa1..196b5b95f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -48,7 +48,7 @@ gulp.task('default', ["test"]); gulp.task('browser', function(cb){ runSequence('build-browser-test', 'build-browser', cb); -}) +}); /** Build all-in-one files for use in the browser */ gulp.task('build-browser', function () { @@ -168,7 +168,7 @@ gulp.task('watch-n-test', ['test-nodejs'], function () { var neo4jLinuxUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-NIGHTLY-unix.tar.gz'; var neo4jWinUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-NIGHTLY-windows.zip'; -var neo4jHome = './build/neo4j-enterprise-3.0.0-M02'; +var neo4jHome = './build/neo4j-enterprise-3.0.0'; var isWin = /^win/.test(process.platform); gulp.task('download-neo4j', function() { @@ -187,6 +187,11 @@ gulp.task('download-neo4j', function() { } }); +gulp.task('set-password', ['download-neo4j'], function() { + return gulp.src('test/resources/auth') + .pipe(gulp.dest(neo4jHome + "/data/dbms/")); +}); + var featureFiles = 'https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz'; var featureHome = './build/tck'; @@ -232,7 +237,7 @@ gulp.task('set', function() { }); -gulp.task('start-neo4j', ['download-neo4j'], function() { +gulp.task('start-neo4j', ['set-password'], function() { if(isWin) { runPowershell('Install-Neo4jServer -Neo4jServer ' + neo4jHome + ' -Name neo4j-js;' + 'Start-Neo4jServer -Neo4jServer ' + neo4jHome + ' -ServiceName neo4j-js'); diff --git a/src/v1/driver.js b/src/v1/driver.js index 28f1b9c76..8e8ff93dd 100644 --- a/src/v1/driver.js +++ b/src/v1/driver.js @@ -29,12 +29,14 @@ class Driver { * @constructor * @param {string} url * @param {string} userAgent + * @param {Object} token */ - constructor(url, userAgent) { + constructor(url, userAgent, token) { this._url = url; this._userAgent = userAgent || 'neo4j-javascript/0.0'; this._openSessions = {}; this._sessionIdGenerator = 0; + this._token = token || {}; } /** @@ -44,8 +46,7 @@ class Driver { session() { let sessionId = this._sessionIdGenerator++; let conn = connect(this._url); - conn.initialize(this._userAgent); - + conn.initialize(this._userAgent, this._token); let _driver = this; let _session = new Session( conn, () => { // On close of session, remove it from the list of open sessions diff --git a/src/v1/index.js b/src/v1/index.js index 1225d5b61..231205293 100644 --- a/src/v1/index.js +++ b/src/v1/index.js @@ -24,7 +24,10 @@ import {VERSION} from '../version'; let USER_AGENT = "neo4j-javascript/" + VERSION; export default { - driver: (url) => new Driver(url, USER_AGENT), + driver: (url, token) => new Driver(url, USER_AGENT, token), int: int, - isInt: isInt + isInt: isInt, + auth : { + basic : (username, password) => { return { scheme:"basic", principal : username, credentials : password };} + } } diff --git a/src/v1/internal/connector.js b/src/v1/internal/connector.js index 688064ef2..f32769147 100644 --- a/src/v1/internal/connector.js +++ b/src/v1/internal/connector.js @@ -273,9 +273,9 @@ class Connection { } /** Queue an INIT-message to be sent to the database */ - initialize( clientName, observer ) { + initialize( clientName, token, observer ) { this._queueObserver(observer); - this._packer.packStruct( INIT, [clientName] ); + this._packer.packStruct( INIT, [clientName, token] ); this._chunker.messageBoundary(); } diff --git a/test/internal/connector.test.js b/test/internal/connector.test.js index 948d7fd13..78c00ddb8 100644 --- a/test/internal/connector.test.js +++ b/test/internal/connector.test.js @@ -20,12 +20,13 @@ var DummyChannel = require('../../lib/v1/internal/ch-dummy.js'); var connect = require("../../lib/v1/internal/connector.js").connect; describe('connector', function() { - it('should read/write basic messages', function(done) { + + fit('should read/write basic messages', function(done) { // Given var conn = connect("bolt://localhost") // When - conn.initialize( "mydriver/0.0.0", { + conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}, { onCompleted: function( msg ) { expect( msg ).not.toBeNull(); conn.close(); @@ -44,7 +45,7 @@ describe('connector', function() { // When var records = []; - conn.initialize( "mydriver/0.0.0" ); + conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"} ); conn.run( "RETURN 1.0", {} ); conn.pullAll( { onNext: function( record ) { @@ -66,10 +67,10 @@ describe('connector', function() { // When var records = []; - conn.initialize( "mydriver/0.0.0" ); + conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"} ); 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 11 b1 01 8e 6d 79 64 72 69 76 65 72 2f 30 2e 30 2e 30 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 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 ' ); done(); }); diff --git a/test/neo4j-driver.test.js b/test/neo4j-driver.test.js index 835d1a1cb..36d7c5411 100644 --- a/test/neo4j-driver.test.js +++ b/test/neo4j-driver.test.js @@ -21,9 +21,8 @@ describe('neo4j-driver', function() { it('should expose version 1 of the API as a property', function(done) { // When var neo4jDriver = require("../lib"); - // Then I can access and use V1 of the API - var driver = neo4jDriver.v1.driver("bolt://localhost"); + var driver = neo4jDriver.v1.driver("bolt://localhost", neo4jDriver.v1.auth.basic("neo4j", "neo4j")); driver.session().run( "RETURN 1" ) .then( function() { driver.close(); }) .then( done ); @@ -34,7 +33,7 @@ describe('neo4j-driver', function() { var neo4jV1 = require("../lib/v1"); // Then I can access and use V1 of the API - var driver = neo4jV1.driver("bolt://localhost"); + var driver = neo4jV1.driver("bolt://localhost", neo4jV1.auth.basic("neo4j", "neo4j")); driver.session().run( "RETURN 1" ) .then( function() { driver.close(); }) .then( done ); diff --git a/test/resources/auth b/test/resources/auth new file mode 100644 index 000000000..0f96b6d8b --- /dev/null +++ b/test/resources/auth @@ -0,0 +1 @@ +neo4j:SHA-256,E4B4C20A3933637A1EE5ADBDE16290F6915E516A67216E35CAE1208A86F91E3B,2801E325BE8A074BD92F1A4B692AE167: diff --git a/test/v1/driver.test.js b/test/v1/driver.test.js index e77664f50..70ecf5961 100644 --- a/test/v1/driver.test.js +++ b/test/v1/driver.test.js @@ -20,9 +20,10 @@ var neo4j = require("../../lib/v1"); describe('driver', function() { + it('should expose sessions', function() { // Given - var driver = neo4j.driver("bolt://localhost"); + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); // When var session = driver.session(); diff --git a/test/v1/examples.test.js b/test/v1/examples.test.js index 65f0da2b3..40864412f 100644 --- a/test/v1/examples.test.js +++ b/test/v1/examples.test.js @@ -26,7 +26,7 @@ describe('transaction', function() { var driver, session, out, console; beforeEach(function(done) { - driver = neo4j.driver("bolt://localhost"); + driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); session = driver.session(); // Override console.log, to assert on stdout output @@ -42,7 +42,7 @@ describe('transaction', function() { it('should document a minimum viable snippet', function(done) { // tag::minimum-snippet[] - var driver = neo4j.driver("bolt://localhost"); + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); session.run( "CREATE (neo:Person {name:'Neo', age:23})" ); diff --git a/test/v1/session.test.js b/test/v1/session.test.js index 127fc831f..69b80f0ab 100644 --- a/test/v1/session.test.js +++ b/test/v1/session.test.js @@ -25,7 +25,7 @@ describe('session', function() { var driver, session; beforeEach(function(done) { - driver = neo4j.driver("bolt://localhost"); + driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); session = driver.session(); session.run("MATCH (n) DETACH DELETE n").then(done); diff --git a/test/v1/tck/steps/environment.js b/test/v1/tck/steps/environment.js index 2b90673a3..c7b360515 100644 --- a/test/v1/tck/steps/environment.js +++ b/test/v1/tck/steps/environment.js @@ -5,7 +5,7 @@ module.exports = function () { var failedScenarios = [] this.Before("@reset_database", function( scenario, callback ) { - this.driver = neo4j.driver("bolt://localhost"); + this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); this.session = this.driver.session(); this.session.run("MATCH (n) DETACH DELETE n").then( function( ) { callback(); @@ -14,7 +14,7 @@ module.exports = function () { }); this.Before("~@reset_database", function( scenario, callback ) { - this.driver = neo4j.driver("bolt://localhost"); + this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); this.session = this.driver.session(); callback(); }); diff --git a/test/v1/transaction.test.js b/test/v1/transaction.test.js index 2ac72a4aa..27b2f704d 100644 --- a/test/v1/transaction.test.js +++ b/test/v1/transaction.test.js @@ -24,7 +24,7 @@ describe('transaction', function() { var driver, session; beforeEach(function(done) { - driver = neo4j.driver("bolt://localhost"); + driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); session = driver.session(); session.run("MATCH (n) DETACH DELETE n").then(done); diff --git a/test/v1/types.test.js b/test/v1/types.test.js index dadbb5014..6f31e71ca 100644 --- a/test/v1/types.test.js +++ b/test/v1/types.test.js @@ -64,7 +64,7 @@ describe('map values', function() { describe('node values', function() { it('should support returning nodes ', function(done) { // Given - var driver = neo4j.driver("bolt://localhost"); + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); // When @@ -84,7 +84,7 @@ describe('node values', function() { describe('relationship values', function() { it('should support returning relationships', function(done) { // Given - var driver = neo4j.driver("bolt://localhost"); + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); // When @@ -104,7 +104,7 @@ describe('relationship values', function() { describe('path values', function() { it('should support returning paths', function(done) { // Given - var driver = neo4j.driver("bolt://localhost"); + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); // When @@ -133,7 +133,7 @@ describe('path values', function() { function testVal( val ) { return function( done ) { - var driver = neo4j.driver("bolt://localhost"); + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j")); var session = driver.session(); session.run("RETURN {val} as v", {val: val})