Skip to content

Commit 56298bf

Browse files
authored
chore(ci): add tls support test to evergreen
NODE-877
1 parent 5255657 commit 56298bf

File tree

7 files changed

+124
-13
lines changed

7 files changed

+124
-13
lines changed

.evergreen/config.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ functions:
7676
params:
7777
script: |
7878
${PREPARE_SHELL}
79-
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
79+
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} \
80+
AUTH=${AUTH} SSL=${SSL} \
81+
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
82+
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
8083
- command: expansions.update
8184
params:
8285
file: mo-expansion.yml
@@ -98,20 +101,18 @@ functions:
98101
type: test
99102
params:
100103
working_dir: src
101-
script: >
104+
script: |
102105
${PREPARE_SHELL}
103106
104-
105107
if [ -n "${CLIENT_ENCRYPTION}" ]; then
106108
# Disable xtrace (just in case it was accidentally set).
107109
set +x
108110
. ./prepare_client_encryption.sh
109111
rm -f ./prepare_client_encryption.sh
110112
fi
111113
112-
113-
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} MONGODB_URI="${MONGODB_URI}" bash
114-
${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
114+
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} MONGODB_URI="${MONGODB_URI}" \
115+
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
115116
run checks:
116117
- command: shell.exec
117118
type: test
@@ -179,6 +180,15 @@ functions:
179180
script: |
180181
MONGODB_URI='${plain_auth_mongodb_uri}' NODE_LTS_NAME='${NODE_LTS_NAME}' \
181182
bash ${PROJECT_DIRECTORY}/.evergreen/run-ldap-tests.sh
183+
run tls tests:
184+
- command: shell.exec
185+
type: test
186+
params:
187+
working_dir: src
188+
script: |
189+
NODE_LTS_NAME=${NODE_LTS_NAME} DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
190+
SSL_CA_FILE="${SSL_CA_FILE}" SSL_KEY_FILE="${SSL_KEY_FILE}" \
191+
MONGODB_URI="${MONGODB_URI}" bash ${PROJECT_DIRECTORY}/.evergreen/run-tls-tests.sh
182192
pre:
183193
- func: fetch source
184194
- func: prepare resources
@@ -776,6 +786,17 @@ tasks:
776786
commands:
777787
- func: install dependencies
778788
- func: run ldap tests
789+
- name: test-tls-support
790+
tags:
791+
- tls-support
792+
commands:
793+
- func: install dependencies
794+
- func: bootstrap mongo-orchestration
795+
vars:
796+
SSL: ssl
797+
VERSION: latest
798+
TOPOLOGY: server
799+
- func: run tls tests
779800
- name: run-checks
780801
tags:
781802
- run-checks
@@ -841,6 +862,7 @@ buildvariants:
841862
- test-2.6-sharded_cluster-unified
842863
- test-atlas-connectivity
843864
- test-auth-ldap
865+
- test-tls-support
844866
- name: macos-1014-dubnium
845867
display_name: macOS 10.14 Node Dubnium
846868
run_on: macos-1014
@@ -1008,6 +1030,7 @@ buildvariants:
10081030
- test-3.2-sharded_cluster-unified
10091031
- test-atlas-connectivity
10101032
- test-auth-ldap
1033+
- test-tls-support
10111034
- name: ubuntu-18.04-dubnium
10121035
display_name: Ubuntu 18.04 Node Dubnium
10131036
run_on: ubuntu1804-test

.evergreen/config.yml.in

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ functions:
9494
params:
9595
script: |
9696
${PREPARE_SHELL}
97-
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
97+
MONGODB_VERSION=${VERSION} TOPOLOGY=${TOPOLOGY} \
98+
AUTH=${AUTH} SSL=${SSL} \
99+
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
100+
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
98101
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
99102
- command: expansions.update
100103
params:
@@ -128,7 +131,8 @@ functions:
128131
rm -f ./prepare_client_encryption.sh
129132
fi
130133

131-
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} MONGODB_URI="${MONGODB_URI}" bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
134+
AUTH=${AUTH} SSL=${SSL} UNIFIED=${UNIFIED} MONGODB_URI="${MONGODB_URI}" \
135+
bash ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
132136

133137
"run checks":
134138
- command: shell.exec
@@ -215,6 +219,17 @@ functions:
215219
script: |
216220
MONGODB_URI='${plain_auth_mongodb_uri}' NODE_LTS_NAME='${NODE_LTS_NAME}' \
217221
bash ${PROJECT_DIRECTORY}/.evergreen/run-ldap-tests.sh
222+
223+
"run tls tests":
224+
- command: shell.exec
225+
type: test
226+
params:
227+
working_dir: "src"
228+
script: |
229+
NODE_LTS_NAME=${NODE_LTS_NAME} DRIVERS_TOOLS="${DRIVERS_TOOLS}" \
230+
SSL_CA_FILE="${SSL_CA_FILE}" SSL_KEY_FILE="${SSL_KEY_FILE}" \
231+
MONGODB_URI="${MONGODB_URI}" bash ${PROJECT_DIRECTORY}/.evergreen/run-tls-tests.sh
232+
218233
pre:
219234
- func: "fetch source"
220235
- func: "prepare resources"

