forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci(NODE-6505): Setup CI #4
Closed
Closed
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1ccf38e
temp
aditi-khare-mongoDB aeda36b
temp
aditi-khare-mongoDB e5d8cad
temp 2
aditi-khare-mongoDB a041206
test
aditi-khare-mongoDB 0c978a2
edit
aditi-khare-mongoDB f8cbb9a
removed errors
aditi-khare-mongoDB 2fa3417
on push
aditi-khare-mongoDB c71d3c2
test
aditi-khare-mongoDB e6facfe
path
aditi-khare-mongoDB 06f9758
path
aditi-khare-mongoDB 86f7874
path
aditi-khare-mongoDB 7a30734
path
aditi-khare-mongoDB b39c754
fixed
aditi-khare-mongoDB ccb726e
typo
aditi-khare-mongoDB b0a1c3c
install mocha
aditi-khare-mongoDB 6198ade
fixed?
aditi-khare-mongoDB a135e79
fix tests
aditi-khare-mongoDB ca25868
run tests
aditi-khare-mongoDB 270d151
ready for rereview
aditi-khare-mongoDB 69dbda6
ready for rereview 2
aditi-khare-mongoDB 3ce14a4
typo
aditi-khare-mongoDB eac708f
ready for review
aditi-khare-mongoDB f38366b
change to two files for local testing
aditi-khare-mongoDB 62d18d8
fixed deps
aditi-khare-mongoDB 40858d4
requested changes
aditi-khare-mongoDB d6044e7
fix
aditi-khare-mongoDB 08f4c23
fix wording
aditi-khare-mongoDB 1098636
change all occurences of encrypted-cluster to data
aditi-khare-mongoDB 955cedf
remove extra gha call - use local script instead
aditi-khare-mongoDB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Encryption Tests | ||
|
||
on: | ||
push: | ||
branches: ['master'] | ||
pull_request: | ||
branches: [ 'master' ] | ||
workflow_dispatch: {} | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
id-token: write | ||
|
||
jobs: | ||
run-tests: | ||
permissions: | ||
# required for all workflows | ||
security-events: write | ||
id-token: write | ||
contents: write | ||
runs-on: ubuntu-latest | ||
name: Encryption tests | ||
env: | ||
FORCE_COLOR: true | ||
steps: | ||
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0 | ||
- name: Setup node | ||
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 | ||
with: | ||
node-version: latest | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Install mongodb-client-encryption | ||
run: npm install mongodb-client-encryption | ||
- name: Set up cluster | ||
id: setup-cluster | ||
uses: mongodb-labs/drivers-evergreen-tools@master | ||
with: | ||
version: 8.0.0 | ||
topology: sharded_cluster | ||
auth: auth | ||
- name: Run Tests | ||
run: npm run test-encryption | ||
env: | ||
MONGOOSE_TEST_URI: ${{ steps.setup-cluster.outputs.cluster-uri }} | ||
CRYPT_SHARED_LIB_PATH: ${{ steps.setup-cluster.outputs.crypt-shared-lib-path }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,3 +67,6 @@ examples/ecommerce-netlify-functions/.netlify/state.json | |
|
||
notes.md | ||
list.out | ||
|
||
data | ||
*.pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# note: in order to use FLE with mongodb, we must | ||
# have mongocryptd or the shared library downloaded | ||
# have an enterprise server >= 4.2 | ||
|
||
# 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 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
baileympearson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# sets up mongodb cluster and encryption configuration, adds relevant variables to the environment, and runs encryption tests | ||
|
||
export CWD=$(pwd); | ||
|
||
# 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 | ||
|
||
# extracts MONGOOSE_TEST_URI and CRYPT_SHARED_LIB_PATH from .yml file into environment variables for this test run | ||
baileympearson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
read -r -d '' SOURCE_SCRIPT << EOM | ||
const fs = require('fs'); | ||
baileympearson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const file = fs.readFileSync('mo-expansion.yml', { encoding: 'utf-8' }) | ||
.trim().split('\\n'); | ||
const regex = /^(?<key>.*): "(?<value>.*)"$/; | ||
const variables = file.map( | ||
(line) => regex.exec(line.trim()).groups | ||
).map( | ||
({key, value}) => \`export \${key}='\${value}'\` | ||
).join('\n'); | ||
|
||
process.stdout.write(variables); | ||
process.stdout.write('\n'); | ||
EOM | ||
|
||
node --eval "$SOURCE_SCRIPT" | tee expansions.sh | ||
source expansions.sh | ||
|
||
export MONGOOSE_TEST_URI=$MONGODB_URI | ||
|
||
# run encryption tests | ||
npm run test-encryption |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
const mdb = require('mongodb'); | ||
const isBsonType = require('../../lib/helpers/isBsonType'); | ||
|
||
const LOCAL_KEY = Buffer.from('Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', 'base64'); | ||
|
||
describe('ci', () => { | ||
describe('environmental variables', () => { | ||
it('MONGOOSE_TEST_URI is set', async function() { | ||
const uri = process.env.MONGOOSE_TEST_URI; | ||
assert.ok(uri); | ||
}); | ||
|
||
it('CRYPT_SHARED_LIB_PATH is set', async function() { | ||
const shared_library_path = process.env.CRYPT_SHARED_LIB_PATH; | ||
assert.ok(shared_library_path); | ||
}); | ||
}); | ||
|
||
describe('basic integration', () => { | ||
let keyVaultClient; | ||
let dataKey; | ||
let encryptedClient; | ||
let unencryptedClient; | ||
|
||
beforeEach(async function() { | ||
keyVaultClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI); | ||
await keyVaultClient.connect(); | ||
await keyVaultClient.db('keyvault').collection('datakeys'); | ||
const clientEncryption = new mdb.ClientEncryption(keyVaultClient, { | ||
keyVaultNamespace: 'keyvault.datakeys', | ||
kmsProviders: { local: { key: LOCAL_KEY } } | ||
}); | ||
dataKey = await clientEncryption.createDataKey('local'); | ||
|
||
encryptedClient = new mdb.MongoClient( | ||
process.env.MONGOOSE_TEST_URI, | ||
{ | ||
autoEncryption: { | ||
keyVaultNamespace: 'keyvault.datakeys', | ||
kmsProviders: { local: { key: LOCAL_KEY } }, | ||
schemaMap: { | ||
'db.coll': { | ||
bsonType: 'object', | ||
encryptMetadata: { | ||
keyId: [dataKey] | ||
}, | ||
properties: { | ||
a: { | ||
encrypt: { | ||
bsonType: 'int', | ||
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random', | ||
keyId: [dataKey] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
extraOptions: { | ||
cryptdSharedLibRequired: true, | ||
cryptSharedLibPath: process.env.CRYPT_SHARED_LIB_PATH | ||
} | ||
} | ||
} | ||
); | ||
|
||
unencryptedClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI); | ||
}); | ||
|
||
afterEach(async function() { | ||
await keyVaultClient.close(); | ||
await encryptedClient.close(); | ||
await unencryptedClient.close(); | ||
}); | ||
|
||
it('ci set-up should support basic mongodb auto-encryption integration', async() => { | ||
await encryptedClient.connect(); | ||
const { insertedId } = await encryptedClient.db('db').collection('coll').insertOne({ a: 1 }); | ||
|
||
// client not configured with autoEncryption, returns a encrypted binary type, meaning that encryption succeeded | ||
const encryptedResult = await unencryptedClient.db('db').collection('coll').findOne({ _id: insertedId }); | ||
|
||
assert.ok(encryptedResult); | ||
assert.ok(encryptedResult.a); | ||
assert.ok(isBsonType(encryptedResult.a, 'Binary')); | ||
assert.ok(encryptedResult.a.sub_type === 6); | ||
|
||
// when the encryptedClient runs a find, the original unencrypted value is returned | ||
const unencryptedResult = await encryptedClient.db('db').collection('coll').findOne({ _id: insertedId }); | ||
assert.ok(unencryptedResult); | ||
assert.ok(unencryptedResult.a === 1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have tooling to run encryption tests using drivers-evergreen-tools - can we just use the same tooling in CI instead of using the github action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call!