Skip to content

Commit eac708f

Browse files
ready for review
1 parent 3ce14a4 commit eac708f

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed

.github/workflows/encryption-tests.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ name: Encryption Tests
22

33
on:
44
push:
5-
branches: ['master', 'NODE-6505/ci-setup']
5+
branches: ['master']
6+
pull_request:
7+
branches: [ 'master' ]
68
workflow_dispatch: {}
79

810
permissions:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ examples/ecommerce-netlify-functions/.netlify/state.json
6767

6868
notes.md
6969
list.out
70+
71+
encrypted-cluster

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ If you have a question about Mongoose (not a bug report) please post it to eithe
4646
* execute `npm run test-tsd` to run the typescript tests
4747
* execute `npm run ts-benchmark` to run the typescript benchmark "performance test" for a single time.
4848
* 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.
49+
* in order to run tests that require an encrypted cluster locally, run `npm run test-encryption-local`. Alternatively, you can start an encrypted cluster using the `scripts/encrypted-cluster.sh` file
4950

5051
## Documentation
5152

mongocryptd.pid

Whitespace-only changes.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"license": "MIT",
2121
"dependencies": {
2222
"bson": "^6.7.0",
23+
"hugo": "^0.0.3",
2324
"kareem": "2.6.3",
2425
"mongodb": "~6.10.0",
2526
"mongodb-client-encryption": "^6.1.0",
@@ -106,6 +107,7 @@
106107
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
107108
"test-tsd": "node ./test/types/check-types-filename && tsd",
108109
"test-encryption": "mocha --exit ./test/encryption/*.test.js",
110+
"test-encryption-local": "chmod +x scripts/encrypted-cluster.sh && scripts/encrypted-cluster.sh",
109111
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
110112
"test-coverage": "nyc --reporter=html --reporter=text npm test",
111113
"ts-benchmark": "cd ./benchmarks/typescript/simple && npm install && npm run benchmark | node ../../../scripts/tsc-diagnostics-check"

scripts/encrypted-cluster.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
# sets up an encrypted mongodb cluster
4+
5+
if [ -d "encrypted-cluster" ]; then
6+
cd encrypted-cluster
7+
else
8+
mkdir encrypted-cluster
9+
cd encrypted-cluster
10+
11+
if [-d drivers-evergreen-tools]; then
12+
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git"
13+
fi
14+
15+
export DRIVERS_TOOLS=$(pwd)/drivers-evergreen-tools
16+
export MONGODB_VERSION=8.0
17+
export AUTH=true
18+
export MONGODB_BINARIES=$DRIVERS_TOOLS/mongodb/bin
19+
export NODE_DRIVER=~/dev/node-mongodb-native
20+
export MONGO_ORCHESTRATION_HOME=$DRIVERS_TOOLS/mo
21+
export PROJECT_ORCHESTRATION_HOME=$DRIVERS_TOOLS/.evergreen/orchestration
22+
export TOPOLOGY=sharded_cluster
23+
export SSL=nossl
24+
25+
cd $DRIVERS_TOOLS
26+
rm -rf mongosh mongodb mo
27+
mkdir mo
28+
cd -
29+
30+
rm expansions.sh 2> /dev/null
31+
32+
bash $DRIVERS_TOOLS/.evergreen/run-orchestration.sh
33+
fi
34+
35+
# IMPORTANT: extracts mongodb-uri, and starts the cluster of servers, store the uri for GitHub output
36+
37+
read -r -d '' SOURCE_SCRIPT << EOM
38+
const fs = require('fs');
39+
const file = fs.readFileSync('mo-expansion.yml', { encoding: 'utf-8' })
40+
.trim().split('\\n');
41+
const regex = /^(?<key>.*): "(?<value>.*)"$/;
42+
const variables = file.map(
43+
(line) => regex.exec(line.trim()).groups
44+
).map(
45+
({key, value}) => \`export \${key}='\${value}'\`
46+
).join('\n');
47+
48+
process.stdout.write(variables);
49+
process.stdout.write('\n');
50+
EOM
51+
52+
node --eval "$SOURCE_SCRIPT" | tee expansions.sh
53+
source expansions.sh
54+
55+
export MONGOOSE_TEST_URI=$MONGODB_URI
56+
57+
npm run test-encryption

test/encryption/encryption.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ describe('basic integration', () => {
4444
'db.coll': {
4545
bsonType: 'object',
4646
encryptMetadata: {
47-
keyId: [new mdb.UUID(dataKey)]
47+
keyId: [dataKey]
4848
},
4949
properties: {
5050
a: {
5151
encrypt: {
5252
bsonType: 'int',
5353
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random',
54-
keyId: [new mdb.UUID(dataKey)]
54+
keyId: [dataKey]
5555
}
5656
}
5757
}
@@ -78,9 +78,11 @@ describe('basic integration', () => {
7878
await encryptedClient.connect();
7979
await encryptedClient.db('db').collection('coll').insertOne({ a: 1 });
8080

81+
const { insertedId } = await encryptedClient.db('db').collection('coll').insertOne({ a: 1 });
82+
8183
// a dummyClient not configured with autoEncryption, returns a encrypted binary type, meaning that encryption succeeded
82-
const encryptedCursor = await dummyClient.db('db').collection('coll').find();
83-
const encryptedResult = await encryptedCursor.next();
84+
const encryptedResult = await dummyClient.db('db').collection('coll').findOne({ _id: insertedId });
85+
8486
assert.ok(encryptedResult);
8587
assert.ok(encryptedResult.a);
8688
assert.ok(isBsonType(encryptedResult.a, 'Binary'));

0 commit comments

Comments
 (0)