Skip to content

Commit 80f2470

Browse files
author
Can Ibanoglu
committed
Merge remote-tracking branch 'upstream/1.0' into graph-types
Conflicts: src/v1/index.js
2 parents 52e09ae + 3447cbb commit 80f2470

17 files changed

+597
-156
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ We build a special browser version of the driver, which supports connecting to N
2727
This will make a global `neo4j` object available, where you can access the `v1` API at `neo4j.v1`:
2828

2929
```javascript
30-
var driver = neo4j.v1.driver("bolt://localhost");
30+
var driver = neo4j.v1.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
3131
```
3232

3333
## Usage examples
3434

3535
```javascript
3636

37-
// Create a driver instance
38-
var driver = neo4j.driver("bolt://localhost");
37+
// Create a driver instance, for the user neo4j with password neo4j.
38+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
3939

4040
// Create a session to run Cypher statements in.
4141
// Note: Always make sure to close sessions when you are done using them!

gulpfile.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ gulp.task('default', ["test"]);
4848

4949
gulp.task('browser', function(cb){
5050
runSequence('build-browser-test', 'build-browser', cb);
51-
})
51+
});
5252

5353
/** Build all-in-one files for use in the browser */
5454
gulp.task('build-browser', function () {
@@ -168,7 +168,7 @@ gulp.task('watch-n-test', ['test-nodejs'], function () {
168168

169169
var neo4jLinuxUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-NIGHTLY-unix.tar.gz';
170170
var neo4jWinUrl = 'http://alpha.neohq.net/dist/neo4j-enterprise-3.0.0-NIGHTLY-windows.zip';
171-
var neo4jHome = './build/neo4j-enterprise-3.0.0-M02';
171+
var neo4jHome = './build/neo4j-enterprise-3.0.0';
172172
var isWin = /^win/.test(process.platform);
173173

174174
gulp.task('download-neo4j', function() {
@@ -187,6 +187,11 @@ gulp.task('download-neo4j', function() {
187187
}
188188
});
189189

190+
gulp.task('set-password', ['download-neo4j'], function() {
191+
return gulp.src('test/resources/auth')
192+
.pipe(gulp.dest(neo4jHome + "/data/dbms/"));
193+
});
194+
190195
var featureFiles = 'https://s3-eu-west-1.amazonaws.com/remoting.neotechnology.com/driver-compliance/tck.tar.gz';
191196
var featureHome = './build/tck';
192197

@@ -200,7 +205,7 @@ gulp.task('run-tck', ['download-tck', 'nodejs'], function() {
200205
return gulp.src(featureHome + "/*").pipe(cucumber({
201206
'steps': 'test/v1/tck/steps/*.js',
202207
'format': 'pretty',
203-
'tags' : "~@in_dev"
208+
'tags' : ['~@in_dev', '~@db','~@match_acceptance']
204209
}));
205210
});
206211

@@ -232,7 +237,7 @@ gulp.task('set', function() {
232237

233238
});
234239

235-
gulp.task('start-neo4j', ['download-neo4j'], function() {
240+
gulp.task('start-neo4j', ['set-password'], function() {
236241
if(isWin) {
237242
runPowershell('Install-Neo4jServer -Neo4jServer ' + neo4jHome + ' -Name neo4j-js;' +
238243
'Start-Neo4jServer -Neo4jServer ' + neo4jHome + ' -ServiceName neo4j-js');

src/v1/driver.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ class Driver {
2929
* @constructor
3030
* @param {string} url
3131
* @param {string} userAgent
32+
* @param {Object} token
3233
*/
33-
constructor(url, userAgent) {
34+
constructor(url, userAgent, token) {
3435
this._url = url;
3536
this._userAgent = userAgent || 'neo4j-javascript/0.0';
3637
this._openSessions = {};
3738
this._sessionIdGenerator = 0;
39+
this._token = token || {};
3840
}
3941

4042
/**
@@ -44,8 +46,7 @@ class Driver {
4446
session() {
4547
let sessionId = this._sessionIdGenerator++;
4648
let conn = connect(this._url);
47-
conn.initialize(this._userAgent);
48-
49+
conn.initialize(this._userAgent, this._token);
4950
let _driver = this;
5051
let _session = new Session( conn, () => {
5152
// On close of session, remove it from the list of open sessions

src/v1/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ import {Node, Relationship, UnboundRelationship, PathSegment, Path} from './grap
2525
let USER_AGENT = "neo4j-javascript/" + VERSION;
2626

2727
export default {
28-
driver: (url) => new Driver(url, USER_AGENT),
29-
int : int,
30-
isInt : isInt,
28+
driver: (url, token) => new Driver(url, USER_AGENT, token),
29+
int: int,
30+
isInt: isInt,
31+
auth : {
32+
basic: (username, password) => {
33+
return {scheme: "basic", principal: username, credentials: password};
34+
}
35+
},
3136
types : {
3237
Node : Node,
3338
Relationship : Relationship,

src/v1/internal/connector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ class Connection {
273273
}
274274

275275
/** Queue an INIT-message to be sent to the database */
276-
initialize( clientName, observer ) {
276+
initialize( clientName, token, observer ) {
277277
this._queueObserver(observer);
278-
this._packer.packStruct( INIT, [clientName] );
278+
this._packer.packStruct( INIT, [clientName, token] );
279279
this._chunker.messageBoundary();
280280
}
281281

test/internal/connector.test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ var DummyChannel = require('../../lib/v1/internal/ch-dummy.js');
2020
var connect = require("../../lib/v1/internal/connector.js").connect;
2121

2222
describe('connector', function() {
23-
it('should read/write basic messages', function(done) {
23+
24+
fit('should read/write basic messages', function(done) {
2425
// Given
2526
var conn = connect("bolt://localhost")
2627

2728
// When
28-
conn.initialize( "mydriver/0.0.0", {
29+
conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"}, {
2930
onCompleted: function( msg ) {
3031
expect( msg ).not.toBeNull();
3132
conn.close();
@@ -44,7 +45,7 @@ describe('connector', function() {
4445

4546
// When
4647
var records = [];
47-
conn.initialize( "mydriver/0.0.0" );
48+
conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"} );
4849
conn.run( "RETURN 1.0", {} );
4950
conn.pullAll( {
5051
onNext: function( record ) {
@@ -66,10 +67,10 @@ describe('connector', function() {
6667

6768
// When
6869
var records = [];
69-
conn.initialize( "mydriver/0.0.0" );
70+
conn.initialize( "mydriver/0.0.0", {scheme: "basic", principal: "neo4j", credentials: "neo4j"} );
7071
conn.run( "RETURN 1", {} );
7172
conn.sync();
72-
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 ' );
73+
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 ' );
7374
done();
7475
});
7576

test/neo4j-driver.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ describe('neo4j-driver', function() {
2121
it('should expose version 1 of the API as a property', function(done) {
2222
// When
2323
var neo4jDriver = require("../lib");
24-
2524
// Then I can access and use V1 of the API
26-
var driver = neo4jDriver.v1.driver("bolt://localhost");
25+
var driver = neo4jDriver.v1.driver("bolt://localhost", neo4jDriver.v1.auth.basic("neo4j", "neo4j"));
2726
driver.session().run( "RETURN 1" )
2827
.then( function() { driver.close(); })
2928
.then( done );
@@ -34,7 +33,7 @@ describe('neo4j-driver', function() {
3433
var neo4jV1 = require("../lib/v1");
3534

3635
// Then I can access and use V1 of the API
37-
var driver = neo4jV1.driver("bolt://localhost");
36+
var driver = neo4jV1.driver("bolt://localhost", neo4jV1.auth.basic("neo4j", "neo4j"));
3837
driver.session().run( "RETURN 1" )
3938
.then( function() { driver.close(); })
4039
.then( done );

test/resources/auth

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
neo4j:SHA-256,E4B4C20A3933637A1EE5ADBDE16290F6915E516A67216E35CAE1208A86F91E3B,2801E325BE8A074BD92F1A4B692AE167:

test/v1/driver.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
var neo4j = require("../../lib/v1");
2121

2222
describe('driver', function() {
23+
2324
it('should expose sessions', function() {
2425
// Given
25-
var driver = neo4j.driver("bolt://localhost");
26+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
2627

2728
// When
2829
var session = driver.session();

test/v1/examples.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('transaction', function() {
2626
var driver, session, out, console;
2727

2828
beforeEach(function(done) {
29-
driver = neo4j.driver("bolt://localhost");
29+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
3030
session = driver.session();
3131

3232
// Override console.log, to assert on stdout output
@@ -42,7 +42,7 @@ describe('transaction', function() {
4242

4343
it('should document a minimum viable snippet', function(done) {
4444
// tag::minimum-snippet[]
45-
var driver = neo4j.driver("bolt://localhost");
45+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
4646
var session = driver.session();
4747

4848
session.run( "CREATE (neo:Person {name:'Neo', age:23})" );

test/v1/session.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('session', function() {
2525
var driver, session;
2626

2727
beforeEach(function(done) {
28-
driver = neo4j.driver("bolt://localhost");
28+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
2929
session = driver.session();
3030

3131
session.run("MATCH (n) DETACH DELETE n").then(done);

test/v1/tck/steps/environment.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var neo4j = require("../../../../lib/v1");
2+
3+
module.exports = function () {
4+
5+
var failedScenarios = []
6+
7+
this.Before("@reset_database", function( scenario, callback ) {
8+
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
9+
this.session = this.driver.session();
10+
this.session.run("MATCH (n) DETACH DELETE n").then( function( ) {
11+
callback();
12+
});
13+
callback();
14+
});
15+
16+
this.Before("~@reset_database", function( scenario, callback ) {
17+
this.driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
18+
this.session = this.driver.session();
19+
callback();
20+
});
21+
22+
this.After(function (scenario, callback) {
23+
if (!scenario.isSuccessful()) {
24+
failedScenarios.push(scenario)
25+
}
26+
callback();
27+
});
28+
29+
this.registerHandler('AfterFeatures', function (event, callback) {
30+
if (failedScenarios.length) {
31+
for ( var i = 0; i < failedScenarios.length; i++) {
32+
console.log("FAILED! Scenario: " + failedScenarios[i].getName());
33+
console.log("With Exception: " + failedScenarios[i].getException() + "\n");
34+
}
35+
return process.exit(2);
36+
}
37+
callback();
38+
});
39+
}

0 commit comments

Comments
 (0)