Skip to content

Commit 488fe22

Browse files
committed
JS driver v1.0.5: Checking in transpiled files for bower
1 parent 2d3dadd commit 488fe22

11 files changed

+1733
-688
lines changed

lib/browser/neo4j-web.js

Lines changed: 716 additions & 329 deletions
Large diffs are not rendered by default.

lib/browser/neo4j-web.min.js

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/browser/neo4j-web.test.js

Lines changed: 857 additions & 325 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v1/driver.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,18 @@ var USER_AGENT = "neo4j-javascript/" + _version.VERSION;
254254
* // This means that by default, connections "just work" while still giving you
255255
* // good encrypted protection.
256256
* //
257-
* // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
257+
* // TRUST_CUSTOM_CA_SIGNED_CERTIFICATES is the classic approach to trust verification -
258258
* // whenever we establish an encrypted connection, we ensure the host is using
259259
* // an encryption certificate that is in, or is signed by, a certificate listed
260260
* // as trusted. In the web bundle, this list of trusted certificates is maintained
261261
* // by the web browser. In NodeJS, you configure the list with the next config option.
262-
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
262+
* //
263+
* // TRUST_SYSTEM_CA_SIGNED_CERTIFICATES meand that you trust whatever certificates
264+
* // are in the default certificate chain of th
265+
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES" | TRUST_CUSTOM_CA_SIGNED_CERTIFICATES | TRUST_SYSTEM_CA_SIGNED_CERTIFICATES,
263266
*
264267
* // List of one or more paths to trusted encryption certificates. This only
265-
* // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
268+
* // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".
266269
* // The certificate files should be in regular X.509 PEM format.
267270
* // For instance, ['./trusted.pem']
268271
* trustedCertificates: [],

lib/v1/internal/ch-node.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,48 @@ function storeFingerprint(serverId, knownHostsPath, fingerprint, cb) {
130130
}
131131

132132
var TrustStrategy = {
133+
/**
134+
* @deprecated Since version 1.0. Will be deleted in a future version. TRUST_CUSTOM_CA_SIGNED_CERTIFICATES.
135+
*/
133136
TRUST_SIGNED_CERTIFICATES: function TRUST_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
137+
console.log("`TRUST_SIGNED_CERTIFICATES` has been deprecated as option and will be removed in a future version of " + "the driver. Please use `TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` instead.");
138+
return TrustStrategy.TRUST_CUSTOM_CA_SIGNED_CERTIFICATES(opts, onSuccess, onFailure);
139+
},
140+
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES: function TRUST_CUSTOM_CA_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
134141
if (!opts.trustedCertificates || opts.trustedCertificates.length == 0) {
135-
onFailure((0, _error.newError)("You are using TRUST_SIGNED_CERTIFICATES as the method " + "to verify trust for encrypted connections, but have not configured any " + "trustedCertificates. You must specify the path to at least one trusted " + "X.509 certificate for this to work. Two other alternatives is to use " + "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=false " + "in your driver configuration."));
142+
onFailure((0, _error.newError)("You are using TRUST_CUSTOM_CA_SIGNED_CERTIFICATES as the method " + "to verify trust for encrypted connections, but have not configured any " + "trustedCertificates. You must specify the path to at least one trusted " + "X.509 certificate for this to work. Two other alternatives is to use " + "TRUST_ON_FIRST_USE or to disable encryption by setting encrypted=false " + "in your driver configuration."));
136143
return;
137144
}
138145

139146
var tlsOpts = {
140-
ca: opts.trustedCertificates.map(_fs2['default'].readFileSync),
147+
ca: opts.trustedCertificates.map(function (f) {
148+
return _fs2['default'].readFileSync(f);
149+
}),
141150
// Because we manually check for this in the connect callback, to give
142151
// a more helpful error to the user
143152
rejectUnauthorized: false
144153
};
145154

