From 06ffdead0036e6648bbe8d425f0fe73f671a6cd2 Mon Sep 17 00:00:00 2001 From: Aditi Khare Date: Thu, 9 Jan 2025 17:29:47 -0500 Subject: [PATCH] comments addressed readd dependency readd dependency lint readd dependency readd dependency fix dep fix dep2 fix dep2 fix dep3 fix dep4 fix dep5 fix dep6 --- .github/workflows/encryption-tests.yml | 2 + CONTRIBUTING.md | 9 ++- package.json | 2 +- scripts/configure-cluster-with-encryption.sh | 83 +++++++++++--------- scripts/run-encryption-tests.sh | 23 ------ 5 files changed, 57 insertions(+), 62 deletions(-) delete mode 100755 scripts/run-encryption-tests.sh diff --git a/.github/workflows/encryption-tests.yml b/.github/workflows/encryption-tests.yml index 521aae66ab..263ebaedc1 100644 --- a/.github/workflows/encryption-tests.yml +++ b/.github/workflows/encryption-tests.yml @@ -31,5 +31,7 @@ jobs: node-version: latest - name: Install Dependencies run: npm install + - name: Install mongodb-client-encryption + run: npm install mongodb-client-encryption - name: Run Tests run: npm run test-encryption diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 103d03a6ef..18e99b6657 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,8 +46,13 @@ If you have a question about Mongoose (not a bug report) please post it to eithe * execute `npm run test-tsd` to run the typescript tests * execute `npm run ts-benchmark` to run the typescript benchmark "performance test" for a single time. * execute `npm run ts-benchmark-watch` to run the typescript benchmark "performance test" while watching changes on types folder. Note: Make sure to commit all changes before executing this command. -* in order to run tests that require an cluster with encryption locally, run `npm run test-encryption`. Alternatively, you can start an encrypted cluster using the `scripts/configure-cluster-with-encryption.sh` file. -* These scripts can take a few minutes to run. If a encryption script is exited prematurely, restart the shell and delete the `data/` directory to ensure clean-up. +* in order to run tests that require an cluster with encryption locally, run `npm run test-encryption`/ Alternatively, you can start an encrypted cluster using the `scripts/configure-cluster-with-encryption.sh` file. + * These scripts can take a few minutes to run. + * To change an encryption configuration, it is recommended to follow these steps: + * Edit the variables in `scripts/configure-cluster-with-encryption.sh` with your desired configuration. + * Restart your shell. + * Delete the `data/` directory if it exists. + * Finally, run the configuration script. ## Documentation diff --git a/package.json b/package.json index 39d4451eeb..cdf2556c7c 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js", "test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js", "test-tsd": "node ./test/types/check-types-filename && tsd", - "test-encryption": "bash scripts/run-encryption-tests.sh", + "test-encryption": "bash scripts/configure-cluster-with-encryption.sh && mocha --exit ./test/encryption/*.test.js && npm uninstall mongodb-client-encryption > /dev/null", "tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}", "test-coverage": "nyc --reporter=html --reporter=text npm test", "ts-benchmark": "cd ./benchmarks/typescript/simple && npm install && npm run benchmark | node ../../../scripts/tsc-diagnostics-check" diff --git a/scripts/configure-cluster-with-encryption.sh b/scripts/configure-cluster-with-encryption.sh index 9c4adf330b..8f366bc4bb 100644 --- a/scripts/configure-cluster-with-encryption.sh +++ b/scripts/configure-cluster-with-encryption.sh @@ -5,39 +5,50 @@ # this script downloads all tools required to use FLE with mongodb, then starts a cluster of the provided configuration (sharded on 8.0 server) export CWD=$(pwd); -mkdir data -cd data - -# install encryption dependency -npm install mongodb-client-encryption > /dev/null - -# note: - # we're using drivers-evergreen-tools which is a repo used by MongoDB drivers to start clusters for testing. - # if you'd like to make changes to the cluster settings, edit the exported variables below. - # for configuration options for the exported variables, see here: https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-orchestration.sh - # after this script is run, the data/ folder will notably contain the following: - # 'mo-expansion.yml' file which contains for your cluster URI and crypt shared library path - # 'drivers-evergreen-tools/mongodb/bin' which contain executables for other mongodb libraries such as mongocryptd, mongosh, and mongod -if [ ! -d "drivers-evergreen-tools/" ]; then - git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" -fi - -# configure cluster settings -export DRIVERS_TOOLS=$CWD/data/drivers-evergreen-tools -export MONGODB_VERSION=8.0 -export AUTH=true -export MONGODB_BINARIES=$DRIVERS_TOOLS/mongodb/bin -export MONGO_ORCHESTRATION_HOME=$DRIVERS_TOOLS/mo -export PROJECT_ORCHESTRATION_HOME=$DRIVERS_TOOLS/.evergreen/orchestration -export TOPOLOGY=sharded_cluster -export SSL=nossl - -cd $DRIVERS_TOOLS -rm -rf mongosh mongodb mo -mkdir mo -cd - - -rm expansions.sh 2> /dev/null - -# start cluster -bash $DRIVERS_TOOLS/.evergreen/run-orchestration.sh + +# install extra dependency +npm install mongodb-client-encryption + +# set up mongodb cluster and encryption configuration if the data/ folder does not exist +if [ ! -d "data" ]; then + + mkdir data + cd data + + # note: + # we're using drivers-evergreen-tools which is a repo used by MongoDB drivers to start clusters for testing. + # if you'd like to make changes to the cluster settings, edit the exported variables below. + # for configuration options for the exported variables, see here: https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-orchestration.sh + # after this script is run, the data/ folder will notably contain the following: + # 'mo-expansion.yml' file which contains for your cluster URI and crypt shared library path + # 'drivers-evergreen-tools/mongodb/bin' which contain executables for other mongodb libraries such as mongocryptd, mongosh, and mongod + if [ ! -d "drivers-evergreen-tools/" ]; then + git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" + fi + + # configure cluster settings + export DRIVERS_TOOLS=$CWD/data/drivers-evergreen-tools + export MONGODB_VERSION=8.0 + export AUTH=true + export MONGODB_BINARIES=$DRIVERS_TOOLS/mongodb/bin + export MONGO_ORCHESTRATION_HOME=$DRIVERS_TOOLS/mo + export PROJECT_ORCHESTRATION_HOME=$DRIVERS_TOOLS/.evergreen/orchestration + export TOPOLOGY=sharded_cluster + export SSL=nossl + + cd $DRIVERS_TOOLS + rm -rf mongosh mongodb mo + mkdir mo + cd - + + rm expansions.sh 2> /dev/null + + echo 'Configuring Cluster...' + + # start cluster + (bash $DRIVERS_TOOLS/.evergreen/run-orchestration.sh) 1> /dev/null 2> /dev/null + + echo 'Cluster Configuration Finished!' + + cd .. +fi \ No newline at end of file diff --git a/scripts/run-encryption-tests.sh b/scripts/run-encryption-tests.sh deleted file mode 100755 index 60b7dfae24..0000000000 --- a/scripts/run-encryption-tests.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -# sets up mongodb cluster and encryption configuration, adds relevant variables to the environment, and runs encryption tests - -export CWD=$(pwd); - -# install encryption dependency -npm install mongodb-client-encryption > /dev/null - -# set up mongodb cluster and encryption configuration if the data/ folder does not exist -# note: for tooling, cluster set-up and configuration look into the 'scripts/configure-cluster-with-encryption.sh' script -if [ -d "data" ]; then - cd data -else - source $CWD/scripts/configure-cluster-with-encryption.sh -fi - -# run encryption tests -cd .. -npx mocha --exit ./test/encryption/*.test.js - -# uninstall encryption dependency -npm uninstall mongodb-client-encryption > /dev/null \ No newline at end of file