@@ -1090,39 +1090,138 @@ describe('encryption integration tests', () => {
1090
1090
/ e n c r y p t e d f i e l d s c a n n o t b e d e c l a r e d o n b o t h t h e b a s e s c h e m a a n d t h e c h i l d s c h e m a i n a d i s c r i m i n a t o r \. p a t h = n a m e /
1091
1091
) ;
1092
1092
} ) ;
1093
+
1094
+ it ( 'throws on duplicate keys declared on root and child discriminators, parent with fle, child without' , async function ( ) {
1095
+ const schema = new Schema ( {
1096
+ name : {
1097
+ type : String , encrypt : { keyId }
1098
+ }
1099
+ } , {
1100
+ encryptionType : 'queryableEncryption'
1101
+ } ) ;
1102
+ model = connection . model ( 'Schema' , schema ) ;
1103
+ assert . throws ( ( ) => model . discriminator ( 'Test' , new Schema ( {
1104
+ name : {
1105
+ type : String
1106
+ }
1107
+ } ) ) ,
1108
+ / e n c r y p t e d f i e l d s c a n n o t h a v e t h e s a m e p a t h a s a n o n - e n c r y p t e d f i e l d f o r d i s c r i m i n a t o r s . p a t h = n a m e /
1109
+ ) ;
1110
+ } ) ;
1111
+
1112
+ it ( 'throws on duplicate keys declared on root and child discriminators, child with fle, parent without' , async function ( ) {
1113
+ const schema = new Schema ( {
1114
+ name : String
1115
+ } ) ;
1116
+ model = connection . model ( 'Schema' , schema ) ;
1117
+ assert . throws ( ( ) => model . discriminator ( 'Test' , new Schema ( {
1118
+ name : {
1119
+ type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1120
+ } , {
1121
+ encryptionType : 'queryableEncryption'
1122
+ } ) ) ,
1123
+ / e n c r y p t e d f i e l d s c a n n o t h a v e t h e s a m e p a t h a s a n o n - e n c r y p t e d f i e l d f o r d i s c r i m i n a t o r s . p a t h = n a m e /
1124
+ ) ;
1125
+ } ) ;
1093
1126
} ) ;
1094
1127
} ) ;
1095
1128
1096
- describe ( 'Nested Schema overrides nested path ' , function ( ) {
1129
+ describe ( 'Nested paths in discriminators with conflicting definitions for the same key ' , function ( ) {
1097
1130
beforeEach ( async function ( ) {
1098
1131
connection = createConnection ( ) ;
1099
1132
} ) ;
1100
1133
1101
- it ( 'nested objects throw an error' , async function ( ) {
1102
- model = connection . model ( 'Schema' , new Schema ( {
1103
- name : {
1104
- first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1105
- }
1106
- } , { encryptionType : 'csfle' } ) ) ;
1134
+ describe ( 'same definition on parent and child' , function ( ) {
1135
+ it ( 'throws an error' , function ( ) {
1136
+ model = connection . model ( 'Schema' , new Schema ( {
1137
+ name : {
1138
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1139
+ }
1140
+ } , { encryptionType : 'csfle' } ) ) ;
1107
1141
1108
- assert . throws ( ( ) => {
1109
- model . discriminator ( 'Test' , new Schema ( {
1110
- name : { first : Number } // Different type, no encryption, stored as same field in MDB
1111
- } ) ) ;
1142
+ assert . throws ( ( ) => {
1143
+ model . discriminator ( 'Test' , new Schema ( {
1144
+ name : { first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } } } // Different type, no encryption, stored as same field in MDB
1145
+ } , { encryptionType : 'csfle' } ) ) ;
1146
+ } , / e n c r y p t e d f i e l d s c a n n o t b e d e c l a r e d o n b o t h t h e b a s e s c h e m a a n d t h e c h i l d s c h e m a i n a d i s c r i m i n a t o r . p a t h / ) ;
1112
1147
} ) ;
1113
1148
} ) ;
1114
1149
1115
- it ( 'nested schemas throw an error' , async function ( ) {
1116
- model = connection . model ( 'Schema' , new Schema ( {
1117
- name : {
1118
- first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1119
- }
1120
- } , { encryptionType : 'csfle' } ) ) ;
1150
+ describe ( 'child overrides parent\'s encryption' , function ( ) {
1151
+ it ( 'throws an error' , function ( ) {
1152
+ model = connection . model ( 'Schema' , new Schema ( {
1153
+ name : {
1154
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1155
+ }
1156
+ } , { encryptionType : 'csfle' } ) ) ;
1121
1157
1122
- assert . throws ( ( ) => {
1123
- model . discriminator ( 'Test' , new Schema ( {
1124
- name : new Schema ( { first : Number } ) // Different type, no encryption, stored as same field in MDB
1125
- } ) ) ;
1158
+ assert . throws ( ( ) => {
1159
+ model . discriminator ( 'Test' , new Schema ( {
1160
+ name : { first : Number } // Different type, no encryption, stored as same field in MDB
1161
+ } ) ) ;
1162
+ } , / e n c r y p t e d f i e l d s c a n n o t h a v e t h e s a m e p a t h a s a n o n - e n c r y p t e d f i e l d f o r d i s c r i m i n a t o r s . p a t h = n a m e / ) ;
1163
+ } ) ;
1164
+ } ) ;
1165
+ } ) ;
1166
+
1167
+ describe ( 'Nested schemas in discriminators with conflicting definitions for the same key' , function ( ) {
1168
+ beforeEach ( async function ( ) {
1169
+ connection = createConnection ( ) ;
1170
+ } ) ;
1171
+
1172
+ describe ( 'same definition on parent and child' , function ( ) {
1173
+ it ( 'throws an error' , function ( ) {
1174
+ model = connection . model ( 'Schema' , new Schema ( {
1175
+ name : new Schema ( {
1176
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1177
+ } , { encryptionType : 'csfle' } )
1178
+ } , { encryptionType : 'csfle' } ) ) ;
1179
+
1180
+ assert . throws ( ( ) => {
1181
+ model . discriminator ( 'Test' , new Schema ( {
1182
+ name : new Schema ( {
1183
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1184
+ } , { encryptionType : 'csfle' } ) // Different type, no encryption, stored as same field in MDB
1185
+ } , { encryptionType : 'csfle' } ) ) ;
1186
+ } , / e n c r y p t e d f i e l d s c a n n o t b e d e c l a r e d o n b o t h t h e b a s e s c h e m a a n d t h e c h i l d s c h e m a i n a d i s c r i m i n a t o r . p a t h / ) ;
1187
+ } ) ;
1188
+ } ) ;
1189
+
1190
+ describe ( 'child overrides parent\'s encryption' , function ( ) {
1191
+ it ( 'throws an error' , function ( ) {
1192
+ model = connection . model ( 'Schema' , new Schema ( {
1193
+ name : new Schema ( {
1194
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1195
+ } , { encryptionType : 'csfle' } )
1196
+ } , { encryptionType : 'csfle' } ) ) ;
1197
+
1198
+ assert . throws ( ( ) => {
1199
+ model . discriminator ( 'Test' , new Schema ( {
1200
+ name : new Schema ( {
1201
+ first : Number
1202
+ } )
1203
+ } ) ) ;
1204
+ } , / e n c r y p t e d f i e l d s c a n n o t h a v e t h e s a m e p a t h a s a n o n - e n c r y p t e d f i e l d f o r d i s c r i m i n a t o r s . p a t h = n a m e .f i r s t / ) ;
1205
+ } ) ;
1206
+ } ) ;
1207
+
1208
+ describe ( 'multiple levels of nesting' , function ( ) {
1209
+ it ( 'throws an error' , function ( ) {
1210
+ model = connection . model ( 'Schema' , new Schema ( {
1211
+ name : new Schema ( {
1212
+ first : new Schema ( {
1213
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1214
+ } , { encryptionType : 'csfle' } )
1215
+ } , { encryptionType : 'csfle' } )
1216
+ } , { encryptionType : 'csfle' } ) ) ;
1217
+
1218
+ assert . throws ( ( ) => {
1219
+ model . discriminator ( 'Test' , new Schema ( {
1220
+ name : new Schema ( {
1221
+ first : { type : String , encrypt : { keyId : [ keyId ] , algorithm } }
1222
+ } , { encryptionType : 'csfle' } ) // Different type, no encryption, stored as same field in MDB
1223
+ } , { encryptionType : 'csfle' } ) ) ;
1224
+ } , / e n c r y p t e d f i e l d s c a n n o t h a v e t h e s a m e p a t h a s a n o n - e n c r y p t e d f i e l d f o r d i s c r i m i n a t o r s . p a t h = n a m e .f i r s t / ) ;
1126
1225
} ) ;
1127
1226
} ) ;
1128
1227
} ) ;
0 commit comments