From 5dbf929af412900aa8eebac92c00e004df5910d5 Mon Sep 17 00:00:00 2001 From: Cledson Date: Wed, 8 Apr 2020 17:08:16 -0300 Subject: [PATCH] [mongoose] Added connection options related to auto encryption using CSFLE (#43723) * added new connection options related to the new feature csfle * added basic test case for auto-encryption in mongoose client connection --- types/mongoose/index.d.ts | 10 ++++++++++ types/mongoose/mongoose-tests.ts | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 398239535b..e19b646ba8 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -37,6 +37,7 @@ // Dongjun Lee // Valentin Agachi // Jan Nemcik +// Cl3dson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -395,6 +396,15 @@ declare module "mongoose" { * is set to true.(default: false) */ autoCreate?: boolean; + + /** Configure csfle as especified in MongoDB official guide */ + autoEncryption?: { + keyVaultNamespace: string, + kmsProviders: any, + schemaMap: any, + extraOptions?: any + } + /** Specify a journal write concern (default: false). */ journal?: boolean; diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index ef99393420..548d63e930 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -37,6 +37,22 @@ const connection3 = mongoose.connect(connectUri, function (error) { error.stack; }); +/** + * Test taken from MongoDB CSFLE guide + * https://docs.mongodb.com/drivers/use-cases/client-side-field-level-encryption-guide + */ + +const connection4:Promise = mongoose.connect(connectUri,{ + useNewUrlParser: true, + useUnifiedTopology: true, + autoEncryption: { + keyVaultNamespace: 'encryption.__keyVault', + kmsProviders: {}, + schemaMap: {}, + extraOptions: {} + } +}) + var mongooseConnection: mongoose.Connection = mongoose.createConnection(); mongooseConnection.dropDatabase().then(()=>{}); mongooseConnection.dropCollection('foo').then(()=>{});