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
const metadata = {
44
44
requires : {
@@ -55,6 +55,24 @@ const eeMetadata = {
55
55
}
56
56
} ;
57
57
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
+
58
76
// Tests for the ClientEncryption type are not included as part of the YAML tests.
59
77
60
78
// In the prose tests LOCAL_MASTERKEY refers to the following base64:
@@ -63,6 +81,9 @@ const eeMetadata = {
63
81
64
82
// Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk
65
83
describe ( 'Client Side Encryption Prose Tests' , metadata , function ( ) {
84
+ let externalKey ;
85
+ let externalSchema ;
86
+
66
87
const dataDbName = 'db' ;
67
88
const dataCollName = 'coll' ;
68
89
const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
@@ -75,6 +96,11 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
75
96
'base64'
76
97
) ;
77
98
99
+ before ( async function ( ) {
100
+ externalKey = await loadExternal ( 'external-key.json' ) ;
101
+ externalSchema = await loadExternal ( 'external-schema.json' ) ;
102
+ } ) ;
103
+
78
104
describe ( 'Data key and double encryption' , function ( ) {
79
105
// Data key and double encryption
80
106
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -350,18 +376,8 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
350
376
// and confirming that the externalClient is firing off keyVault requests during
351
377
// encrypted operations
352
378
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 ( ) {
363
380
this . client = this . configuration . newClient ( ) ;
364
-
365
381
// 1. Create a MongoClient without encryption enabled (referred to as ``client``).
366
382
return (
367
383
this . client
@@ -551,15 +567,15 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
551
567
} ) ;
552
568
553
569
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
+ } ) ;
563
579
564
580
let hasRunFirstTimeSetup = false ;
565
581
@@ -826,9 +842,9 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
826
842
827
843
describe ( 'Corpus Test' , function ( ) {
828
844
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 ( ) ;
832
848
} ) ;
833
849
} ) ;
834
850
@@ -1691,6 +1707,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1691
1707
context (
1692
1708
'Case 5: `tlsDisableOCSPEndpointCheck` is permitted' ,
1693
1709
metadata ,
1710
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1694
1711
function ( ) { }
1695
1712
) . skipReason = 'TODO(NODE-4840): Node does not support any OCSP options' ;
1696
1713
@@ -1911,12 +1928,12 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1911
1928
beforeEach ( async function ( ) {
1912
1929
// Load the file encryptedFields.json as encryptedFields.
1913
1930
encryptedFields = EJSON . parse (
1914
- await fs . promises . readFile ( path . join ( data , 'encryptedFields.json' ) ) ,
1931
+ await fs . readFile ( path . join ( data , 'encryptedFields.json' ) , 'utf8' ) ,
1915
1932
{ relaxed : false }
1916
1933
) ;
1917
1934
// Load the file key1-document.json as key1Document.
1918
1935
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' ) ,
1920
1937
{ relaxed : false }
1921
1938
) ;
1922
1939
// Read the "_id" field of key1Document as key1ID.
@@ -2312,15 +2329,13 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
2312
2329
kmip : { } ,
2313
2330
local : undefined
2314
2331
} ;
2315
- /** @type {import('../../mongodb').MongoClient } */
2316
2332
let client1 ;
2317
- /** @type {import('../../mongodb').MongoClient } */
2318
2333
let client2 ;
2319
2334
2320
2335
describe ( 'Case 1: Rewrap with separate ClientEncryption' , function ( ) {
2321
2336
/**
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`.
2324
2339
*/
2325
2340
function * generateTestCombinations ( ) {
2326
2341
const providers = Object . keys ( masterKeys ) ;
0 commit comments