Skip to content

Commit 40858d4

Browse files
requested changes
1 parent 62d18d8 commit 40858d4

File tree

6 files changed

+88
-77
lines changed

6 files changed

+88
-77
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module.exports = {
1414
'**/docs/js/native.js',
1515
'!.*',
1616
'node_modules',
17-
'.git'
17+
'.git',
18+
'encrypted-cluster'
1819
],
1920
overrides: [
2021
{

mongocryptd.pid

Whitespace-only changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
106106
"test-tsd": "node ./test/types/check-types-filename && tsd",
107107
"test-encryption": "mocha --exit ./test/encryption/*.test.js",
108-
"test-encryption-local": "chmod +x scripts/run-encryption-tests-local.sh && scripts/run-encryption-tests-local.sh",
108+
"test-encryption-local": "bash scripts/run-encryption-tests-local.sh",
109109
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
110110
"test-coverage": "nyc --reporter=html --reporter=text npm test",
111111
"ts-benchmark": "cd ./benchmarks/typescript/simple && npm install && npm run benchmark | node ../../../scripts/tsc-diagnostics-check"

scripts/run-encryption-tests-local.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env bash
22

3-
# sets up an encrypted mongodb cluster
3+
# sets up an encrypted mongodb cluster, adds relevant variables to the environment, and runs encryption tests
44

55
export CWD=$(pwd);
66

7+
# set up encrypted mongodb cluster if the encrypted-cluster folder does not exist
8+
# note: for tooling, cluster set-up and configuration look into the 'scripts/start-encrypted-cluster.sh' script
79
if [ -d "encrypted-cluster" ]; then
810
cd encrypted-cluster
911
else
1012
source $CWD/scripts/start-encrypted-cluster.sh
1113
fi
1214

13-
# IMPORTANT: extracts mongodb-uri, and starts the cluster of servers, store the uri for GitHub output
14-
15+
# extracts MONGOOSE_TEST_URI and CRYPT_SHARED_LIB_PATH from .yml file into environment variables for this test run
1516
read -r -d '' SOURCE_SCRIPT << EOM
1617
const fs = require('fs');
1718
const file = fs.readFileSync('mo-expansion.yml', { encoding: 'utf-8' })
@@ -32,4 +33,5 @@ source expansions.sh
3233

3334
export MONGOOSE_TEST_URI=$MONGODB_URI
3435

36+
# run encryption tests
3537
npm run test-encryption

scripts/start-encrypted-cluster.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1+
# creates a encrypted cluster (sharded on 8.0 server)
12

23
export CWD=$(pwd);
34
mkdir encrypted-cluster
45
cd encrypted-cluster
56

7+
# note:
8+
# we're using drivers-evergreen-tools which is a repo that handles cluster set-up for us.
9+
# if you'd like to make changes to the cluster settings, edit the exported variables below.
10+
# for configuration options for the exported variables, see here: https://github.com/mongodb-labs/drivers-evergreen-tools/blob/master/.evergreen/run-orchestration.sh
11+
# after this script is run, the encrypted-cluster/ folder will notably contain the following:
12+
# 'mo-expansion.yml' file which contains for your cluster URI and crypt shared library path
13+
# 'drivers-evergreen-tools/mongodb/bin' which contain executables for other mongodb libraries such as mongocryptd, mongosh, and mongod
614
if [ ! -d "drivers-evergreen-tools/" ]; then
715
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git"
816
fi
917

18+
# configure cluster settings
1019
export DRIVERS_TOOLS=$CWD/encrypted-cluster/drivers-evergreen-tools
1120
export MONGODB_VERSION=8.0
1221
export AUTH=true
1322
export MONGODB_BINARIES=$DRIVERS_TOOLS/mongodb/bin
14-
export NODE_DRIVER=~/dev/node-mongodb-native
1523
export MONGO_ORCHESTRATION_HOME=$DRIVERS_TOOLS/mo
1624
export PROJECT_ORCHESTRATION_HOME=$DRIVERS_TOOLS/.evergreen/orchestration
1725
export TOPOLOGY=sharded_cluster
@@ -24,4 +32,5 @@ cd -
2432

2533
rm expansions.sh 2> /dev/null
2634

27-
bash $DRIVERS_TOOLS/.evergreen/run-orchestration.sh
35+
# start cluster
36+
bash $DRIVERS_TOOLS/.evergreen/run-orchestration.sh

test/encryption/encryption.test.js

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -6,92 +6,91 @@ const isBsonType = require('../../lib/helpers/isBsonType');
66

77
const LOCAL_KEY = Buffer.from('Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', 'base64');
88

9-
describe('environmental variables', () => {
10-
it('MONGOOSE_TEST_URI is set', async function() {
11-
const uri = process.env.MONGOOSE_TEST_URI;
12-
assert.ok(uri);
13-
});
9+
describe('ci', () => {
10+
describe('environmental variables', () => {
11+
it('MONGOOSE_TEST_URI is set', async function() {
12+
const uri = process.env.MONGOOSE_TEST_URI;
13+
assert.ok(uri);
14+
});
1415

15-
it('CRYPT_SHARED_LIB_PATH is set', async function() {
16-
const shared_library_path = process.env.CRYPT_SHARED_LIB_PATH;
17-
assert.ok(shared_library_path);
16+
it('CRYPT_SHARED_LIB_PATH is set', async function() {
17+
const shared_library_path = process.env.CRYPT_SHARED_LIB_PATH;
18+
assert.ok(shared_library_path);
19+
});
1820
});
19-
});
2021

21-
describe('basic integration', () => {
22-
let keyVaultClient;
23-
let dataKey;
24-
let encryptedClient;
25-
let dummyClient;
22+
describe('basic integration', () => {
23+
let keyVaultClient;
24+
let dataKey;
25+
let encryptedClient;
26+
let unencryptedClient;
2627

27-
beforeEach(async function() {
28-
keyVaultClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI);
29-
await keyVaultClient.connect();
30-
await keyVaultClient.db('keyvault').collection('datakeys');
31-
const clientEncryption = new mdb.ClientEncryption(keyVaultClient, {
32-
keyVaultNamespace: 'keyvault.datakeys',
33-
kmsProviders: { local: { key: LOCAL_KEY } }
34-
});
35-
dataKey = await clientEncryption.createDataKey('local');
28+
beforeEach(async function() {
29+
keyVaultClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI);
30+
await keyVaultClient.connect();
31+
await keyVaultClient.db('keyvault').collection('datakeys');
32+
const clientEncryption = new mdb.ClientEncryption(keyVaultClient, {
33+
keyVaultNamespace: 'keyvault.datakeys',
34+
kmsProviders: { local: { key: LOCAL_KEY } }
35+
});
36+
dataKey = await clientEncryption.createDataKey('local');
3637

37-
encryptedClient = new mdb.MongoClient(
38-
process.env.MONGOOSE_TEST_URI,
39-
{
40-
autoEncryption: {
41-
keyVaultNamespace: 'keyvault.datakeys',
42-
kmsProviders: { local: { key: LOCAL_KEY } },
43-
schemaMap: {
44-
'db.coll': {
45-
bsonType: 'object',
46-
encryptMetadata: {
47-
keyId: [dataKey]
48-
},
49-
properties: {
50-
a: {
51-
encrypt: {
52-
bsonType: 'int',
53-
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random',
54-
keyId: [dataKey]
38+
encryptedClient = new mdb.MongoClient(
39+
process.env.MONGOOSE_TEST_URI,
40+
{
41+
autoEncryption: {
42+
keyVaultNamespace: 'keyvault.datakeys',
43+
kmsProviders: { local: { key: LOCAL_KEY } },
44+
schemaMap: {
45+
'db.coll': {
46+
bsonType: 'object',
47+
encryptMetadata: {
48+
keyId: [dataKey]
49+
},
50+
properties: {
51+
a: {
52+
encrypt: {
53+
bsonType: 'int',
54+
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random',
55+
keyId: [dataKey]
56+
}
5557
}
5658
}
5759
}
60+
},
61+
extraOptions: {
62+
cryptdSharedLibRequired: true,
63+
cryptSharedLibPath: process.env.CRYPT_SHARED_LIB_PATH
5864
}
59-
},
60-
extraOptions: {
61-
cryptdSharedLibRequired: true,
62-
cryptSharedLibPath: process.env.CRYPT_SHARED_LIB_PATH
6365
}
6466
}
65-
}
66-
);
67+
);
6768

68-
dummyClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI);
69-
});
70-
71-
afterEach(async function() {
72-
await keyVaultClient.close();
73-
await encryptedClient.close();
74-
await dummyClient.close();
75-
});
69+
unencryptedClient = new mdb.MongoClient(process.env.MONGOOSE_TEST_URI);
70+
});
7671

77-
it('supports mongodb csfle auto-encryption integration', async() => {
78-
await encryptedClient.connect();
79-
await encryptedClient.db('db').collection('coll').insertOne({ a: 1 });
72+
afterEach(async function() {
73+
await keyVaultClient.close();
74+
await encryptedClient.close();
75+
await unencryptedClient.close();
76+
});
8077

81-
const { insertedId } = await encryptedClient.db('db').collection('coll').insertOne({ a: 1 });
78+
it('ci set-up should support basic mongodb auto-encryption integration', async() => {
79+
await encryptedClient.connect();
80+
const { insertedId } = await encryptedClient.db('db').collection('coll').insertOne({ a: 1 });
8281

83-
// a dummyClient not configured with autoEncryption, returns a encrypted binary type, meaning that encryption succeeded
84-
const encryptedResult = await dummyClient.db('db').collection('coll').findOne({ _id: insertedId });
82+
// client not configured with autoEncryption, returns a encrypted binary type, meaning that encryption succeeded
83+
const encryptedResult = await unencryptedClient.db('db').collection('coll').findOne({ _id: insertedId });
8584

86-
assert.ok(encryptedResult);
87-
assert.ok(encryptedResult.a);
88-
assert.ok(isBsonType(encryptedResult.a, 'Binary'));
89-
assert.ok(encryptedResult.a.sub_type === 6);
85+
assert.ok(encryptedResult);
86+
assert.ok(encryptedResult.a);
87+
assert.ok(isBsonType(encryptedResult.a, 'Binary'));
88+
assert.ok(encryptedResult.a.sub_type === 6);
9089

91-
// when the encryptedClient runs a find, the original unencrypted value is returned
92-
const unencryptedCursor = await encryptedClient.db('db').collection('coll').find();
93-
const unencryptedResult = await unencryptedCursor.next();
94-
assert.ok(unencryptedResult);
95-
assert.ok(unencryptedResult.a === 1);
90+
// when the encryptedClient runs a find, the original unencrypted value is returned
91+
const unencryptedResult = await encryptedClient.db('db').collection('coll').findOne({ _id: insertedId });
92+
assert.ok(unencryptedResult);
93+
assert.ok(unencryptedResult.a === 1);
94+
});
9695
});
9796
});

0 commit comments

Comments
 (0)