Skip to content

Commit a30b9bc

Browse files
author
Neo Technology Build Agent
committed
JS driver v1.1.0-M02: Checking in transpiled files for bower
1 parent 53f6758 commit a30b9bc

File tree

12 files changed

+1874
-598
lines changed

12 files changed

+1874
-598
lines changed

lib/browser/neo4j-web.js

Lines changed: 652 additions & 278 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: 997 additions & 278 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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ var _ConnectionStreamObserver = (function (_StreamObserver) {
213213
this._hasFailed = true;
214214
}
215215
}
216+
}, {
217+
key: 'onCompleted',
218+
value: function onCompleted(message) {
219+
if (this._driver.onCompleted) {
220+
this._driver.onCompleted(message);
221+
}
222+
}
216223
}]);
217224

218225
return _ConnectionStreamObserver;
@@ -248,15 +255,18 @@ var USER_AGENT = "neo4j-javascript/" + _version.VERSION;
248255
* // This means that by default, connections "just work" while still giving you
249256
* // good encrypted protection.
250257
* //
251-
* // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
258+
* // TRUST_CUSTOM_CA_SIGNED_CERTIFICATES is the classic approach to trust verification -
252259
* // whenever we establish an encrypted connection, we ensure the host is using
253260
* // an encryption certificate that is in, or is signed by, a certificate listed
254261
* // as trusted. In the web bundle, this list of trusted certificates is maintained
255262
* // by the web browser. In NodeJS, you configure the list with the next config option.
256-
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
263+
* //
264+
* // TRUST_SYSTEM_CA_SIGNED_CERTIFICATES meand that you trust whatever certificates
265+
* // are in the default certificate chain of th
266+
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES" | TRUST_CUSTOM_CA_SIGNED_CERTIFICATES | TRUST_SYSTEM_CA_SIGNED_CERTIFICATES,
257267
*
258268
* // List of one or more paths to trusted encryption certificates. This only
259-
* // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
269+
* // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".
260270
* // The certificate files should be in regular X.509 PEM format.
261271
* // For instance, ['./trusted.pem']
262272
* trustedCertificates: [],

lib/v1/index.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Object.defineProperty(exports, '__esModule', {
2323
value: true
2424
});
2525

26+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
27+
2628
var _integer = require('./integer');
2729

2830
var _driver = require('./driver');
@@ -31,22 +33,51 @@ var _graphTypes = require('./graph-types');
3133

3234
var _error = require('./error');
3335

36+
var _result = require('./result');
37+
38+
var _result2 = _interopRequireDefault(_result);
39+
40+
var _resultSummary = require('./result-summary');
41+
42+
var _resultSummary2 = _interopRequireDefault(_resultSummary);
43+
44+
var _record = require('./record');
45+
3446
exports['default'] = {
3547
driver: _driver.driver,
3648
int: _integer.int,
3749
isInt: _integer.isInt,
3850
Neo4jError: _error.Neo4jError,
3951
auth: {
4052
basic: function basic(username, password) {
41-
return { scheme: "basic", principal: username, credentials: password };
53+
var realm = arguments.length <= 2 || arguments[2] === undefined ? undefined : arguments[2];
54+
55+
if (realm) {
56+
return { scheme: "basic", principal: username, credentials: password, realm: realm };
57+
} else {
58+
return { scheme: "basic", principal: username, credentials: password };
59+
}
60+
},
61+
custom: function custom(principal, credentials, realm, scheme) {
62+
var parameters = arguments.length <= 4 || arguments[4] === undefined ? undefined : arguments[4];
63+
64+
if (parameters) {
65+
return { scheme: scheme, principal: principal, credentials: credentials, realm: realm,
66+
parameters: parameters };
67+
} else {
68+
return { scheme: scheme, principal: principal, credentials: credentials, realm: realm };
69+
}
4270
}
4371
},
4472
types: {
4573
Node: _graphTypes.Node,
4674
Relationship: _graphTypes.Relationship,
4775
UnboundRelationship: _graphTypes.UnboundRelationship,
4876
PathSegment: _graphTypes.PathSegment,
49-
Path: _graphTypes.Path
77+
Path: _graphTypes.Path,
78+
Result: _result2['default'],
79+
ResultSummary: _resultSummary2['default'],
80+
Record: _record.Record
5081
}
5182
};
5283
module.exports = exports['default'];

lib/v1/internal/ch-node.js

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,35 @@ function userHome() {
6464
return process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'];
6565
}
6666