146155
var socket = _tls2['default'].connect(opts.port, opts.host, tlsOpts, function () {
147156
if (!socket.authorized) {
148-
onFailure((0, _error.newError)("Server certificate is not trusted. If you trust the database you are connecting to, add" + " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" + " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " + " is a security measure to protect against man-in-the-middle attacks. If you are just trying " + " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=false` in the driver" + " options."));
157+
onFailure((0, _error.newError)("Server certificate is not trusted. If you trust the database you are connecting to, add" + " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" + " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " + " is a security measure to protect against man-in-the-middle attacks. If you are just trying " + " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=false` in the driver" + " options. Socket responded with: " + socket.authorizationError));
158+
} else {
159+
onSuccess();
160+
}
161+
});
162+
socket.on('error', onFailure);
163+
return socket;
164+
},
165+
TRUST_SYSTEM_CA_SIGNED_CERTIFICATES: function TRUST_SYSTEM_CA_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
166+
167+
var tlsOpts = {
168+
// Because we manually check for this in the connect callback, to give
169+
// a more helpful error to the user
170+
rejectUnauthorized: false
171+
};
172+
var socket = _tls2['default'].connect(opts.port, opts.host, tlsOpts, function () {
173+
if (!socket.authorized) {
174+
onFailure((0, _error.newError)("Server certificate is not trusted. If you trust the database you are connecting to, use " + "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES and add" + " the signing certificate, or the server certificate, to the list of certificates trusted by this driver" + " using `neo4j.v1.driver(.., { trustedCertificates:['path/to/certificate.crt']}). This " + " is a security measure to protect against man-in-the-middle attacks. If you are just trying " + " Neo4j out and are not concerned about encryption, simply disable it using `encrypted=false` in the driver" + " options."));
149175
} else {
150176
onSuccess();
151177
}
@@ -167,7 +193,7 @@ var TrustStrategy = {
167193
// the raw cert cannot be accessed (or, at least I couldn't find a way to)
168194
// therefore, we can't generate a SHA512 fingerprint, meaning we can't
169195
// do TOFU, and the safe approach is to fail.
170-
onFailure((0, _error.newError)("You are using a version of NodeJS that does not " + "support trust-on-first use encryption. You can either upgrade NodeJS to " + "a newer version, use `trust:TRUST_SIGNED_CERTIFICATES` in your driver " + "config instead, or disable encryption using `encrypted:false`."));
196+
onFailure((0, _error.newError)("You are using a version of NodeJS that does not " + "support trust-on-first use encryption. You can either upgrade NodeJS to " + "a newer version, use `trust:TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` in your driver " + "config instead, or disable encryption using `encrypted:false`."));
171197
return;
172198
}
173199

@@ -207,7 +233,7 @@ function connect(opts, onSuccess) {
207233
} else if (TrustStrategy[opts.trust]) {
208234
return TrustStrategy[opts.trust](opts, onSuccess, onFailure);
209235
} else {
210-
onFailure((0, _error.newError)("Unknown trust strategy: " + opts.trust + ". Please use either " + "trust:'TRUST_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " + "configuration. Alternatively, you can disable encryption by setting " + "`encrypted:false`. There is no mechanism to use encryption without trust verification, " + "because this incurs the overhead of encryption without improving security. If " + "the driver does not verify that the peer it is connected to is really Neo4j, it " + "is very easy for an attacker to bypass the encryption by pretending to be Neo4j."));
236+
onFailure((0, _error.newError)("Unknown trust strategy: " + opts.trust + ". Please use either " + "trust:'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES' or trust:'TRUST_ON_FIRST_USE' in your driver " + "configuration. Alternatively, you can disable encryption by setting " + "`encrypted:false`. There is no mechanism to use encryption without trust verification, " + "because this incurs the overhead of encryption without improving security. If " + "the driver does not verify that the peer it is connected to is really Neo4j, it " + "is very easy for an attacker to bypass the encryption by pretending to be Neo4j."));
211237
}
212238
}
213239

@@ -250,6 +276,7 @@ var NodeChannel = (function () {
250276
});
251277

252278
self._conn.on('error', self._handleConnectionError);
279+
self._conn.on('end', self._handleConnectionTerminated);
253280

254281
// Drain all pending messages
255282
var pending = self._pending;
@@ -268,6 +295,14 @@ var NodeChannel = (function () {
268295
this.onerror(err);
269296
}
270297
}
298+
}, {
299+
key: '_handleConnectionTerminated',
300+
value: function _handleConnectionTerminated() {
301+
this._error = new Error('Connection was closed by server');
302+
if (this.onerror) {
303+
this.onerror(this._error);
304+
}
305+
}
271306

272307
/**
273308
* Write the passed in buffer to connection
@@ -302,6 +337,7 @@ var NodeChannel = (function () {
302337
this._open = false;
303338
if (this._conn) {
304339
this._conn.end();
340+
this._conn.removeListener('end', this._handleConnectionTerminated);
305341
this._conn.on('end', cb);
306342
} else {
307343
cb();

lib/v1/internal/ch-websocket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ var WebSocketChannel = (function () {
5757

5858
var scheme = "ws";
5959
if (opts.encrypted) {
60-
if (!opts.trust || opts.trust === "TRUST_SIGNED_CERTIFICATES") {
60+
if (!opts.trust || opts.trust === "TRUST_SIGNED_CERTIFICATES" || opts.trust === "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES") {
6161
scheme = "wss";
6262
} else {
63-
this._error = (0, _error.newError)("The browser version of this driver only supports one trust " + "strategy, 'TRUST_SIGNED_CERTIFICATES'. " + opts.trust + " is not supported. Please " + "either use TRUST_SIGNED_CERTIFICATES or disable encryption by setting " + "`encrypted:false` in the driver configuration.");
63+
this._error = (0, _error.newError)("The browser version of this driver only supports one trust " + "strategy, 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES'. " + opts.trust + " is not supported. Please " + "either use TRUST_CUSTOM_CA_SIGNED_CERTIFICATES or disable encryption by setting " + "`encrypted:false` in the driver configuration.");
6464
return;
6565
}
6666
}

lib/v1/internal/connector.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ NODE = 0x4E,
9898
PATH = 0x50,
9999

100100
//sent before version negotiation
101-
MAGIC_PREAMBLE = 0x6060B017;
101+
MAGIC_PREAMBLE = 0x6060B017,
102+
DEBUG = false;
102103

103104
var URLREGEX = new RegExp(["[^/]+//", // scheme
104105
"(([^:/?#]*)", // hostname
@@ -109,6 +110,20 @@ function host(url) {
109110
return url.match(URLREGEX)[2];
110111
}
111112

113+
/**
114+
* Very rudimentary log handling, should probably be replaced by something proper at some point.
115+
* @param actor the part that sent the message, 'S' for server and 'C' for client
116+
* @param msg the bolt message
117+
*/
118+
function log(actor, msg) {
119+
if (DEBUG) {
120+
for (var i = 2; i < arguments.length; i++) {
121+
msg += " " + JSON.stringify(arguments[i]);
122+
}
123+
console.log(actor + ":" + msg);
124+
}
125+
}
126+
112127
function port(url) {
113128
return url.match(URLREGEX)[3];
114129
}
@@ -317,16 +332,19 @@ var Connection = (function () {
317332

318333
switch (msg.signature) {
319334
case RECORD:
335+
log("S", "RECORD", msg.fields[0]);
320336
this._currentObserver.onNext(msg.fields[0]);
321337
break;
322338
case SUCCESS:
339+
log("S", "SUCCESS", msg.fields[0]);
323340
try {
324341
this._currentObserver.onCompleted(msg.fields[0]);
325342
} finally {
326343
this._currentObserver = this._pendingObservers.shift();
327344
}
328345
break;
329346
case FAILURE:
347+
log("S", "FAILURE", msg);
330348
try {
331349
this._currentObserver.onError(msg);
332350
this._errorMsg = msg;
@@ -356,6 +374,7 @@ var Connection = (function () {
356374
}
357375
break;
358376
case IGNORED:
377+
log("S", "IGNORED");
359378
try {
360379
if (this._errorMsg && this._currentObserver.onError) this._currentObserver.onError(this._errorMsg);else if (this._currentObserver.onError) this._currentObserver.onError(msg);
361380
} finally {
@@ -373,6 +392,7 @@ var Connection = (function () {
373392
value: function initialize(clientName, token, observer) {
374393
var _this2 = this;
375394

395+
log("C", "INIT", clientName, token);
376396
this._queueObserver(observer);
377397
this._packer.packStruct(INIT, [this._packable(clientName), this._packable(token)], function (err) {
378398
return _this2._handleFatalError(err);
@@ -387,6 +407,7 @@ var Connection = (function () {
387407
value: function run(statement, params, observer) {
388408
var _this3 = this;
389409

410+
log("C", "RUN", statement, params);
390411
this._queueObserver(observer);
391412
this._packer.packStruct(RUN, [this._packable(statement), this._packable(params)], function (err) {
392413
return _this3._handleFatalError(err);
@@ -400,6 +421,7 @@ var Connection = (function () {
400421
value: function pullAll(observer) {
401422
var _this4 = this;
402423

424+
log("C", "PULL_ALL");
403425
this._queueObserver(observer);
404426
this._packer.packStruct(PULL_ALL, [], function (err) {
405427
return _this4._handleFatalError(err);
@@ -413,6 +435,7 @@ var Connection = (function () {
413435
value: function discardAll(observer) {
414436
var _this5 = this;
415437

438+
log("C", "DISCARD_ALL");
416439
this._queueObserver(observer);
417440
this._packer.packStruct(DISCARD_ALL, [], function (err) {
418441
return _this5._handleFatalError(err);
@@ -426,6 +449,7 @@ var Connection = (function () {
426449
value: function reset(observer) {
427450
var _this6 = this;
428451

452+
log("C", "RESET");
429453
this._isHandlingFailure = true;
430454
var self = this;
431455
var wrappedObs = {
@@ -451,6 +475,7 @@ var Connection = (function () {
451475
value: function _ackFailure(observer) {
452476
var _this7 = this;
453477

478+
log("C", "ACK_FAILURE");
454479
this._queueObserver(observer);
455480
this._packer.packStruct(ACK_FAILURE, [], function (err) {
456481
return _this7._handleFatalError(err);
@@ -527,7 +552,7 @@ function connect(url) {
527552
// Default to using encryption if trust-on-first-use is available
528553
encrypted: config.encrypted == null ? (0, _features2["default"])("trust_on_first_use") : config.encrypted,
529554
// Default to using trust-on-first-use if it is available
530-
trust: config.trust || ((0, _features2["default"])("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_SIGNED_CERTIFICATES"),
555+
trust: config.trust || ((0, _features2["default"])("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES"),
531556
trustedCertificates: config.trustedCertificates || [],
532557
knownHosts: config.knownHosts
533558
}));

lib/v1/internal/pool.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ var Pool = (function () {
6363
_createClass(Pool, [{
6464
key: "acquire",
6565
value: function acquire() {
66-
if (this._pool.length > 0) {
67-
return this._pool.pop();
68-
} else {
69-
return this._create(this._release);
66+
var resource = undefined;
67+
while (this._pool.length) {
68+
resource = this._pool.pop();
69+
70+
if (this._validate(resource)) {
71+
return resource;
72+
}
7073
}
74+
75+
return this._create(this._release);
7176
}
7277
}, {
7378
key: "_release",

lib/v1/result-summary.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@ var ResultSummary = (function () {
4747

4848
this.statement = { text: statement, parameters: parameters };
4949
this.statementType = metadata.type;
50-
this.updateStatistics = new StatementStatistics(metadata.stats || {});
50+
var counters = new StatementStatistics(metadata.stats || {});
51+
this.counters = counters;
52+
//for backwards compatibility, remove in future version
53+
this.updateStatistics = counters;
5154
this.plan = metadata.plan || metadata.profile ? new Plan(metadata.plan || metadata.profile) : false;
5255
this.profile = metadata.profile ? new ProfiledPlan(metadata.profile) : false;
5356
this.notifications = this._buildNotifications(metadata.notifications);
57+
this.resultConsumedAfter = metadata.result_consumed_after;
58+
this.resultAvailableAfter = metadata.result_available_after;
5459
}
5560

5661
/**

lib/v1/result.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ var Result = (function () {
4848
* @param {StreamObserver} streamObserver
4949
* @param {mixed} statement - Cypher statement to execute
5050
* @param {Object} parameters - Map with parameters to use in statement
51+
* @param metaSupplier function, when called provides metadata
5152
*/
5253

53-
function Result(streamObserver, statement, parameters) {
54+
function Result(streamObserver, statement, parameters, metaSupplier) {
5455
_classCallCheck(this, Result);
5556

5657
this._streamObserver = streamObserver;
5758
this._p = null;
5859
this._statement = statement;
5960
this._parameters = parameters || {};
61+
this._metaSupplier = metaSupplier || function () {
62+
return {};
63+
};
6064
}
6165

6266
/**
@@ -133,7 +137,15 @@ var Result = (function () {
133137
var _this = this;
134138

135139
var onCompletedOriginal = observer.onCompleted;
140+
var self = this;
136141
var onCompletedWrapper = function onCompletedWrapper(metadata) {
142+
143+
var additionalMeta = self._metaSupplier();
144+
for (var key in additionalMeta) {
145+
if (additionalMeta.hasOwnProperty(key)) {
146+
metadata[key] = additionalMeta[key];
147+
}
148+
}
137149
var sum = new _resultSummary.ResultSummary(_this._statement, _this._parameters, metadata);
138150
onCompletedOriginal.call(observer, sum);
139151
};

0 commit comments

Comments
 (0)