@@ -63,30 +63,59 @@ describe('MongoCryptConstructor', () => {
63
63
expect ( MongoCrypt ) . to . have . property ( 'libmongocryptVersion' ) . that . is . a . string ;
64
64
} ) ;
65
65
66
- it ( 'throws if kmsProviders are not a buffer' , ( ) => {
67
- expect ( ( ) => new MongoCrypt ( { kmsProviders : 3 } ) ) . to . throw (
68
- / P a r a m e t e r ` o p t i o n s .k m s P r o v i d e r s ` m u s t b e a U i n t 8 A r r a y ./
69
- ) ;
66
+ describe ( 'options.kmsProviders' , ( ) => {
67
+ it ( 'throws if provided and are not a Uint8Array' , ( ) => {
68
+ expect ( ( ) => new MongoCrypt ( { kmsProviders : 3 } ) ) . to . throw (
69
+ / P a r a m e t e r ` o p t i o n s .k m s P r o v i d e r s ` m u s t b e a U i n t 8 A r r a y ./
70
+ ) ;
71
+ } ) ;
72
+
73
+ it ( 'throws when explicitly set to undefined' , ( ) => {
74
+ // the error is different because it is thrown from libmongocrypt
75
+ expect ( ( ) => new MongoCrypt ( { kmsProviders : undefined } ) ) . to . throw ( / n o k m s p r o v i d e r s e t / ) ;
76
+ } ) ;
70
77
} ) ;
71
78
72
- it ( 'throws when `schemaMap` is not a buffer' , ( ) => {
73
- expect (
74
- ( ) =>
79
+ describe ( 'options.schemaMap' , ( ) => {
80
+ it ( 'throws when provided and not a Uint8Array' , ( ) => {
81
+ expect (
82
+ ( ) =>
83
+ new MongoCrypt ( {
84
+ kmsProviders : serialize ( { aws : { } } ) ,
85
+ schemaMap : 3
86
+ } )
87
+ ) . to . throw ( / P a r a m e t e r ` o p t i o n s .s c h e m a M a p ` m u s t b e a U i n t 8 A r r a y ./ ) ;
88
+ } ) ;
89
+
90
+ it ( 'can be explicitly set to `undefined`' , ( ) => {
91
+ expect (
75
92
new MongoCrypt ( {
76
93
kmsProviders : serialize ( { aws : { } } ) ,
77
- schemaMap : 3
94
+ schemaMap : undefined
78
95
} )
79
- ) . to . throw ( / P a r a m e t e r ` o p t i o n s .s c h e m a M a p ` m u s t b e a U i n t 8 A r r a y ./ ) ;
96
+ ) . to . be . instanceOf ( MongoCrypt ) ;
97
+ } ) ;
80
98
} ) ;
81
99
82
- it ( 'throws when `encryptedFieldsMap` is not a buffer' , ( ) => {
83
- expect (
84
- ( ) =>
100
+ describe ( 'options.encryptedFieldsMap' , ( ) => {
101
+ it ( 'throws when provided and not a Uint8Array' , ( ) => {
102
+ expect (
103
+ ( ) =>
104
+ new MongoCrypt ( {
105
+ kmsProviders : serialize ( { aws : { } } ) ,
106
+ encryptedFieldsMap : 3
107
+ } )
108
+ ) . to . throw ( / P a r a m e t e r ` o p t i o n s .e n c r y p t e d F i e l d s M a p ` m u s t b e a U i n t 8 A r r a y ./ ) ;
109
+ } ) ;
110
+
111
+ it ( 'can be explicitly set to `undefined`' , ( ) => {
112
+ expect (
85
113
new MongoCrypt ( {
86
114
kmsProviders : serialize ( { aws : { } } ) ,
87
- encryptedFieldsMap : 3
115
+ encryptedFieldsMap : undefined
88
116
} )
89
- ) . to . throw ( / P a r a m e t e r ` o p t i o n s .e n c r y p t e d F i e l d s M a p ` m u s t b e a U i n t 8 A r r a y ./ ) ;
117
+ ) . to . be . instanceOf ( MongoCrypt ) ;
118
+ } ) ;
90
119
} ) ;
91
120
92
121
it ( 'throws when cryptSharedLibSearchPaths is not an array' , ( ) => {
@@ -106,7 +135,7 @@ describe('MongoCryptConstructor', () => {
106
135
} ) ;
107
136
108
137
describe ( '.makeEncryptionContext()' , ( ) => {
109
- it ( 'throws if `command` is not a buffer ' , ( ) => {
138
+ it ( 'throws if `command` is not a Uint8Array ' , ( ) => {
110
139
expect ( ( ) => mc . makeEncryptionContext ( 'foo.bar' , 'some non-buffer' ) ) . to . throw (
111
140
/ P a r a m e t e r ` c o m m a n d ` m u s t b e a U i n t 8 A r r a y ./
112
141
) ;
@@ -120,7 +149,7 @@ describe('MongoCryptConstructor', () => {
120
149
} ) ;
121
150
122
151
describe ( '.makeDecryptionContext()' , ( ) => {
123
- it ( 'throws if not provided a buffer ' , ( ) => {
152
+ it ( 'throws if not provided a Uint8Array ' , ( ) => {
124
153
expect ( ( ) => mc . makeDecryptionContext ( 'foo.bar' ) ) . to . throw (
125
154
/ P a r a m e t e r ` v a l u e ` m u s t b e a U i n t 8 A r r a y ./
126
155
) ;
@@ -134,7 +163,7 @@ describe('MongoCryptConstructor', () => {
134
163
} ) ;
135
164
136
165
describe ( '.makeExplicitDecryptionContext()' , ( ) => {
137
- it ( 'throws if not provided a buffer ' , ( ) => {
166
+ it ( 'throws if not provided a Uint8Array ' , ( ) => {
138
167
expect ( ( ) => mc . makeExplicitDecryptionContext ( 'foo.bar' ) ) . to . throw (
139
168
/ P a r a m e t e r ` v a l u e ` m u s t b e a U i n t 8 A r r a y ./
140
169
) ;
@@ -154,65 +183,75 @@ describe('MongoCryptConstructor', () => {
154
183
) ;
155
184
} ) ;
156
185
157
- it ( 'throws when the filter is not a buffer' , ( ) => {
158
- expect ( ( ) => mc . makeRewrapManyDataKeyContext ( 'foo.bar' ) ) . to . throw (
159
- / P a r a m e t e r ` f i l t e r ` m u s t b e a U i n t 8 A r r a y ./
160
- ) ;
186
+ describe ( 'when a filter buffer is provided' , ( ) => {
187
+ it ( 'throws when the filter is not a Uint8Array' , ( ) => {
188
+ expect ( ( ) => mc . makeRewrapManyDataKeyContext ( 'foo.bar' ) ) . to . throw (
189
+ / P a r a m e t e r ` f i l t e r ` m u s t b e a U i n t 8 A r r a y ./
190
+ ) ;
191
+ } ) ;
192
+
193
+ it ( 'can be explicitly passed `undefined`' , ( ) => {
194
+ expect ( mc . makeRewrapManyDataKeyContext ( serialize ( { } ) , undefined ) ) . to . be . instanceOf (
195
+ MongoCryptContextCtor
196
+ ) ;
197
+ } ) ;
161
198
} ) ;
162
199
} ) ;
163
200
164
201
describe ( '.makeDataKeyContext()' , ( ) => {
202
+ const providers = serialize ( {
203
+ provider : 'aws' ,
204
+ region : 'region' ,
205
+ key : 'key'
206
+ } ) ;
165
207
it ( 'returns a MongoCryptContext' , ( ) => {
166
- expect (
167
- mc . makeDataKeyContext (
168
- serialize ( {
169
- provider : 'aws' ,
170
- region : 'region' ,
171
- key : 'key'
172
- } ) ,
173
- { }
174
- )
175
- ) . to . be . instanceOf ( MongoCryptContextCtor ) ;
208
+ expect ( mc . makeDataKeyContext ( providers , { } ) ) . to . be . instanceOf ( MongoCryptContextCtor ) ;
176
209
} ) ;
177
210
178
- it ( 'throws when the first parameter is not a buffer ' , ( ) => {
211
+ it ( 'throws when the first parameter is not a Uint8Array ' , ( ) => {
179
212
expect ( ( ) => mc . makeDataKeyContext ( 'foo.bar' , { } ) ) . to . throw (
180
213
/ P a r a m e t e r ` o p t i o n s ` m u s t b e a U i n t 8 A r r a y ./
181
214
) ;
182
215
} ) ;
183
216
184
- it ( 'throws a TypeError when options.keyAltNames includes values that are not buffers' , ( ) => {
185
- expect ( ( ) =>
186
- mc . makeDataKeyContext (
187
- serialize ( {
188
- provider : 'aws' ,
189
- region : 'region' ,
190
- key : 'key'
191
- } ) ,
192
- {
217
+ describe ( 'options.keyAltNames' , ( ) => {
218
+ it ( 'can be explicitly set to `undefined`' , ( ) => {
219
+ expect (
220
+ mc . makeDataKeyContext ( providers , {
221
+ keyAltNames : undefined
222
+ } )
223
+ ) . to . be . instanceOf ( MongoCryptContextCtor ) ;
224
+ } ) ;
225
+
226
+ it ( 'throws a TypeError when options.keyAltNames includes values that are not Uint8Arrays' , ( ) => {
227
+ expect ( ( ) =>
228
+ mc . makeDataKeyContext ( providers , {
193
229
keyAltNames : [ 1 ]
194
- }
230
+ } )
195
231
)
196
- )
197
- . to . throw ( / P a r a m e t e r ` o p t i o n s . k e y A l t N a m e \[ \] ` m u s t b e a U i n t 8 A r r a y . / )
198
- . to . be . instanceOf ( TypeError ) ;
232
+ . to . throw ( / P a r a m e t e r ` o p t i o n s . k e y A l t N a m e \[ \] ` m u s t b e a U i n t 8 A r r a y . / )
233
+ . to . be . instanceOf ( TypeError ) ;
234
+ } ) ;
199
235
} ) ;
200
236
201
- it ( 'throws a TypeError when options.keyMaterial is not a buffer' , ( ) => {
202
- expect ( ( ) =>
203
- mc . makeDataKeyContext (
204
- serialize ( {
205
- provider : 'aws' ,
206
- region : 'region' ,
207
- key : 'key'
208
- } ) ,
209
- {
237
+ describe ( 'options.keyMaterial' , ( ) => {
238
+ it ( 'can be explicitly set to `undefined`' , ( ) => {
239
+ expect (
240
+ mc . makeDataKeyContext ( providers , {
241
+ keyMaterial : undefined
242
+ } )
243
+ ) . to . be . instanceOf ( MongoCryptContextCtor ) ;
244
+ } ) ;
245
+
246
+ it ( 'throws a TypeError when provided and is not a Uint8Array' , ( ) => {
247
+ expect ( ( ) =>
248
+ mc . makeDataKeyContext ( providers , {
210
249
keyMaterial : 'foo bar baz'
211
- }
250
+ } )
212
251
)
213
- )
214
- . to . throw ( / P a r a m e t e r ` o p t i o n s . k e y M a t e r i a l ` m u s t b e a U i n t 8 A r r a y . / )
215
- . to . be . instanceOf ( TypeError ) ;
252
+ . to . throw ( / P a r a m e t e r ` o p t i o n s . k e y M a t e r i a l ` m u s t b e a U i n t 8 A r r a y . / )
253
+ . to . be . instanceOf ( TypeError ) ;
254
+ } ) ;
216
255
} ) ;
217
256
} ) ;
218
257
@@ -243,30 +282,63 @@ describe('MongoCryptConstructor', () => {
243
282
. to . throw ( / P a r a m e t e r ` v a l u e ` m u s t b e a U i n t 8 A r r a y ./ )
244
283
. to . be . instanceOf ( TypeError ) ;
245
284
} ) ;
246
- it ( 'throws a TypeError when `options.keyId` is not a Buffer' , ( ) => {
247
- expect ( ( ) =>
248
- mc . makeExplicitEncryptionContext ( value , {
249
- // minimum required arguments from libmongocrypt
250
- keyId : 'asdf' ,
251
- expressionMode : false ,
252
- algorithm : 'Unindexed'
253
- } )
254
- )
255
- . to . throw ( / P a r a m e t e r ` k e y I d ` m u s t b e a U i n t 8 A r r a y ./ )
256
- . to . be . instanceOf ( TypeError ) ;
285
+
286
+ describe ( 'options.keyId' , ( ) => {
287
+ it ( 'throws a TypeError when provided and is not a Uint8Array' , ( ) => {
288
+ expect ( ( ) =>
289
+ mc . makeExplicitEncryptionContext ( value , {
290
+ // minimum required arguments from libmongocrypt
291
+ keyId : 'asdf' ,
292
+ expressionMode : false ,
293
+ algorithm : 'Unindexed'
294
+ } )
295
+ )
296
+ . to . throw ( / P a r a m e t e r ` k e y I d ` m u s t b e a U i n t 8 A r r a y ./ )
297
+ . to . be . instanceOf ( TypeError ) ;
298
+ } ) ;
299
+
300
+ it ( 'throws a TypeError when explicitly set to `undefined`' , ( ) => {
301
+ expect ( ( ) =>
302
+ mc . makeExplicitEncryptionContext ( value , {
303
+ // minimum required arguments from libmongocrypt
304
+ keyId : undefined ,
305
+ expressionMode : false ,
306
+ algorithm : 'Unindexed'
307
+ } )
308
+ )
309
+ // error thrown from `libmongocrypt`
310
+ . to . throw ( / e i t h e r k e y i d o r k e y a l t n a m e r e q u i r e d / )
311
+ . to . be . instanceOf ( TypeError ) ;
312
+ } ) ;
257
313
} ) ;
258
314
259
- it ( 'throws a TypeError when `options.keyAltName` is not a Buffer' , ( ) => {
260
- expect ( ( ) =>
261
- mc . makeExplicitEncryptionContext ( value , {
262
- // minimum required arguments from libmongocrypt
263
- keyAltName : 'asdf' ,
264
- expressionMode : false ,
265
- algorithm : 'Unindexed'
266
- } )
267
- )
268
- . to . throw ( / P a r a m e t e r ` k e y A l t N a m e ` m u s t b e a U i n t 8 A r r a y ./ )
269
- . to . be . instanceOf ( TypeError ) ;
315
+ describe ( 'options.keyAltName' , ( ) => {
316
+ it ( 'throws a TypeError provided and is not a Uint8Array' , ( ) => {
317
+ expect ( ( ) =>
318
+ mc . makeExplicitEncryptionContext ( value , {
319
+ // minimum required arguments from libmongocrypt
320
+ keyAltName : 'asdf' ,
321
+ expressionMode : false ,
322
+ algorithm : 'Unindexed'
323
+ } )
324
+ )
325
+ . to . throw ( / P a r a m e t e r ` k e y A l t N a m e ` m u s t b e a U i n t 8 A r r a y ./ )
326
+ . to . be . instanceOf ( TypeError ) ;
327
+ } ) ;
328
+
329
+ it ( 'throws a TypeError when explicitly set to `undefined`' , ( ) => {
330
+ expect ( ( ) =>
331
+ mc . makeExplicitEncryptionContext ( value , {
332
+ // minimum required arguments from libmongocrypt
333
+ keyAltName : undefined ,
334
+ expressionMode : false ,
335
+ algorithm : 'Unindexed'
336
+ } )
337
+ )
338
+ // error thrown from `libmongocrypt`
339
+ . to . throw ( / e i t h e r k e y i d o r k e y a l t n a m e r e q u i r e d / )
340
+ . to . be . instanceOf ( TypeError ) ;
341
+ } ) ;
270
342
} ) ;
271
343
272
344
context ( 'when algorithm is `rangePreview' , ( ) => {
@@ -283,7 +355,7 @@ describe('MongoCryptConstructor', () => {
283
355
. to . be . instanceOf ( TypeError ) ;
284
356
} ) ;
285
357
286
- it ( 'throws a TypeError if `rangeOptions` is not a Buffer ' , ( ) => {
358
+ it ( 'throws a TypeError if `rangeOptions` is not a Uint8Array ' , ( ) => {
287
359
expect ( ( ) =>
288
360
mc . makeExplicitEncryptionContext ( value , {
289
361
// minimum required arguments from libmongocrypt
0 commit comments