1
- 'use strict' ;
2
- const BSON = require ( 'bson' ) ;
3
- const { expect } = require ( 'chai' ) ;
4
- const fs = require ( 'fs' ) ;
5
- const path = require ( 'path' ) ;
6
-
7
- const { dropCollection, APMEventCollector } = require ( '../shared' ) ;
8
-
9
- const { EJSON } = BSON ;
10
- const { LEGACY_HELLO_COMMAND , MongoCryptError, MongoRuntimeError } = require ( '../../mongodb' ) ;
11
- const { MongoServerError, MongoServerSelectionError, MongoClient } = require ( '../../mongodb' ) ;
12
- const { getEncryptExtraOptions } = require ( '../../tools/utils' ) ;
13
-
14
- const {
15
- externalSchema
16
- } = require ( '../../spec/client-side-encryption/external/external-schema.json' ) ;
17
- /* eslint-disable no-restricted-modules */
18
- const { ClientEncryption } = require ( '../../../src/client-side-encryption/client_encryption' ) ;
19
- const { getCSFLEKMSProviders } = require ( '../../csfle-kms-providers' ) ;
20
- const { AlpineTestConfiguration } = require ( '../../tools/runner/config' ) ;
21
-
22
- const getKmsProviders = ( localKey , kmipEndpoint , azureEndpoint , gcpEndpoint ) => {
1
+ import { BSON , EJSON } from 'bson' ;
2
+ import { expect } from 'chai' ;
3
+ import * as fs from 'fs/promises' ;
4
+ import * as path from 'path' ;
5
+
6
+ // eslint-disable-next-line @typescript-eslint/no-restricted-imports
7
+ import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption' ;
8
+ import { getCSFLEKMSProviders } from '../../csfle-kms-providers' ;
9
+ import {
10
+ LEGACY_HELLO_COMMAND ,
11
+ MongoClient ,
12
+ MongoCryptError ,
13
+ MongoRuntimeError ,
14
+ MongoServerError ,
15
+ MongoServerSelectionError
16
+ } from '../../mongodb' ;
17
+ import { AlpineTestConfiguration } from '../../tools/runner/config' ;
18
+ import { getEncryptExtraOptions } from '../../tools/utils' ;
19
+ import { APMEventCollector , dropCollection } from '../shared' ;
20
+
21
+ export const getKmsProviders = ( localKey , kmipEndpoint , azureEndpoint , gcpEndpoint ) => {
23
22
const result = getCSFLEKMSProviders ( ) ;
24
23
if ( localKey ) {
25
24
result . local = { key : localKey } ;
@@ -39,6 +38,7 @@ const getKmsProviders = (localKey, kmipEndpoint, azureEndpoint, gcpEndpoint) =>
39
38
return result ;
40
39
} ;
41
40
41
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
42
42
const noop = ( ) => { } ;
43
43
/** @type { MongoDBMetadataUI } */
44
44
const metadata = {
@@ -56,6 +56,24 @@ const eeMetadata = {
56
56
}
57
57
} ;
58
58
59
+ async function loadExternal ( file ) {
60
+ return EJSON . parse (
61
+ await fs . readFile (
62
+ path . resolve ( __dirname , '../../spec/client-side-encryption/external' , file ) ,
63
+ 'utf8'
64
+ )
65
+ ) ;
66
+ }
67
+
68
+ async function loadLimits ( file ) {
69
+ return EJSON . parse (
70
+ await fs . readFile (
71
+ path . resolve ( __dirname , '../../spec/client-side-encryption/limits' , file ) ,
72
+ 'utf8'
73
+ )
74
+ ) ;
75
+ }
76
+
59
77
// Tests for the ClientEncryption type are not included as part of the YAML tests.
60
78
61
79
// In the prose tests LOCAL_MASTERKEY refers to the following base64:
@@ -64,6 +82,9 @@ const eeMetadata = {
64
82
65
83
// Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk
66
84
describe ( 'Client Side Encryption Prose Tests' , metadata , function ( ) {
85
+ let externalKey ;
86
+ let externalSchema ;
87
+
67
88
const dataDbName = 'db' ;
68
89
const dataCollName = 'coll' ;
69
90
const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
@@ -76,6 +97,11 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
76
97
'base64'
77
98
) ;
78
99
100
+ before ( async function ( ) {
101
+ externalKey = await loadExternal ( 'external-key.json' ) ;
102
+ externalSchema = await loadExternal ( 'external-schema.json' ) ;
103
+ } ) ;
104
+
79
105
describe ( 'Data key and double encryption' , function ( ) {
80
106
// Data key and double encryption
81
107
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -351,18 +377,8 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
351
377
// and confirming that the externalClient is firing off keyVault requests during
352
378
// encrypted operations
353
379
describe ( 'External Key Vault Test' , function ( ) {
354
- function loadExternal ( file ) {
355
- return EJSON . parse (
356
- fs . readFileSync ( path . resolve ( __dirname , '../../spec/client-side-encryption/external' , file ) )
357
- ) ;
358
- }
359
-
360
- const externalKey = loadExternal ( 'external-key.json' ) ;
361
- const externalSchema = loadExternal ( 'external-schema.json' ) ;
362
-
363
- beforeEach ( function ( ) {
380
+ beforeEach ( async function ( ) {
364
381
this . client = this . configuration . newClient ( ) ;
365
-
366
382
// 1. Create a MongoClient without encryption enabled (referred to as ``client``).
367
383
return (
368
384
this . client
@@ -552,15 +568,15 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
552
568
} ) ;
553
569
554
570
describe ( 'BSON size limits and batch splitting' , function ( ) {
555
- function loadLimits ( file ) {
556
- return EJSON . parse (
557
- fs . readFileSync ( path . resolve ( __dirname , '../../spec/client-side-encryption/limits' , file ) )
558
- ) ;
559
- }
560
-
561
- const limitsSchema = loadLimits ( 'limits-schema .json' ) ;
562
- const limitsKey = loadLimits ( 'limits-key .json' ) ;
563
- const limitsDoc = loadLimits ( 'limits-doc.json' ) ;
571
+ let limitsSchema ;
572
+ let limitsKey ;
573
+ let limitsDoc ;
574
+
575
+ before ( async function ( ) {
576
+ limitsSchema = await loadLimits ( 'limits-schema.json' ) ;
577
+ limitsKey = await loadLimits ( 'limits-key .json' ) ;
578
+ limitsDoc = await loadLimits ( 'limits-doc .json' ) ;
579
+ } ) ;
564
580
565
581
let hasRunFirstTimeSetup = false ;
566
582
@@ -827,9 +843,9 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
827
843
828
844
describe ( 'Corpus Test' , function ( ) {
829
845
it ( 'runs in a separate suite' , ( ) => {
830
- expect ( ( ) =>
831
- fs . statSync ( path . resolve ( __dirname , './client_side_encryption.prose.06.corpus.test.ts' ) )
832
- ) . not . to . throw ( ) ;
846
+ expect ( async ( ) => {
847
+ await fs . stat ( path . resolve ( __dirname , './client_side_encryption.prose.06.corpus.test.ts' ) ) ;
848
+ } ) . not . to . throw ( ) ;
833
849
} ) ;
834
850
} ) ;
835
851
@@ -1687,6 +1703,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1687
1703
context (
1688
1704
'Case 5: `tlsDisableOCSPEndpointCheck` is permitted' ,
1689
1705
metadata ,
1706
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1690
1707
function ( ) { }
1691
1708
) . skipReason = 'TODO(NODE-4840): Node does not support any OCSP options' ;
1692
1709
@@ -1907,12 +1924,12 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1907
1924
beforeEach ( async function ( ) {
1908
1925
// Load the file encryptedFields.json as encryptedFields.
1909
1926
encryptedFields = EJSON . parse (
1910
- await fs . promises . readFile ( path . join ( data , 'encryptedFields.json' ) ) ,
1927
+ await fs . readFile ( path . join ( data , 'encryptedFields.json' ) , 'utf8' ) ,
1911
1928
{ relaxed : false }
1912
1929
) ;
1913
1930
// Load the file key1-document.json as key1Document.
1914
1931
key1Document = EJSON . parse (
1915
- await fs . promises . readFile ( path . join ( data , 'keys' , 'key1-document.json' ) ) ,
1932
+ await fs . readFile ( path . join ( data , 'keys' , 'key1-document.json' ) , 'utf8' ) ,
1916
1933
{ relaxed : false }
1917
1934
) ;
1918
1935
// Read the "_id" field of key1Document as key1ID.
@@ -2308,15 +2325,13 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
2308
2325
kmip : { } ,
2309
2326
local : undefined
2310
2327
} ;
2311
- /** @type {import('../../mongodb').MongoClient } */
2312
2328
let client1 ;
2313
- /** @type {import('../../mongodb').MongoClient } */
2314
2329
let client2 ;
2315
2330
2316
2331
describe ( 'Case 1: Rewrap with separate ClientEncryption' , function ( ) {
2317
2332
/**
2318
- * Run the following test case for each pair of KMS providers (referred to as `` srcProvider`` and `` dstProvider` `).
2319
- * Include pairs where `` srcProvider`` equals `` dstProvider` `.
2333
+ * Run the following test case for each pair of KMS providers (referred to as `srcProvider` and `dstProvider`).
2334
+ * Include pairs where `srcProvider` equals `dstProvider`.
2320
2335
*/
2321
2336
function * generateTestCombinations ( ) {
2322
2337
const providers = Object . keys ( masterKeys ) ;
0 commit comments