67+
function mkFullPath(pathToCreate) {
68+
try {
69+
_fs2['default'].mkdirSync(pathToCreate);
70+
} catch (e) {
71+
if (e.code === 'ENOENT') {
72+
// Create parent dir
73+
mkFullPath(_path2['default'].dirname(pathToCreate));
74+
// And now try again
75+
mkFullPath(pathToCreate);
76+
return;
77+
}
78+
if (e.code === 'EEXIST') {
79+
return;
80+
}
81+
throw e;
82+
}
83+
}
84+
6785
function loadFingerprint(serverId, knownHostsPath, cb) {
68-
if (!_fs2['default'].existsSync(knownHostsPath)) {
69-
cb(null);
70-
return;
86+
try {
87+
_fs2['default'].accessSync(knownHostsPath);
88+
} catch (e) {
89+
return cb(null);
7190
}
7291
var found = false;
7392
require('readline').createInterface({
7493
input: _fs2['default'].createReadStream(knownHostsPath)
7594
}).on('line', function (line) {
76-
if (line.startsWith(serverId)) {
95+
if (!found && line.startsWith(serverId)) {
7796
found = true;
7897
cb(line.split(" ")[1]);
7998
}
@@ -84,31 +103,77 @@ function loadFingerprint(serverId, knownHostsPath, cb) {
84103
});
85104
}
86105

87-
function storeFingerprint(serverId, knownHostsPath, fingerprint) {
106+
var _lockFingerprintFromAppending = {};
107+
function storeFingerprint(serverId, knownHostsPath, fingerprint, cb) {
108+
// we check if the serverId has been appended
109+
if (!!_lockFingerprintFromAppending[serverId]) {
110+
// if it has, we ignore it
111+
return cb(null);
112+
}
113+
114+
// we make the line as appended
115+
// ( 1 is more efficient to store than true because true is an oddball )
116+
_lockFingerprintFromAppending[serverId] = 1;
117+
118+
// If file doesn't exist, create full path to it
119+
try {
120+
_fs2['default'].accessSync(knownHostsPath);
121+
} catch (_) {
122+
mkFullPath(_path2['default'].dirname(knownHostsPath));
123+
}
124+
88125
_fs2['default'].appendFile(knownHostsPath, serverId + " " + fingerprint + _os.EOL, "utf8", function (err) {
126+
delete _lockFingerprintFromAppending[serverId];
89127
if (err) {
90128
console.log(err);
91129
}
130+
return cb(err);
92131
});
93132
}
94133

95134
var TrustStrategy = {
135+
/**
136+
* @deprecated Since version 1.0. Will be deleted in a future version. TRUST_CUSTOM_CA_SIGNED_CERTIFICATES.
137+
*/
96138
TRUST_SIGNED_CERTIFICATES: function TRUST_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
139+
console.log("`TRUST_SIGNED_CERTIFICATES` has been deprecated as option and will be removed in a future version of " + "the driver. Pleas use `TRUST_CUSTOM_CA_SIGNED_CERTIFICATES` instead.");
140+
return TrustStrategy.TRUST_CUSTOM_CA_SIGNED_CERTIFICATES(opts, onSuccess, onFailure);
141+
},
142+
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES: function TRUST_CUSTOM_CA_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
97143
if (!opts.trustedCertificates || opts.trustedCertificates.length == 0) {
98-
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=\"" + _util.ENCRYPTION_OFF + "\"" + "in your driver configuration."));
144+
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=\"" + _util.ENCRYPTION_OFF + "\"" + "in your driver configuration."));
99145
return;
100146
}
101147

102148
var tlsOpts = {
103-
ca: opts.trustedCertificates.map(_fs2['default'].readFileSync),
149+
ca: opts.trustedCertificates.map(function (f) {
150+
return _fs2['default'].readFileSync(f);
151+
}),
104152
// Because we manually check for this in the connect callback, to give
105153
// a more helpful error to the user
106154
rejectUnauthorized: false
107155
};
108156

109157
var socket = _tls2['default'].connect(opts.port, opts.host, tlsOpts, function () {
110158
if (!socket.authorized) {
111-
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=\"" + _util.ENCRYPTION_OFF + "\"` in the driver" + " options."));
159+
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=\"" + _util.ENCRYPTION_OFF + "\"`" + " in the driver options. Socket responded with: " + socket.authorizationError));
160+
} else {
161+
onSuccess();
162+
}
163+
});
164+
socket.on('error', onFailure);
165+
return socket;
166+
},
167+
TRUST_SYSTEM_CA_SIGNED_CERTIFICATES: function TRUST_SYSTEM_CA_SIGNED_CERTIFICATES(opts, onSuccess, onFailure) {
168+
169+
var tlsOpts = {
170+
// Because we manually check for this in the connect callback, to give
171+
// a more helpful error to the user
172+
rejectUnauthorized: false
173+
};
174+
var socket = _tls2['default'].connect(opts.port, opts.host, tlsOpts, function () {
175+
if (!socket.authorized) {
176+
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=\"" + _util.ENCRYPTION_OFF + "\"`" + " in the driver options. Socket responded with: " + socket.authorizationError));
112177
} else {
113178
onSuccess();
114179
}
@@ -130,7 +195,7 @@ var TrustStrategy = {
130195
// the raw cert cannot be accessed (or, at least I couldn't find a way to)
131196
// therefore, we can't generate a SHA512 fingerprint, meaning we can't
132197
// do TOFU, and the safe approach is to fail.
133-
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:\"" + _util.ENCRYPTION_OFF + "\"`."));
198+
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:\"" + _util.ENCRYPTION_OFF + "\"`."));
134199
return;
135200
}
136201

