Skip to content

Commit 3ce65b1

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 3ce65b1

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
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: 5 additions & 7 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.'
62-
var expectedCode = 'Neo.ClientError';
60+
var expectedStartOfMessage = 'The client is unauthorized due to authentication failure.';
61+
var expectedCode = 'Neo.ClientError.Security.Unauthorized';
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 + "'");

test/v1/tck/steps/tlssteps.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ module.exports = function () {
151151
});
152152

153153
this.Then(/^I should get a helpful error explaining that no trusted certificate found$/, function (callback) {
154-
console.log(this.error.message);
155154
var expected = "Server certificate is not trusted. If you trust the database you are connecting to, add the signing " +
156155
"certificate, or the server certificate, to the list of certificates trusted by this driver using " +
157156
"`neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This is a security measure to protect " +

0 commit comments

Comments
 (0)