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 ) => {
2322 const result = getCSFLEKMSProviders ( ) ;
2423 if ( localKey ) {
2524 result . local = { key : localKey } ;
@@ -39,6 +38,7 @@ const getKmsProviders = (localKey, kmipEndpoint, azureEndpoint, gcpEndpoint) =>
3938 return result ;
4039} ;
4140
41+ // eslint-disable-next-line @typescript-eslint/no-empty-function
4242const noop = ( ) => { } ;
4343/** @type { MongoDBMetadataUI } */
4444const metadata = {
@@ -56,6 +56,24 @@ const eeMetadata = {
5656 }
5757} ;
5858
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+
5977// Tests for the ClientEncryption type are not included as part of the YAML tests.
6078
6179// In the prose tests LOCAL_MASTERKEY refers to the following base64:
@@ -64,6 +82,9 @@ const eeMetadata = {
6482
6583// Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk
6684describe ( 'Client Side Encryption Prose Tests' , metadata , function ( ) {
85+ let externalKey ;
86+ let externalSchema ;
87+
6788 const dataDbName = 'db' ;
6889 const dataCollName = 'coll' ;
6990 const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
@@ -76,6 +97,11 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
7697 'base64'
7798 ) ;
7899
100+ before ( async function ( ) {
101+ externalKey = await loadExternal ( 'external-key.json' ) ;
102+ externalSchema = await loadExternal ( 'external-schema.json' ) ;
103+ } ) ;
104+
79105 describe ( 'Data key and double encryption' , function ( ) {
80106 // Data key and double encryption
81107 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -351,18 +377,8 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
351377 // and confirming that the externalClient is firing off keyVault requests during
352378 // encrypted operations
353379 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 ( ) {
364381 this . client = this . configuration . newClient ( ) ;
365-
366382 // 1. Create a MongoClient without encryption enabled (referred to as ``client``).
367383 return (
368384 this . client
@@ -552,15 +568,15 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
552568 } ) ;
553569
554570 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+ } ) ;
564580
565581 let hasRunFirstTimeSetup = false ;
566582
@@ -827,9 +843,9 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
827843
828844 describe ( 'Corpus Test' , function ( ) {
829845 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 ( ) ;
833849 } ) ;
834850 } ) ;
835851
@@ -1687,6 +1703,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
16871703 context (
16881704 'Case 5: `tlsDisableOCSPEndpointCheck` is permitted' ,
16891705 metadata ,
1706+ // eslint-disable-next-line @typescript-eslint/no-empty-function
16901707 function ( ) { }
16911708 ) . skipReason = 'TODO(NODE-4840): Node does not support any OCSP options' ;
16921709
@@ -1907,12 +1924,12 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
19071924 beforeEach ( async function ( ) {
19081925 // Load the file encryptedFields.json as encryptedFields.
19091926 encryptedFields = EJSON . parse (
1910- await fs . promises . readFile ( path . join ( data , 'encryptedFields.json' ) ) ,
1927+ await fs . readFile ( path . join ( data , 'encryptedFields.json' ) , 'utf8' ) ,
19111928 { relaxed : false }
19121929 ) ;
19131930 // Load the file key1-document.json as key1Document.
19141931 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' ) ,
19161933 { relaxed : false }
19171934 ) ;
19181935 // Read the "_id" field of key1Document as key1ID.
@@ -2308,15 +2325,13 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
23082325 kmip : { } ,
23092326 local : undefined
23102327 } ;
2311- /** @type {import('../../mongodb').MongoClient } */
23122328 let client1 ;
2313- /** @type {import('../../mongodb').MongoClient } */
23142329 let client2 ;
23152330
23162331 describe ( 'Case 1: Rewrap with separate ClientEncryption' , function ( ) {
23172332 /**
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`.
23202335 */
23212336 function * generateTestCombinations ( ) {
23222337 const providers = Object . keys ( masterKeys ) ;
0 commit comments