@@ -960,7 +960,6 @@ srDVjIT3LsvTqw==`,
960960 return ;
961961 }
962962 expect . fail ( 'missed exception' ) ;
963- break ;
964963 default :
965964 throw new Error ( `unreachable ${ kmsName } ` ) ;
966965 }
@@ -1058,6 +1057,97 @@ srDVjIT3LsvTqw==`,
10581057 expect ( printedOutput ) . to . deep . equal ( [ ] ) ;
10591058 } ) ;
10601059
1060+ it ( 'allows $lookup with a collection with automatic encryption' , async function ( ) {
1061+ const keyMongo = new Mongo (
1062+ instanceState ,
1063+ uri ,
1064+ {
1065+ keyVaultNamespace : `${ dbname } .__keyVault` ,
1066+ kmsProviders : { local : { key : 'A' . repeat ( 128 ) } } ,
1067+ } ,
1068+ { } ,
1069+ serviceProvider
1070+ ) ;
1071+
1072+ await keyMongo . connect ( ) ;
1073+ instanceState . mongos . push ( keyMongo ) ;
1074+
1075+ const keyVault = await keyMongo . getKeyVault ( ) ;
1076+
1077+ const dataKey1 = await keyVault . createKey ( 'local' ) ;
1078+ const dataKey2 = await keyVault . createKey ( 'local' ) ;
1079+
1080+ const schemaMap = {
1081+ 'test.coll1' : {
1082+ bsonType : 'object' ,
1083+ properties : {
1084+ phoneNumber : {
1085+ encrypt : {
1086+ bsonType : 'string' ,
1087+ keyId : [ dataKey1 ] ,
1088+ algorithm : 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' ,
1089+ } ,
1090+ } ,
1091+ key : {
1092+ bsonType : 'string' ,
1093+ } ,
1094+ } ,
1095+ } ,
1096+ 'test.coll2' : {
1097+ bsonType : 'object' ,
1098+ properties : {
1099+ phoneNumber : {
1100+ encrypt : {
1101+ bsonType : 'string' ,
1102+ keyId : [ dataKey2 ] ,
1103+ algorithm : 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' ,
1104+ } ,
1105+ } ,
1106+ key : {
1107+ bsonType : 'string' ,
1108+ } ,
1109+ } ,
1110+ } ,
1111+ } ;
1112+
1113+ const autoMongo = new Mongo ( instanceState , uri , {
1114+ keyVaultNamespace : `${ dbname } .__keyVault` ,
1115+ kmsProviders : { local : { key : 'A' . repeat ( 128 ) } } ,
1116+ schemaMap,
1117+ } ) ;
1118+
1119+ const coll1 = autoMongo . getDB ( 'test' ) . getCollection ( 'coll1' ) ;
1120+ await coll1 . insertMany ( [
1121+ { phoneNumber : '123-456-7890' , key : 'foo' } ,
1122+ { phoneNumber : '123-456-7891' , key : 'bar' } ,
1123+ ] ) ;
1124+
1125+ const coll2 = autoMongo . getDB ( 'test' ) . getCollection ( 'coll2' ) ;
1126+ await coll2 . insertMany ( [
1127+ { phoneNumber : '123-456-7892' , key : 'baz' } ,
1128+ { phoneNumber : '123-456-7893' , key : 'foo' } ,
1129+ ] ) ;
1130+ const result = await (
1131+ await coll1 . aggregate ( [
1132+ {
1133+ $lookup : {
1134+ from : 'coll2' ,
1135+ localField : 'key' ,
1136+ foreignField : 'key' ,
1137+ as : 'lookupMatch' ,
1138+ } ,
1139+ } ,
1140+ ] )
1141+ )
1142+ . map ( ( { key, lookupMatch } ) => ( { key, size : lookupMatch . length } ) )
1143+ . toArray ( ) ;
1144+
1145+ expect ( result ) . deep . equals ( [
1146+ { key : 'foo' , size : 1 } ,
1147+ { key : 'bar' , size : 0 } ,
1148+ ] ) ;
1149+ } ) ;
1150+
10611151 it ( 'prints a warning when creating the keyAltNames index fails' , async function ( ) {
10621152 const mongo = new Mongo (
10631153 instanceState ,
0 commit comments