Skip to content

Commit c12137e

Browse files
committed
test: add ssl filter
1 parent 6061779 commit c12137e

File tree

3 files changed

+55
-34
lines changed

3 files changed

+55
-34
lines changed

test/functional/core/server.test.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Connection = core.Connection;
1414

1515
describe('Server tests', function() {
1616
it('should correctly connect server to single instance', {
17-
metadata: { requires: { topology: 'single' } },
17+
metadata: { requires: { topology: 'single', ssl: false } },
1818

1919
test: function(done) {
2020
const config = this.configuration;
@@ -34,7 +34,7 @@ describe('Server tests', function() {
3434
});
3535

3636
it('should correctly connect server to single instance and execute ismaster', {
37-
metadata: { requires: { topology: 'single' } },
37+
metadata: { requires: { topology: 'single', ssl: false } },
3838

3939
test: function(done) {
4040
const config = this.configuration;
@@ -60,7 +60,7 @@ describe('Server tests', function() {
6060
});
6161

6262
it('should correctly connect server to single instance and execute ismaster returning raw', {
63-
metadata: { requires: { topology: 'single' } },
63+
metadata: { requires: { topology: 'single', ssl: false } },
6464

6565
test: function(done) {
6666
const config = this.configuration;
@@ -93,7 +93,7 @@ describe('Server tests', function() {
9393
});
9494

9595
it('should correctly connect server to single instance and execute insert', {
96-
metadata: { requires: { topology: 'single' } },
96+
metadata: { requires: { topology: 'single', ssl: false } },
9797

9898
test: function(done) {
9999
const config = this.configuration;
@@ -128,7 +128,7 @@ describe('Server tests', function() {
128128
it(
129129
'should correctly connect server to single instance and send an uncompressed message if an uncompressible command is specified',
130130
{
131-
metadata: { requires: { topology: 'single' } },
131+
metadata: { requires: { topology: 'single', ssl: false } },
132132

133133
test: function(done) {
134134
const config = this.configuration;
@@ -163,7 +163,7 @@ describe('Server tests', function() {
163163
);
164164

165165
it('should correctly connect server to single instance and execute bulk insert', {
166-
metadata: { requires: { topology: 'single' } },
166+
metadata: { requires: { topology: 'single', ssl: false } },
167167

168168
test: function(done) {
169169
const config = this.configuration;
@@ -201,7 +201,7 @@ describe('Server tests', function() {
201201
});
202202

203203
it('should correctly connect server to single instance and execute insert with w:0', {
204-
metadata: { requires: { topology: 'single' } },
204+
metadata: { requires: { topology: 'single', ssl: false } },
205205

206206
test: function(done) {
207207
const config = this.configuration;
@@ -239,7 +239,7 @@ describe('Server tests', function() {
239239
});
240240

241241
it('should correctly connect server to single instance and execute update', {
242-
metadata: { requires: { topology: 'single' } },
242+
metadata: { requires: { topology: 'single', ssl: false } },
243243

244244
test: function(done) {
245245
const config = this.configuration;
@@ -278,7 +278,7 @@ describe('Server tests', function() {
278278
});
279279

280280
it('should correctly connect server to single instance and execute remove', {
281-
metadata: { requires: { topology: 'single' } },
281+
metadata: { requires: { topology: 'single', ssl: false } },
282282

283283
test: function(done) {
284284
const config = this.configuration;
@@ -318,7 +318,7 @@ describe('Server tests', function() {
318318
// Skipped due to use of topology manager
319319
it.skip('should correctly recover with multiple restarts', {
320320
metadata: {
321-
requires: { topology: ['single'] }
321+
requires: { topology: 'single', ssl: false }
322322
},
323323

324324
// The actual test we wish to run
@@ -404,7 +404,7 @@ describe('Server tests', function() {
404404
});
405405

406406
it('should correctly reconnect to server with automatic reconnect enabled', {
407-
metadata: { requires: { topology: 'single' } },
407+
metadata: { requires: { topology: 'single', ssl: false } },
408408
test: function(done) {
409409
const config = this.configuration;
410410
if (config.usingUnifiedTopology()) {
@@ -475,12 +475,7 @@ describe('Server tests', function() {
475475
});
476476

477477
it('should correctly reconnect to server with automatic reconnect disabled', {
478-
metadata: {
479-
requires: {
480-
topology: 'single'
481-
}
482-
// ignore: { travis:true }
483-
},
478+
metadata: { requires: { topology: 'single', ssl: false } },
484479

485480
test: function(done) {
486481
const config = this.configuration;
@@ -545,12 +540,7 @@ describe('Server tests', function() {
545540
});
546541

547542
it('should reconnect when initial connection failed', {
548-
metadata: {
549-
requires: {
550-
topology: 'single'
551-
},
552-
ignore: { travis: true }
553-
},
543+
metadata: { requires: { topology: 'single', ssl: false } },
554544

555545
test: function(done) {
556546
const config = this.configuration;
@@ -587,7 +577,7 @@ describe('Server tests', function() {
587577
});
588578

589579
it('should correctly place new connections in available list on reconnect', {
590-
metadata: { requires: { topology: 'single' } },
580+
metadata: { requires: { topology: 'single', ssl: false } },
591581
test: function(done) {
592582
const config = this.configuration;
593583
if (config.usingUnifiedTopology()) {
@@ -653,12 +643,7 @@ describe('Server tests', function() {
653643
});
654644

655645
it('should not overflow the poolSize due to concurrent operations', {
656-
metadata: {
657-
requires: {
658-
topology: 'single'
659-
},
660-
ignore: { travis: true }
661-
},
646+
metadata: { requires: { topology: 'single', ssl: false } },
662647

663648
test: function(done) {
664649
var self = this;
@@ -708,7 +693,8 @@ describe('Server tests', function() {
708693
metadata: {
709694
requires: {
710695
node: '>0.8.0',
711-
topology: ['single', 'ssl', 'wiredtiger']
696+
topology: 'single',
697+
ssl: false
712698
}
713699
},
714700

@@ -780,7 +766,7 @@ describe('Server tests', function() {
780766
});
781767

782768
it('should error when invalid compressors are specified', {
783-
metadata: { requires: { topology: 'single' } },
769+
metadata: { requires: { topology: 'single', ssl: false } },
784770

785771
test: function(done) {
786772
const config = this.configuration;
@@ -934,7 +920,7 @@ describe('Server tests', function() {
934920
it(
935921
'should correctly connect server to single instance and execute insert with snappy compression',
936922
{
937-
metadata: { requires: { topology: ['single'], mongodb: '>=3.5.x' } },
923+
metadata: { requires: { topology: 'single', mongodb: '>=3.5.x', ssl: false } },
938924

939925
test: function(done) {
940926
const config = this.configuration;
@@ -1021,7 +1007,7 @@ describe('Server tests', function() {
10211007

10221008
// NOTE: skipped for flakiness
10231009
it.skip('Should not try to reconnect forever if reconnectTries = 0', {
1024-
metadata: { requires: { topology: 'single' } },
1010+
metadata: { requires: { topology: 'single', ssl: false } },
10251011

10261012
test: function(done) {
10271013
const config = this.configuration;

test/tools/runner/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const fs = require('fs');
23
const url = require('url');
34
const qs = require('querystring');
45
const util = require('util');
@@ -67,6 +68,10 @@ class NativeConfiguration {
6768
return !!process.env.MONGODB_UNIFIED_TOPOLOGY;
6869
}
6970

71+
usingTLS() {
72+
return !!(process.env.SSL_KEY_FILE && process.env.SSL_CA_FILE);
73+
}
74+
7075
get tlsOptions() {
7176
const tlsCertificateKeyFile = process.env.SSL_KEY_FILE;
7277
const tlsCAFile = process.env.SSL_CA_FILE;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
/**
4+
* Filter for tests that require or don't support SSL
5+
*
6+
* example:
7+
* metadata: {
8+
* requires: {
9+
* ssl: true // only run test if SSL is enabled
10+
* ssl: false // only run test if SSL is not enabled
11+
* }
12+
* }
13+
*/
14+
class SSLFilter {
15+
constructor() {
16+
// Get environmental variables that are known
17+
this.ssl = !!(process.env.SSL_KEY_FILE && process.env.SSL_CA_FILE);
18+
}
19+
20+
filter(test) {
21+
if (!test.metadata) return true;
22+
if (!test.metadata.requires) return true;
23+
const ssl = test.metadata.requires.ssl;
24+
if (typeof ssl !== 'boolean') return true;
25+
if (this.ssl === ssl) return true;
26+
return false;
27+
}
28+
}
29+
30+
module.exports = SSLFilter;

0 commit comments

Comments
 (0)