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