@@ -162,22 +162,6 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
162
162
) ;
163
163
} ) ;
164
164
165
- beforeEach ( async function ( ) {
166
- await clientNoTls . connect ( ) ;
167
- await clientWithTls . connect ( ) ;
168
- await clientWithTlsExpired . connect ( ) ;
169
- await clientWithInvalidHostname . connect ( ) ;
170
- await dropCollection ( clientNoTls . db ( keyVaultDbName ) , keyVaultCollName ) ;
171
- await dropCollection ( clientNoTls . db ( keyVaultDbName ) , keyVaultCollName ) ;
172
- } ) ;
173
-
174
- afterEach ( async function ( ) {
175
- await clientNoTls . close ( ) ;
176
- await clientWithTls . close ( ) ;
177
- await clientWithTlsExpired . close ( ) ;
178
- await clientWithInvalidHostname . close ( ) ;
179
- } ) ;
180
-
181
165
// Case 1.
182
166
context ( 'Case 1: AWS' , metadata , function ( ) {
183
167
const masterKey = {
@@ -188,40 +172,39 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
188
172
const masterKeyExpired = { ...masterKey , endpoint : '127.0.0.1:8000' } ;
189
173
const masterKeyInvalidHostname = { ...masterKey , endpoint : '127.0.0.1:8001' } ;
190
174
191
- it ( 'fails with no tls' , metadata , async function ( ) {
175
+ it ( 'fails with various invalid tls options ' , metadata , async function ( ) {
192
176
try {
177
+ await clientNoTls . connect ( ) ;
193
178
await clientEncryptionNoTls . createDataKey ( 'aws' , { masterKey } ) ;
194
179
expect . fail ( 'it must fail with no tls' ) ;
195
180
} catch ( e ) {
196
181
expect ( e . originalError . message ) . to . include ( 'certificate required' ) ;
182
+ await clientNoTls . close ( ) ;
197
183
}
198
- } ) ;
199
-
200
- it ( 'passes with tls but fails to parse' , metadata , async function ( ) {
201
184
try {
185
+ await clientWithTls . connect ( ) ;
202
186
await clientEncryptionWithTls . createDataKey ( 'aws' , { masterKey } ) ;
203
187
expect . fail ( 'it must fail to parse response' ) ;
204
188
} catch ( e ) {
189
+ await clientWithTls . close ( ) ;
205
190
expect ( e . message ) . to . include ( 'parse error' ) ;
206
191
}
207
- } ) ;
208
-
209
- it ( 'fails with expired certificates' , metadata , async function ( ) {
210
192
try {
193
+ await clientWithTlsExpired . connect ( ) ;
211
194
await clientEncryptionWithTlsExpired . createDataKey ( 'aws' , { masterKeyExpired } ) ;
212
195
expect . fail ( 'it must fail with invalid certificate' ) ;
213
196
} catch ( e ) {
197
+ await clientWithTlsExpired . close ( ) ;
214
198
expect ( e . message ) . to . include ( 'expected UTF-8 key' ) ;
215
199
}
216
- } ) ;
217
-
218
- it ( 'fails with invalid hostnames' , metadata , async function ( ) {
219
200
try {
201
+ await clientWithInvalidHostname . connect ( ) ;
220
202
await clientEncryptionWithInvalidHostname . createDataKey ( 'aws' , {
221
203
masterKeyInvalidHostname
222
204
} ) ;
223
205
expect . fail ( 'it must fail with invalid hostnames' ) ;
224
206
} catch ( e ) {
207
+ await clientWithInvalidHostname . close ( ) ;
225
208
expect ( e . message ) . to . include ( 'expected UTF-8 key' ) ;
226
209
}
227
210
} ) ;
@@ -234,38 +217,37 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
234
217
keyName : 'foo'
235
218
} ;
236
219
237
- it ( 'fails with no tls' , metadata , async function ( ) {
220
+ it ( 'fails with various invalid tls options ' , metadata , async function ( ) {
238
221
try {
222
+ await clientNoTls . connect ( ) ;
239
223
await clientEncryptionNoTls . createDataKey ( 'azure' , { masterKey } ) ;
240
224
expect . fail ( 'it must fail with no tls' ) ;
241
225
} catch ( e ) {
226
+ await clientNoTls . close ( ) ;
242
227
expect ( e . originalError . message ) . to . include ( 'certificate required' ) ;
243
228
}
244
- } ) ;
245
-
246
- it ( 'fails with invalid host' , metadata , async function ( ) {
247
229
try {
230
+ await clientWithTls . connect ( ) ;
248
231
await clientEncryptionWithTls . createDataKey ( 'azure' , { masterKey } ) ;
249
232
expect . fail ( 'it must fail with invalid host' ) ;
250
233
} catch ( e ) {
234
+ await clientWithTls . close ( ) ;
251
235
expect ( e . message ) . to . include ( 'HTTP status=404' ) ;
252
236
}
253
- } ) ;
254
-
255
- it ( 'fails with expired certificates' , metadata , async function ( ) {
256
237
try {
238
+ await clientWithTlsExpired . connect ( ) ;
257
239
await clientEncryptionWithTlsExpired . createDataKey ( 'azure' , { masterKey } ) ;
258
240
expect . fail ( 'it must fail with expired certificates' ) ;
259
241
} catch ( e ) {
242
+ await clientWithTlsExpired . close ( ) ;
260
243
expect ( e . originalError . message ) . to . include ( 'certificate has expired' ) ;
261
244
}
262
- } ) ;
263
-
264
- it ( 'fails with invalid hostnames' , metadata , async function ( ) {
265
245
try {
246
+ await clientWithInvalidHostname . connect ( ) ;
266
247
await clientEncryptionWithInvalidHostname . createDataKey ( 'azure' , { masterKey } ) ;
267
248
expect . fail ( 'it must fail with invalid hostnames' ) ;
268
249
} catch ( e ) {
250
+ await clientWithInvalidHostname . close ( ) ;
269
251
expect ( e . originalError . message ) . to . include ( 'does not match certificate' ) ;
270
252
}
271
253
} ) ;
@@ -280,70 +262,67 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
280
262
keyName : 'foo'
281
263
} ;
282
264
283
- it ( 'fails with no tls' , metadata , async function ( ) {
265
+ it ( 'fails with various invalid tls options ' , metadata , async function ( ) {
284
266
try {
267
+ await clientNoTls . connect ( ) ;
285
268
await clientEncryptionNoTls . createDataKey ( 'gcp' , { masterKey } ) ;
286
269
expect . fail ( 'it must fail with no tls' ) ;
287
270
} catch ( e ) {
271
+ await clientNoTls . close ( ) ;
288
272
expect ( e . originalError . message ) . to . include ( 'certificate required' ) ;
289
273
}
290
- } ) ;
291
-
292
- it ( 'fails with invalid host' , metadata , async function ( ) {
293
274
try {
275
+ await clientWithTls . connect ( ) ;
294
276
await clientEncryptionWithTls . createDataKey ( 'gcp' , { masterKey } ) ;
295
277
expect . fail ( 'it must fail with invalid host' ) ;
296
278
} catch ( e ) {
279
+ await clientWithTls . close ( ) ;
297
280
expect ( e . message ) . to . include ( 'HTTP status=404' ) ;
298
281
}
299
- } ) ;
300
-
301
- it ( 'fails with expired certificates' , metadata , async function ( ) {
302
282
try {
283
+ await clientWithTlsExpired . connect ( ) ;
303
284
await clientEncryptionWithTlsExpired . createDataKey ( 'gcp' , { masterKey } ) ;
304
285
expect . fail ( 'it must fail with expired certificates' ) ;
305
286
} catch ( e ) {
287
+ await clientWithTlsExpired . close ( ) ;
306
288
expect ( e . originalError . message ) . to . include ( 'certificate has expired' ) ;
307
289
}
308
- } ) ;
309
-
310
- it ( 'fails with invalid hostnames' , metadata , async function ( ) {
311
290
try {
291
+ await clientWithInvalidHostname . connect ( ) ;
312
292
await clientEncryptionWithInvalidHostname . createDataKey ( 'gcp' , { masterKey } ) ;
313
293
expect . fail ( 'it must fail with invalid hostnames' ) ;
314
294
} catch ( e ) {
295
+ await clientWithInvalidHostname . close ( ) ;
315
296
expect ( e . originalError . message ) . to . include ( 'does not match certificate' ) ;
316
297
}
317
298
} ) ;
318
299
} ) ;
319
300
320
- // Case 4. The success test is skipped as the client was closing from the after
321
- // block before the it block actually finished. But we have another test in the
322
- // KMIP section that tests the same thing and works.
301
+ // Case 4.
323
302
context ( 'Case 4: KMIP' , metadata , function ( ) {
324
- it ( 'fails with no tls' , metadata , async function ( ) {
303
+ it ( 'fails with various invalid tls options ' , metadata , async function ( ) {
325
304
try {
305
+ await clientNoTls . connect ( ) ;
326
306
await clientEncryptionNoTls . createDataKey ( 'kmip' ) ;
327
307
expect . fail ( 'it must fail with no tls' ) ;
328
308
} catch ( e ) {
309
+ await clientNoTls . close ( ) ;
329
310
expect ( e . originalError . message ) . to . include ( 'before secure TLS connection' ) ;
330
311
}
331
- } ) ;
332
-
333
- it ( 'fails with expired certificates' , metadata , async function ( ) {
334
312
try {
313
+ await clientWithTlsExpired . connect ( ) ;
335
314
await clientEncryptionWithTlsExpired . createDataKey ( 'kmip' ) ;
336
315
expect . fail ( 'it must fail with expired certificates' ) ;
337
316
} catch ( e ) {
317
+ await clientWithTlsExpired . close ( ) ;
338
318
expect ( e . originalError . message ) . to . include ( 'certificate has expired' ) ;
339
319
}
340
- } ) ;
341
-
342
- it ( 'fails with invalid hostnames' , metadata , async function ( ) {
343
320
try {
321
+ await clientWithInvalidHostname . connect ( ) ;
344
322
await clientEncryptionWithInvalidHostname . createDataKey ( 'kmip' ) ;
345
323
expect . fail ( 'it must fail with invalid hostnames' ) ;
346
324
} catch ( e ) {
325
+ await clientWithInvalidHostname . close ( ) ;
347
326
expect ( e . originalError . message ) . to . include ( 'does not match certificate' ) ;
348
327
}
349
328
} ) ;
0 commit comments