Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit 6bd0ec2

Browse files
alenakhineikaRhys Howell
andauthored
COMPASS-4268: Use proper password for ssh (#277)
* fix: use proper password for ssh * test: remove slow and timeout * Use clone deep to ensure driver options remain unchanged after ssh tunnel injection Co-authored-by: Rhys Howell <rhys@rhysh@live.com>
1 parent 1355f97 commit 6bd0ec2

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

.eslintrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"env": {
33
"mocha": true,
4-
es6: true
4+
"es6": true
5+
},
6+
"parserOptions": {
7+
"ecmaVersion": 2018,
8+
"sourceType": "module"
59
},
610
"extends": ["mongodb-js/node"]
711
}

lib/connect.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const async = require('async');
44
const {
55
includes,
66
clone,
7+
cloneDeep,
78
assign,
89
isString,
910
isFunction,
@@ -128,7 +129,7 @@ const getTasks = (model, setupListeners) => {
128129
}
129130

130131
const ctx = (error, opts) => {
131-
options = opts;
132+
options = { ...model.driverOptions, ...opts };
132133

133134
if (error) {
134135
state.emit('status', { message, error });
@@ -210,7 +211,17 @@ const getTasks = (model, setupListeners) => {
210211
validOptions.useNewUrlParser = true;
211212
validOptions.useUnifiedTopology = true;
212213

213-
const mongoClient = new MongoClient(model.driverUrl, validOptions);
214+
const modelClone = cloneDeep(model, true);
215+
216+
if (model.sshTunnel !== 'NONE') {
217+
// Populate the SSH Tunnel options correctly
218+
modelClone.set({
219+
hostname: model.sshTunnelOptions.localAddr,
220+
port: model.sshTunnelOptions.localPort
221+
});
222+
}
223+
224+
const mongoClient = new MongoClient(modelClone.driverUrl, validOptions);
214225

215226
if (setupListeners) {
216227
setupListeners(mongoClient);

lib/model.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,7 @@ assign(derived, {
588588
req.query.ssl = 'false';
589589
}
590590

591-
const reqClone = clone(req);
592-
593-
return toURL(reqClone);
591+
return toURL(req);
594592
}
595593
},
596594
safeUrl: {

test/connect.test.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ const setupListeners = () => {};
1111
const data = require('mongodb-connection-fixture');
1212

1313
describe('connection model connector', () => {
14-
describe('local', function() {
15-
this.slow(2000);
16-
this.timeout(10000);
17-
14+
describe('local', () => {
1815
before(
1916
require('mongodb-runner/mocha/before')({ port: 27018, version: '4.0.0' })
2017
);
@@ -67,7 +64,7 @@ describe('connection model connector', () => {
6764
sshTunnelHostname: 'my.ssh-server.com',
6865
sshTunnelPassword: 'password',
6966
sshTunnelUsername: 'my-user',
70-
serverSelectionTimeoutMS: 1000
67+
extraOptions: { serverSelectionTimeoutMS: 100 }
7168
});
7269

7370
assert(model.isValid());
@@ -83,10 +80,7 @@ describe('connection model connector', () => {
8380
});
8481
});
8582

86-
describe('cloud #slow', function() {
87-
this.slow(5000);
88-
this.timeout(10000);
89-
83+
describe('cloud #slow', () => {
9084
data.MATRIX.map(d => {
9185
it.skip('should connect to ' + d.name, done => {
9286
connect(d, setupListeners, (err, client) => {

0 commit comments

Comments
 (0)