Skip to content

Commit 71d3018

Browse files
authored
GODRIVER-1891 reduce complexity of future matrix testing (#669)
1 parent 7450663 commit 71d3018

File tree

9 files changed

+147
-301
lines changed

9 files changed

+147
-301
lines changed

.evergreen/config.yml

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,6 @@ functions:
190190
script: |
191191
${PREPARE_SHELL}
192192
193-
cp ${PROJECT_DIRECTORY}/data/certificates/server.pem ${DRIVERS_TOOLS}/.evergreen/x509gen/server.pem
194-
cp ${PROJECT_DIRECTORY}/data/certificates/ca.pem ${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem
195-
cp ${PROJECT_DIRECTORY}/data/certificates/client.pem ${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem
196-
cp ${PROJECT_DIRECTORY}/data/certificates/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
197-
198193
MONGODB_VERSION=${VERSION} \
199194
TOPOLOGY=${TOPOLOGY} \
200195
AUTH=${AUTH} \
@@ -211,7 +206,6 @@ functions:
211206
params:
212207
script: |
213208
${PREPARE_SHELL}
214-
cp ${PROJECT_DIRECTORY}/data/certificates/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
215209
216210
MONGODB_VERSION=${VERSION} \
217211
TOPOLOGY=${TOPOLOGY} \
@@ -257,6 +251,8 @@ functions:
257251
cat $i | tr -d '\r' > $i.new
258252
mv $i.new $i
259253
done
254+
# Copy client certificate because symlinks do not work on Windows.
255+
cp ${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
260256
261257
make-files-executable:
262258
- command: shell.exec
@@ -281,68 +277,10 @@ functions:
281277
type: test
282278
params:
283279
working_dir: src/go.mongodb.org/mongo-driver
280+
add_expansions_to_env: true
284281
script: |
285282
${PREPARE_SHELL}
286-
287-
if [ ${SSL} = "ssl" ]; then
288-
export MONGO_GO_DRIVER_CA_FILE="$PROJECT_DIRECTORY/data/certificates/ca.pem"
289-
290-
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
291-
export MONGO_GO_DRIVER_CA_FILE=$(cygpath -m $MONGO_GO_DRIVER_CA_FILE)
292-
fi
293-
fi
294-
295-
# Set temp credentials for AWS if python3 is available.
296-
#
297-
# Using python3-venv in Ubuntu 14.04 (an OS required for legacy server version
298-
# tasks) requires the use of apt-get, which we wish to avoid. So, we do not set
299-
# a python3 binary on Ubuntu 14.04. Setting AWS temp credentials for legacy
300-
# server version tasks is unneccesary, as temp credentials are only needed on 4.2+.
301-
if [ ! -z ${PYTHON3_BINARY} ]; then
302-
export AWS_ACCESS_KEY_ID="${cse_aws_access_key_id}"
303-
export AWS_SECRET_ACCESS_KEY="${cse_aws_secret_access_key}"
304-
export AWS_DEFAULT_REGION="us-east-1"
305-
${PYTHON3_BINARY} -m venv ./venv
306-
307-
# Set the PYTHON environment variable to point to the active python3 binary. This is used by the
308-
# set-temp-creds.sh script.
309-
if [ "Windows_NT" = "$OS" ]; then
310-
export PYTHON="$(pwd)/venv/Scripts/python"
311-
else
312-
export PYTHON="$(pwd)/venv/bin/python"
313-
fi
314-
315-
./venv/${VENV_BIN_DIR|bin}/pip3 install boto3
316-
. ${DRIVERS_TOOLS}/.evergreen/csfle/set-temp-creds.sh
317-
fi
318-
319-
# If GO_BUILD_TAGS is not set, set the default Go build tags to "cse" to enable
320-
# client-side encryption, which requires linking the libmongocrypt C library.
321-
if [ -z ${GO_BUILD_TAGS+x} ]; then
322-
GO_BUILD_TAGS="cse"
323-
fi
324-
325-
export GOFLAGS=-mod=vendor
326-
AUTH=${AUTH} \
327-
SSL=${SSL} \
328-
MONGODB_URI="${MONGODB_URI}" \
329-
TOPOLOGY=${TOPOLOGY} \
330-
MONGO_GO_DRIVER_COMPRESSOR=${MONGO_GO_DRIVER_COMPRESSOR} \
331-
BUILD_TAGS="-tags ${GO_BUILD_TAGS}" \
332-
AWS_ACCESS_KEY_ID="${cse_aws_access_key_id}" \
333-
AWS_SECRET_ACCESS_KEY="${cse_aws_secret_access_key}" \
334-
AWS_DEFAULT_REGION="us-east-1" \
335-
CSFLE_AWS_TEMP_ACCESS_KEY_ID="$CSFLE_AWS_TEMP_ACCESS_KEY_ID" \
336-
CSFLE_AWS_TEMP_SECRET_ACCESS_KEY="$CSFLE_AWS_TEMP_SECRET_ACCESS_KEY" \
337-
CSFLE_AWS_TEMP_SESSION_TOKEN="$CSFLE_AWS_TEMP_SESSION_TOKEN" \
338-
AZURE_TENANT_ID="${cse_azure_tenant_id}" \
339-
AZURE_CLIENT_ID="${cse_azure_client_id}" \
340-
AZURE_CLIENT_SECRET="${cse_azure_client_secret}" \
341-
GCP_EMAIL="${cse_gcp_email}" \
342-
GCP_PRIVATE_KEY="${cse_gcp_private_key}" \
343-
make evg-test \
344-
PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
345-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH
283+
sh ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh
346284
347285
send-perf-data:
348286
- command: json.send
@@ -530,9 +468,15 @@ functions:
530468
${PREPARE_SHELL}
531469
532470
if [ ${SSL} = "ssl" ]; then
533-
export MONGO_GO_DRIVER_CA_FILE="$PROJECT_DIRECTORY/data/certificates/ca.pem"
471+
export MONGO_GO_DRIVER_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
472+
export MONGO_GO_DRIVER_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
473+
export MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client-pkcs8-encrypted.pem"
474+
export MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client-pkcs8-unencrypted.pem"
534475
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
535476
export MONGO_GO_DRIVER_CA_FILE=$(cygpath -m $MONGO_GO_DRIVER_CA_FILE)
477+
export MONGO_GO_DRIVER_KEY_FILE=$(cygpath -m $MONGO_GO_DRIVER_KEY_FILE)
478+
export MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE=$(cygpath -m $MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE)
479+
export MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE=$(cygpath -m $MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE)
536480
fi
537481
fi
538482
@@ -666,7 +610,7 @@ functions:
666610
- command: shell.exec
667611
params:
668612
script: |
669-
DRIVERS_TOOLS=${DRIVERS_TOOLS} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop
613+
DRIVERS_TOOLS=${DRIVERS_TOOLS} MONGODB_URI=${MONGODB_URI} bash ${DRIVERS_TOOLS}/.evergreen/run-load-balancer.sh stop
670614
671615
add-aws-auth-variables-to-file:
672616
- command: shell.exec

.evergreen/run-tests.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
5+
export GOPATH=$(dirname $(dirname $(dirname `pwd`)))
6+
export GOCACHE="$(pwd)/.cache"
7+
export DRIVERS_TOOLS="$(pwd)/../drivers-tools"
8+
9+
if [ "Windows_NT" = "$OS" ]; then
10+
export GOPATH=$(cygpath -m $GOPATH)
11+
export GOCACHE=$(cygpath -m $GOCACHE)
12+
export DRIVERS_TOOLS=$(cygpath -m $DRIVERS_TOOLS)
13+
14+
if [ ! -d "c:/libmongocrypt/include" ]; then
15+
mkdir -p c:/libmongocrypt/include
16+
mkdir -p c:/libmongocrypt/bin
17+
curl https://s3.amazonaws.com/mciuploads/libmongocrypt/windows/latest_release/libmongocrypt.tar.gz --output libmongocrypt.tar.gz
18+
tar -xvzf libmongocrypt.tar.gz
19+
cp ./bin/mongocrypt.dll c:/libmongocrypt/bin
20+
cp ./include/mongocrypt/*.h c:/libmongocrypt/include
21+
export PATH=$PATH:/cygdrive/c/libmongocrypt/bin
22+
fi
23+
else
24+
if [ ! -d "libmongocrypt" ]; then
25+
git clone https://github.com/mongodb/libmongocrypt
26+
./libmongocrypt/.evergreen/compile.sh
27+
fi
28+
fi
29+
30+
export GOROOT="${GOROOT}"
31+
export PATH="${GOROOT}/bin:${GCC_PATH}:$GOPATH/bin:$PATH"
32+
export PROJECT="${project}"
33+
export PKG_CONFIG_PATH=$(pwd)/install/libmongocrypt/lib/pkgconfig:$(pwd)/install/mongo-c-driver/lib/pkgconfig
34+
export LD_LIBRARY_PATH=$(pwd)/install/libmongocrypt/lib
35+
export GOFLAGS=-mod=vendor
36+
37+
SSL=${SSL:-nossl}
38+
if [ "$SSL" != "nossl" ]; then
39+
export MONGO_GO_DRIVER_CA_FILE="${DRIVERS_TOOLS}/.evergreen/x509gen/ca.pem"
40+
export MONGO_GO_DRIVER_KEY_FILE="${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem"
41+
export MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE="${DRIVERS_TOOLS}/.evergreen/x509gen/client-pkcs8-encrypted.pem"
42+
export MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE="${DRIVERS_TOOLS}/.evergreen/x509gen/client-pkcs8-unencrypted.pem"
43+
44+
if [ "Windows_NT" = "$OS" ]; then
45+
export MONGO_GO_DRIVER_CA_FILE=$(cygpath -m $MONGO_GO_DRIVER_CA_FILE)
46+
export MONGO_GO_DRIVER_KEY_FILE=$(cygpath -m $MONGO_GO_DRIVER_KEY_FILE)
47+
export MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE=$(cygpath -m $MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE)
48+
export MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE=$(cygpath -m $MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE)
49+
fi
50+
fi
51+
52+
if [ -z ${AWS_ACCESS_KEY_ID+x} ]; then
53+
export AWS_ACCESS_KEY_ID="${cse_aws_access_key_id}"
54+
export AWS_SECRET_ACCESS_KEY="${cse_aws_secret_access_key}"
55+
fi
56+
57+
# Set temp credentials for AWS if python3 is available.
58+
#
59+
# Using python3-venv in Ubuntu 14.04 (an OS required for legacy server version
60+
# tasks) requires the use of apt-get, which we wish to avoid. So, we do not set
61+
# a python3 binary on Ubuntu 14.04. Setting AWS temp credentials for legacy
62+
# server version tasks is unneccesary, as temp credentials are only needed on 4.2+.
63+
if [ ! -z ${PYTHON3_BINARY} ]; then
64+
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
65+
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
66+
export AWS_DEFAULT_REGION="us-east-1"
67+
${PYTHON3_BINARY} -m venv ./venv
68+
69+
# Set the PYTHON environment variable to point to the active python3 binary. This is used by the
70+
# set-temp-creds.sh script.
71+
if [ "Windows_NT" = "$OS" ]; then
72+
export PYTHON="$(pwd)/venv/Scripts/python"
73+
else
74+
export PYTHON="$(pwd)/venv/bin/python"
75+
fi
76+
77+
./venv/${VENV_BIN_DIR:-bin}/pip3 install boto3
78+
. ${DRIVERS_TOOLS}/.evergreen/csfle/set-temp-creds.sh
79+
fi
80+
81+
# If GO_BUILD_TAGS is not set, set the default Go build tags to "cse" to enable
82+
# client-side encryption, which requires linking the libmongocrypt C library.
83+
if [ -z ${GO_BUILD_TAGS+x} ]; then
84+
GO_BUILD_TAGS="cse"
85+
fi
86+
87+
AUTH=${AUTH} \
88+
SSL=${SSL} \
89+
MONGO_GO_DRIVER_CA_FILE=${MONGO_GO_DRIVER_CA_FILE} \
90+
MONGO_GO_DRIVER_KEY_FILE=${MONGO_GO_DRIVER_KEY_FILE} \
91+
MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE=${MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE} \
92+
MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE=${MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE} \
93+
MONGODB_URI="${MONGODB_URI}" \
94+
TOPOLOGY=${TOPOLOGY} \
95+
MONGO_GO_DRIVER_COMPRESSOR=${MONGO_GO_DRIVER_COMPRESSOR} \
96+
BUILD_TAGS="-tags ${GO_BUILD_TAGS}" \
97+
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
98+
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
99+
AWS_DEFAULT_REGION="us-east-1" \
100+
CSFLE_AWS_TEMP_ACCESS_KEY_ID="$CSFLE_AWS_TEMP_ACCESS_KEY_ID" \
101+
CSFLE_AWS_TEMP_SECRET_ACCESS_KEY="$CSFLE_AWS_TEMP_SECRET_ACCESS_KEY" \
102+
CSFLE_AWS_TEMP_SESSION_TOKEN="$CSFLE_AWS_TEMP_SESSION_TOKEN" \
103+
AZURE_TENANT_ID="${cse_azure_tenant_id}" \
104+
AZURE_CLIENT_ID="${cse_azure_client_id}" \
105+
AZURE_CLIENT_SECRET="${cse_azure_client_secret}" \
106+
GCP_EMAIL="${cse_gcp_email}" \
107+
GCP_PRIVATE_KEY="${cse_gcp_private_key}" \
108+
make evg-test \
109+
PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
110+
LD_LIBRARY_PATH=$LD_LIBRARY_PATH

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,36 @@ MONGODB_URI="mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaS
171171

172172
### Testing Auth and TLS
173173

174-
To test authentication and TLS, first set up a MongoDB cluster with auth and TLS configured. Testing authentication requires a user with the `root` role on the `admin` database. The Go Driver repository comes with example certificates in the `data/certificates` directory. These certs can be used for testing. Here is an example command that would run a mongod with TLS correctly configured for tests:
174+
To test authentication and TLS, first set up a MongoDB cluster with auth and TLS configured. Testing authentication requires a user with the `root` role on the `admin` database. Here is an example command that would run a mongod with TLS correctly configured for tests. Either set or replace PATH_TO_SERVER_KEY_FILE and PATH_TO_CA_FILE with paths to their respective files:
175175

176176
```
177177
mongod \
178178
--auth \
179179
--tlsMode requireTLS \
180-
--tlsCertificateKeyFile $(pwd)/data/certificates/server.pem \
181-
--tlsCAFile $(pwd)/data/certificates/ca.pem \
180+
--tlsCertificateKeyFile $PATH_TO_SERVER_KEY_FILE \
181+
--tlsCAFile $PATH_TO_CA_FILE \
182182
--tlsAllowInvalidCertificates
183183
```
184184

185-
To run the tests with `make`, set `MONGO_GO_DRIVER_CA_FILE` to the location of the CA file used by the database, set `MONGODB_URI` to the connection string of the server, set `AUTH=auth`, and set `SSL=ssl`. For example:
185+
To run the tests with `make`, set:
186+
- `MONGO_GO_DRIVER_CA_FILE` to the location of the CA file used by the database
187+
- `MONGO_GO_DRIVER_KEY_FILE` to the location of the client key file
188+
- `MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE` to the location of the pkcs8 client key file encrypted with the password string: `password`
189+
- `MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE` to the location of the unencrypted pkcs8 key file
190+
- `MONGODB_URI` to the connection string of the server
191+
- `AUTH=auth`
192+
- `SSL=ssl`
193+
194+
For example:
186195

187196
```
188-
AUTH=auth SSL=ssl MONGO_GO_DRIVER_CA_FILE=$(pwd)/data/certificates/ca.pem MONGODB_URI="mongodb://user:password@localhost:27017/?authSource=admin" make
197+
AUTH=auth SSL=ssl \
198+
MONGO_GO_DRIVER_CA_FILE=$PATH_TO_CA_FILE \
199+
MONGO_GO_DRIVER_KEY_FILE=$PATH_TO_CLIENT_KEY_FILE \
200+
MONGO_GO_DRIVER_PKCS8_ENCRYPTED_KEY_FILE=$PATH_TO_ENCRYPTED_KEY_FILE \
201+
MONGO_GO_DRIVER_PKCS8_UNENCRYPTED_KEY_FILE=$PATH_TO_UNENCRYPTED_KEY_FILE \
202+
MONGODB_URI="mongodb://user:password@localhost:27017/?authSource=admin" \
203+
make
189204
```
190205

191206
Notes:

data/certificates/ca.pem

Lines changed: 0 additions & 21 deletions
This file was deleted.

data/certificates/client-pkcs8-encrypted.pem

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)