@@ -142,8 +207,12 @@ var TrustStrategy = {
142207
if (knownFingerprint === serverFingerprint) {
143208
onSuccess();
144209
} else if (knownFingerprint == null) {
145-
storeFingerprint(serverId, knownHostsPath, serverFingerprint);
146-
onSuccess();
210+
storeFingerprint(serverId, knownHostsPath, serverFingerprint, function (err) {
211+
if (err) {
212+
return onFailure(err);
213+
}
214+
return onSuccess();
215+
});
147216
} else {
148217
onFailure((0, _error.newError)("Database encryption certificate has changed, and no longer " + "matches the certificate stored for " + serverId + " in `" + knownHostsPath + "`. As a security precaution, this driver will not automatically trust the new " + "certificate, because doing so would allow an attacker to pretend to be the Neo4j " + "instance we want to connect to. The certificate provided by the server looks like: " + serverCert + ". If you trust that this certificate is valid, simply remove the line " + "starting with " + serverId + " in `" + knownHostsPath + "`, and the driver will " + "update the file with the new certificate. You can configure which file the driver " + "should use to store this information by setting `knownHosts` to another path in " + "your driver configuration - and you can disable encryption there as well using " + "`encrypted:\"" + _util.ENCRYPTION_OFF + "\"`."));
149218
}
@@ -167,7 +236,7 @@ function connect(opts, onSuccess) {
167236
} else if (TrustStrategy[opts.trust]) {
168237
return TrustStrategy[opts.trust](opts, onSuccess, onFailure);
169238
} else {
170-
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:\"" + _util.ENCRYPTION_OFF + "\"`. 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."));
239+
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:\"" + _util.ENCRYPTION_OFF + "\"`. 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."));
171240
}
172241
}
173242

@@ -211,6 +280,7 @@ var NodeChannel = (function () {
211280
});
212281

213282
self._conn.on('error', self._handleConnectionError);
283+
self._conn.on('end', self._handleConnectionTerminated);
214284

215285
// Drain all pending messages
216286
var pending = self._pending;
@@ -229,6 +299,14 @@ var NodeChannel = (function () {
229299
this.onerror(err);
230300
}
231301
}
302+
}, {
303+
key: '_handleConnectionTerminated',
304+
value: function _handleConnectionTerminated() {
305+
this._error = new Error('Connection was closed by server');
306+
if (this.onerror) {
307+
this.onerror(this._error);
308+
}
309+
}
232310
}, {
233311
key: 'isEncrypted',
234312
value: function isEncrypted() {
@@ -268,6 +346,7 @@ var NodeChannel = (function () {
268346
this._open = false;
269347
if (this._conn) {
270348
this._conn.end();
349+
this._conn.removeListener('end', this._handleConnectionTerminated);
271350
this._conn.on('end', cb);
272351
} else {
273352
cb();

lib/v1/internal/ch-websocket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ var WebSocketChannel = (function () {
6262
var scheme = "ws";
6363
//Allow boolean for backwards compatibility
6464
if (opts.encrypted === true || opts.encrypted === _util.ENCRYPTION_ON || opts.encrypted === _util.ENCRYPTION_NON_LOCAL && !(0, _util.isLocalHost)(opts.host)) {
65-
if (!opts.trust || opts.trust === "TRUST_SIGNED_CERTIFICATES") {
65+
if (!opts.trust || opts.trust === "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES") {
6666
scheme = "wss";
6767
} else {
68-
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:\"" + _util.ENCRYPTION_OFF + "\"` in the driver configuration.");
68+
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:\"" + _util.ENCRYPTION_OFF + "\"` in the driver configuration.");
6969
return;
7070
}
7171
}

lib/v1/internal/connector.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ var Connection = (function () {
380380
return _this2._handleFatalError(err);
381381
});
382382
this._chunker.messageBoundary();
383+
this.sync();
383384
}
384385

385386
/** Queue a RUN-message to be sent to the database */
@@ -533,7 +534,7 @@ function connect(url) {
533534
// Default to using ENCRYPTION_NON_LOCAL if trust-on-first-use is available
534535
encrypted: (0, _util.shouldEncrypt)(config.encrypted, (0, _features2["default"])("trust_on_first_use") ? _util.ENCRYPTION_NON_LOCAL : _util.ENCRYPTION_OFF, host(url)),
535536
// Default to using TRUST_ON_FIRST_USE if it is available
536-
trust: config.trust || ((0, _features2["default"])("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_SIGNED_CERTIFICATES"),
537+
trust: config.trust || ((0, _features2["default"])("trust_on_first_use") ? "TRUST_ON_FIRST_USE" : "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES"),
537538
trustedCertificates: config.trustedCertificates || [],
538539
knownHosts: config.knownHosts
539540
}));

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
/**

0 commit comments

Comments
 (0)