@@ -6,92 +6,91 @@ const isBsonType = require('../../lib/helpers/isBsonType');
66
77const 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