Skip to content

Commit 7616428

Browse files
committed
Send INIT eagerly
There is no benefit of queuing the INIT message and it makes error handling trickier.
1 parent fab6d7c commit 7616428

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/v1/internal/connector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class Connection {
323323
this._packer.packStruct( INIT, [this._packable(clientName), this._packable(token)],
324324
(err) => this._handleFatalError(err) );
325325
this._chunker.messageBoundary();
326+
this.sync();
326327
}
327328

328329
/** Queue a RUN-message to be sent to the database */

test/v1/driver.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,19 @@ describe('driver', function() {
4747
// When
4848
driver.session();
4949
});
50+
51+
it('should fail early on wrong credentials', function(done) {
52+
// Given
53+
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "who would use such a password"));
54+
55+
// Expect
56+
driver.onError = function (err) {
57+
//the error message is different whether in browser or node
58+
expect(err.fields[0].code).toEqual('Neo.ClientError.Security.Unauthorized');
59+
done();
60+
};
61+
62+
// When
63+
driver.session();
64+
});
5065
});

test/v1/tck/steps/authsteps.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ module.exports = function () {
5757
var message = this.err.fields[0].message
5858
var code = this.err.fields[0].code
5959

60-
// TODO uncomment this once we fix the init sync
61-
//var expectedStartOfMessage = 'No operations allowed until you send an INIT message successfully.'
60+
var expectedStartOfMessage = 'No operations allowed until you send an INIT message successfully.'
6261
var expectedCode = 'Neo.ClientError';
6362

64-
// TODO uncomment this once we fix the init sync
65-
//if (message.indexOf(expectedStartOfMessage) != 0) {
66-
// throw new Error("Wrong error messsage. Expected: '" + expectedStartOfMessage + "'. Got: '" + message + "'");
67-
//}
63+
if (message.indexOf(expectedStartOfMessage) != 0) {
64+
throw new Error("Wrong error messsage. Expected: '" + expectedStartOfMessage + "'. Got: '" + message + "'");
65+
}
6866

6967
if (code.indexOf(expectedCode) != 0) {
7068
throw new Error("Wrong error code. Expected: '" + expectedCode + "'. Got: '" + code + "'");

0 commit comments

Comments
 (0)