/
run-custom-csfle-tests.sh
101 lines (75 loc) · 3.42 KB
/
run-custom-csfle-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! /usr/bin/env bash
# Initiail checks for running these tests
if [ -z ${AWS_ACCESS_KEY_ID+omitted} ]; then echo "AWS_ACCESS_KEY_ID is unset" && exit 1; fi
if [ -z ${AWS_SECRET_ACCESS_KEY+omitted} ]; then echo "AWS_SECRET_ACCESS_KEY is unset" && exit 1; fi
if [ -z ${CSFLE_KMS_PROVIDERS+omitted} ]; then echo "CSFLE_KMS_PROVIDERS is unset" && exit 1; fi
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export CSFLE_KMS_PROVIDERS=${CSFLE_KMS_PROVIDERS}
[ -s "$PROJECT_DIRECTORY/node-artifacts/nvm/nvm.sh" ] && source "$PROJECT_DIRECTORY"/node-artifacts/nvm/nvm.sh
set -o xtrace # Write all commands first to stderr
set -o errexit # Exit the script with error if any of the commands fail
# Get access to the AWS temporary credentials:
echo "adding temporary AWS credentials to environment"
# CSFLE_AWS_TEMP_ACCESS_KEY_ID, CSFLE_AWS_TEMP_SECRET_ACCESS_KEY, CSFLE_AWS_TEMP_SESSION_TOKEN
. $DRIVERS_TOOLS/.evergreen/csfle/set-temp-creds.sh
ABS_PATH_TO_PATCH=$(pwd)
# Environment Variables:
# CSFLE_GIT_REF - set the git reference to checkout for a custom CSFLE version
# CDRIVER_GIT_REF - set the git reference to checkout for a custom CDRIVER version (this is for libbson)
CSFLE_GIT_REF=${CSFLE_GIT_REF:-master}
CDRIVER_GIT_REF=${CDRIVER_GIT_REF:-1.17.6}
rm -rf ../csfle-deps-tmp
mkdir -p ../csfle-deps-tmp
pushd ../csfle-deps-tmp
rm -rf libmongocrypt mongo-c-driver
git clone https://github.com/mongodb/libmongocrypt.git
pushd libmongocrypt
git fetch --tags
git checkout "$CSFLE_GIT_REF" -b csfle-custom
popd # libmongocrypt
git clone https://github.com/mongodb/mongo-c-driver.git
pushd mongo-c-driver
git fetch --tags
git checkout "$CDRIVER_GIT_REF" -b cdriver-custom
popd # mongo-c-driver
pushd libmongocrypt/bindings/node
npm install --production --ignore-scripts
source ./.evergreen/find_cmake.sh
bash ./etc/build-static.sh
popd # libmongocrypt/bindings/node
popd # ../csfle-deps-tmp
# copy mongodb-client-encryption into driver's node_modules
cp -R ../csfle-deps-tmp/libmongocrypt/bindings/node node_modules/mongodb-client-encryption
export MONGODB_URI=${MONGODB_URI}
set +o errexit # We want to run both test suites even if the first fails
npm run check:csfle
DRIVER_CSFLE_TEST_RESULT=$?
set -o errexit
# Great! our drivers tests ran
# there are tests inside the bindings repo that we also want to check
pushd ../csfle-deps-tmp/libmongocrypt/bindings/node
# a mongocryptd was certainly started by the driver tests,
# let us let the bindings tests start their own
killall mongocryptd || true
# only prod deps were installed earlier, install devDependencies here (except for mongodb!)
npm install --ignore-scripts
# copy mongodb into CSFLE's node_modules
rm -rf node_modules/mongodb
cp -R "$ABS_PATH_TO_PATCH" node_modules/mongodb
pushd node_modules/mongodb
# lets be sure we have compiled TS since driver tests don't need to compile
npm run build:ts
popd # node_modules/mongodb
# this variable needs to be empty
export MONGODB_NODE_SKIP_LIVE_TESTS=""
# all of the below must be defined (as well as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY)
export AWS_REGION="us-east-1"
export AWS_CMK_ID="arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0"
npm test -- --colors
popd # ../csfle-deps-tmp/libmongocrypt/bindings/node
# Exit the script in a way that will show evergreen a pass or fail
if [ $DRIVER_CSFLE_TEST_RESULT -ne 0 ]; then
echo "Driver tests failed, look above for results"
exit 1
fi