Skip to content

Commit 84733ff

Browse files
committed
test: use tls for tests if env vars are provided
1 parent 7c23641 commit 84733ff

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

test/tools/runner/config.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,38 @@ class NativeConfiguration {
6767
return !!process.env.MONGODB_UNIFIED_TOPOLOGY;
6868
}
6969

70+
get tlsOptions() {
71+
const tlsCertificateKeyFile = process.env.SSL_KEY_FILE;
72+
const tlsCAFile = process.env.SSL_CA_FILE;
73+
if (tlsCertificateKeyFile && tlsCertificateKeyFile) {
74+
return { tls: true, tlsCertificateKeyFile, tlsCAFile };
75+
}
76+
return {};
77+
}
78+
79+
get unifiedOptions() {
80+
if (this.usingUnifiedTopology()) {
81+
return { useUnifiedTopology: true, minHeartbeatFrequencyMS: 100 };
82+
}
83+
return {};
84+
}
85+
7086
newClient(dbOptions, serverOptions) {
7187
// support MongoClient contructor form (url, options) for `newClient`
7288
if (typeof dbOptions === 'string') {
7389
return new MongoClient(
7490
dbOptions,
75-
this.usingUnifiedTopology()
76-
? Object.assign({ useUnifiedTopology: true, minHeartbeatFrequencyMS: 100 }, serverOptions)
77-
: serverOptions
91+
Object.assign({}, this.unifiedOptions, this.tlsOptions, serverOptions)
7892
);
7993
}
8094

8195
dbOptions = dbOptions || {};
82-
serverOptions = Object.assign({}, { haInterval: 100 }, serverOptions);
83-
if (this.usingUnifiedTopology()) {
84-
serverOptions.useUnifiedTopology = true;
85-
serverOptions.minHeartbeatFrequencyMS = 100;
86-
}
96+
serverOptions = Object.assign(
97+
{ haInterval: 100 },
98+
this.unifiedOptions,
99+
this.tlsOptions,
100+
serverOptions
101+
);
87102

88103
// Fall back
89104
let dbHost = (serverOptions && serverOptions.host) || this.options.host;

test/tools/runner/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ before(function(_done) {
6161
// )} topology`
6262
// );
6363

64-
const client = new MongoClient(MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true });
64+
const options = { useNewUrlParser: true, useUnifiedTopology: true };
65+
66+
const tlsCertificateKeyFile = process.env.SSL_KEY_FILE;
67+
const tlsCAFile = process.env.SSL_CA_FILE;
68+
69+
if (tlsCertificateKeyFile && tlsCertificateKeyFile) {
70+
Object.assign(options, { tls: true, tlsCertificateKeyFile, tlsCAFile });
71+
}
72+
73+
const client = new MongoClient(MONGODB_URI, options);
6574
const done = err => client.close(err2 => _done(err || err2));
6675

6776
client.connect(err => {

0 commit comments

Comments
 (0)