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 = ( ) => { } ;
4343const metadata = {
4444 requires : {
@@ -55,6 +55,24 @@ const eeMetadata = {
5555 }
5656} ;
5757
58+ async function loadExternal ( file ) {
59+ return EJSON . parse (
60+ await fs . readFile (
61+ path . resolve ( __dirname , '../../spec/client-side-encryption/external' , file ) ,
62+ 'utf8'
63+ )
64+ ) ;
65+ }
66+
67+ async function loadLimits ( file ) {
68+ return EJSON . parse (
69+ await fs . readFile (
70+ path . resolve ( __dirname , '../../spec/client-side-encryption/limits' , file ) ,
71+ 'utf8'
72+ )
73+ ) ;
74+ }
75+
5876// Tests for the ClientEncryption type are not included as part of the YAML tests.
5977
6078// In the prose tests LOCAL_MASTERKEY refers to the following base64:
@@ -63,6 +81,9 @@ const eeMetadata = {
6381
6482// Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk
6583describe ( 'Client Side Encryption Prose Tests' , metadata , function ( ) {
84+ let externalKey ;
85+ let externalSchema ;
86+
6687 const dataDbName = 'db' ;
6788 const dataCollName = 'coll' ;
6889 const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
@@ -75,6 +96,11 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
7596 'base64'
7697 ) ;
7798
99+ before ( async function ( ) {
100+ externalKey = await loadExternal ( 'external-key.json' ) ;
101+ externalSchema = await loadExternal ( 'external-schema.json' ) ;
102+ } ) ;
103+
78104 describe ( 'Data key and double encryption' , function ( ) {
79105 // Data key and double encryption
80106 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -350,18 +376,8 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
350376 // and confirming that the externalClient is firing off keyVault requests during
351377 // encrypted operations
352378 describe ( 'External Key Vault Test' , function ( ) {
353- function loadExternal ( file ) {
354- return EJSON . parse (
355- fs . readFileSync ( path . resolve ( __dirname , '../../spec/client-side-encryption/external' , file ) )
356- ) ;
357- }
358-
359- const externalKey = loadExternal ( 'external-key.json' ) ;
360- const externalSchema = loadExternal ( 'external-schema.json' ) ;
361-
362- beforeEach ( function ( ) {
379+ beforeEach ( async function ( ) {
363380 this . client = this . configuration . newClient ( ) ;
364-
365381 // 1. Create a MongoClient without encryption enabled (referred to as ``client``).
366382 return (
367383 this . client
@@ -551,15 +567,15 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
551567 } ) ;
552568
553569 describe ( 'BSON size limits and batch splitting' , function ( ) {
554- function loadLimits ( file ) {
555- return EJSON . parse (
556- fs . readFileSync ( path . resolve ( __dirname , '../../spec/client-side-encryption/limits' , file ) )
557- ) ;
558- }
559-
560- const limitsSchema = loadLimits ( 'limits-schema .json' ) ;
561- const limitsKey = loadLimits ( 'limits-key .json' ) ;
562- const limitsDoc = loadLimits ( 'limits-doc.json' ) ;
570+ let limitsSchema ;
571+ let limitsKey ;
572+ let limitsDoc ;
573+
574+ before ( async function ( ) {
575+ limitsSchema = await loadLimits ( 'limits-schema.json' ) ;
576+ limitsKey = await loadLimits ( 'limits-key .json' ) ;
577+ limitsDoc = await loadLimits ( 'limits-doc .json' ) ;
578+ } ) ;
563579
564580 let hasRunFirstTimeSetup = false ;
565581
@@ -826,9 +842,9 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
826842
827843 describe ( 'Corpus Test' , function ( ) {
828844 it ( 'runs in a separate suite' , ( ) => {
829- expect ( ( ) =>
830- fs . statSync ( path . resolve ( __dirname , './client_side_encryption.prose.06.corpus.test.ts' ) )
831- ) . not . to . throw ( ) ;
845+ expect ( async ( ) => {
846+ await fs . stat ( path . resolve ( __dirname , './client_side_encryption.prose.06.corpus.test.ts' ) ) ;
847+ } ) . not . to . throw ( ) ;
832848 } ) ;
833849 } ) ;
834850
@@ -1691,6 +1707,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
16911707 context (
16921708 'Case 5: `tlsDisableOCSPEndpointCheck` is permitted' ,
16931709 metadata ,
1710+ // eslint-disable-next-line @typescript-eslint/no-empty-function
16941711 function ( ) { }
16951712 ) . skipReason = 'TODO(NODE-4840): Node does not support any OCSP options' ;
16961713
@@ -1911,12 +1928,12 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
19111928 beforeEach ( async function ( ) {
19121929 // Load the file encryptedFields.json as encryptedFields.
19131930 encryptedFields = EJSON . parse (
1914- await fs . promises . readFile ( path . join ( data , 'encryptedFields.json' ) ) ,
1931+ await fs . readFile ( path . join ( data , 'encryptedFields.json' ) , 'utf8' ) ,
19151932 { relaxed : false }
19161933 ) ;
19171934 // Load the file key1-document.json as key1Document.
19181935 key1Document = EJSON . parse (
1919- await fs . promises . readFile ( path . join ( data , 'keys' , 'key1-document.json' ) ) ,
1936+ await fs . readFile ( path . join ( data , 'keys' , 'key1-document.json' ) , 'utf8' ) ,
19201937 { relaxed : false }
19211938 ) ;
19221939 // Read the "_id" field of key1Document as key1ID.
@@ -2312,15 +2329,13 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
23122329 kmip : { } ,
23132330 local : undefined
23142331 } ;
2315- /** @type {import('../../mongodb').MongoClient } */
23162332 let client1 ;
2317- /** @type {import('../../mongodb').MongoClient } */
23182333 let client2 ;
23192334
23202335 describe ( 'Case 1: Rewrap with separate ClientEncryption' , function ( ) {
23212336 /**
2322- * Run the following test case for each pair of KMS providers (referred to as `` srcProvider`` and `` dstProvider` `).
2323- * Include pairs where `` srcProvider`` equals `` dstProvider` `.
2337+ * Run the following test case for each pair of KMS providers (referred to as `srcProvider` and `dstProvider`).
2338+ * Include pairs where `srcProvider` equals `dstProvider`.
23242339 */
23252340 function * generateTestCombinations ( ) {
23262341 const providers = Object . keys ( masterKeys ) ;
0 commit comments