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,23 +38,41 @@ 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
- /** @type { MongoDBMetadataUI } */
44
- const metadata = {
43
+ const metadata : MongoDBMetadataUI = {
45
44
requires : {
46
45
clientSideEncryption : true ,
47
46
topology : '!load-balanced'
48
47
}
49
48
} ;
50
49
51
- const eeMetadata = {
50
+ const eeMetadata : MongoDBMetadataUI = {
52
51
requires : {
53
52
clientSideEncryption : true ,
54
53
mongodb : '>=7.0.0' ,
55
54
topology : [ 'replicaset' , 'sharded' ]
56
55
}
57
56
} ;
58
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
+
59
76
// Tests for the ClientEncryption type are not included as part of the YAML tests.
60
77
61
78
// In the prose tests LOCAL_MASTERKEY refers to the following base64:
@@ -64,6 +81,9 @@ const eeMetadata = {
64
81
65
82
// Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk
66
83
describe ( 'Client Side Encryption Prose Tests' , metadata , function ( ) {
84
+ let externalKey ;
85
+ let externalSchema ;
86
+
67
87
const dataDbName = 'db' ;
68
88
const dataCollName = 'coll' ;
69
89
const dataNamespace = `${ dataDbName } .${ dataCollName } ` ;
@@ -76,6 +96,11 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
76
96
'base64'
77
97
) ;
78
98
99
+ before ( async function ( ) {
100
+ externalKey = await loadExternal ( 'external-key.json' ) ;
101
+ externalSchema = await loadExternal ( 'external-schema.json' ) ;
102
+ } ) ;
103
+
79
104
describe ( 'Data key and double encryption' , function ( ) {
80
105
// Data key and double encryption
81
106
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -351,18 +376,8 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
351
376
// and confirming that the externalClient is firing off keyVault requests during
352
377
// encrypted operations
353
378
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 ( ) {
379
+ beforeEach ( async function ( ) {
364
380
this . client = this . configuration . newClient ( ) ;
365
-
366
381
// 1. Create a MongoClient without encryption enabled (referred to as ``client``).
367
382
return (
368
383
this . client
@@ -552,15 +567,15 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
552
567
} ) ;
553
568
554
569
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' ) ;
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
+ } ) ;
564
579
565
580
let hasRunFirstTimeSetup = false ;
566
581
@@ -827,9 +842,9 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
827
842
828
843
describe ( 'Corpus Test' , function ( ) {
829
844
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 ( ) ;
845
+ expect ( async ( ) => {
846
+ await fs . stat ( path . resolve ( __dirname , './client_side_encryption.prose.06.corpus.test.ts' ) ) ;
847
+ } ) . not . to . throw ( ) ;
833
848
} ) ;
834
849
} ) ;
835
850
@@ -1687,6 +1702,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1687
1702
context (
1688
1703
'Case 5: `tlsDisableOCSPEndpointCheck` is permitted' ,
1689
1704
metadata ,
1705
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
1690
1706
function ( ) { }
1691
1707
) . skipReason = 'TODO(NODE-4840): Node does not support any OCSP options' ;
1692
1708
@@ -1907,12 +1923,12 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
1907
1923
beforeEach ( async function ( ) {
1908
1924
// Load the file encryptedFields.json as encryptedFields.
1909
1925
encryptedFields = EJSON . parse (
1910
- await fs . promises . readFile ( path . join ( data , 'encryptedFields.json' ) ) ,
1926
+ await fs . readFile ( path . join ( data , 'encryptedFields.json' ) , 'utf8' ) ,
1911
1927
{ relaxed : false }
1912
1928
) ;
1913
1929
// Load the file key1-document.json as key1Document.
1914
1930
key1Document = EJSON . parse (
1915
- await fs . promises . readFile ( path . join ( data , 'keys' , 'key1-document.json' ) ) ,
1931
+ await fs . readFile ( path . join ( data , 'keys' , 'key1-document.json' ) , 'utf8' ) ,
1916
1932
{ relaxed : false }
1917
1933
) ;
1918
1934
// Read the "_id" field of key1Document as key1ID.
@@ -2308,15 +2324,13 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
2308
2324
kmip : { } ,
2309
2325
local : undefined
2310
2326
} ;
2311
- /** @type {import('../../mongodb').MongoClient } */
2312
2327
let client1 ;
2313
- /** @type {import('../../mongodb').MongoClient } */
2314
2328
let client2 ;
2315
2329
2316
2330
describe ( 'Case 1: Rewrap with separate ClientEncryption' , function ( ) {
2317
2331
/**
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` `.
2332
+ * Run the following test case for each pair of KMS providers (referred to as `srcProvider` and `dstProvider`).
2333
+ * Include pairs where `srcProvider` equals `dstProvider`.
2320
2334
*/
2321
2335
function * generateTestCombinations ( ) {
2322
2336
const providers = Object . keys ( masterKeys ) ;
0 commit comments