.evergreen/generate_evergreen_tasks.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ function makeTask({ mongoVersion, topology }) {
9595
}
9696

9797
MONGODB_VERSIONS.forEach(mongoVersion => {
98-
TOPOLOGIES.forEach(topology => {
99-
TASKS.push(makeTask({ mongoVersion, topology }));
100-
});
98+
TOPOLOGIES.forEach(topology =>
99+
TASKS.push(makeTask({ mongoVersion, topology }))
100+
);
101101
});
102102

103103
// singleton task for connectivity tests
@@ -111,6 +111,22 @@ TASKS.push(
111111
name: 'test-auth-ldap',
112112
tags: ['auth', 'ldap'],
113113
commands: [{ func: 'install dependencies' }, { func: 'run ldap tests' }]
114+
},
115+
{
116+
name: 'test-tls-support',
117+
tags: ['tls-support'],
118+
commands: [
119+
{ func: 'install dependencies' },
120+
{
121+
func: 'bootstrap mongo-orchestration',
122+
vars: {
123+
SSL: 'ssl',
124+
VERSION: 'latest',
125+
TOPOLOGY: 'server'
126+
}
127+
},
128+
{ func: 'run tls tests' }
129+
]
114130
}
115131
);
116132

.evergreen/run-tests.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ set -o errexit # Exit the script with error if any of the commands fail
1010
# MARCH Machine Architecture. Defaults to lowercase uname -m
1111

1212
AUTH=${AUTH:-noauth}
13-
SSL=${SSL:-nossl}
1413
UNIFIED=${UNIFIED:-}
1514
MONGODB_URI=${MONGODB_URI:-}
1615

16+
# ssl setup
17+
SSL=${SSL:-nossl}
18+
if [ "$SSL" != "nossl" ]; then
19+
export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
20+
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
21+
fi
22+
1723
# run tests
1824
echo "Running $AUTH tests over $SSL, connecting to $MONGODB_URI"
1925

.evergreen/run-tls-tests.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -o errexit # Exit the script with error if any of the commands fail
4+
5+
export PROJECT_DIRECTORY="$(pwd)"
6+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
7+
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
8+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
9+
export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
10+
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
11+
12+
npm run check:tls

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
},
6666
"scripts": {
6767
"atlas": "mocha --opts '{}' ./test/manual/atlas_connectivity.test.js",
68-
"check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
68+
"check:ldap": "mocha --opts '{}' test/manual/ldap.test.js",
69+
"check:tls": "mocha --opts '{}' test/manual/tls_support.test.js",
6970
"test": "npm run lint && mocha --recursive test/functional test/unit test/core",
7071
"test-nolint": "mocha --recursive test/functional test/unit test/core",
7172
"coverage": "istanbul cover mongodb-test-runner -- -t 60000 test/core test/unit test/functional",

test/manual/tls_support.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
const MongoClient = require('../..').MongoClient;
3+
4+
const REQUIRED_ENV = ['MONGODB_URI', 'SSL_KEY_FILE', 'SSL_CA_FILE'];
5+
6+
describe('TLS Support', function() {
7+
for (let key of REQUIRED_ENV) {
8+
if (process.env[key] == null) {
9+
throw new Error(`skipping SSL tests, ${key} environment variable is not defined`);
10+
}
11+
}
12+
13+
const connectionString = process.env.MONGODB_URI;
14+
const tlsCertificateKeyFile = process.env.SSL_KEY_FILE;
15+
const tlsCAFile = process.env.SSL_CA_FILE;
16+
17+
it(
18+
'should connect with tls',
19+
makeConnectionTest(connectionString, { tls: true, tlsCertificateKeyFile, tlsCAFile })
20+
);
21+
});
22+
23+
function makeConnectionTest(connectionString, clientOptions) {
24+
return function() {
25+
const client = new MongoClient(connectionString, clientOptions);
26+
27+
return client
28+
.connect()
29+
.then(() => client.db('admin').command({ ismaster: 1 }))
30+
.then(() =>
31+
client
32+
.db('test')
33+
.collection('test')
34+
.findOne({})
35+
)
36+
.then(() => client.close());
37+
};
38+
}

0 commit comments

Comments
 (0)