Skip to content

Commit ede93b7

Browse files
committed
chore(NODE-6847): fix flaky KMS closed error in should pass corpus without client schema
1 parent d9c7afc commit ede93b7

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/client-side-encryption/state_machine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ export class StateMachine {
367367
return new MongoCryptError('KMS request failed', { cause });
368368
}
369369

370+
const closeError = new MongoCryptError('KMS request will close');
370371
function onclose() {
371-
return new MongoCryptError('KMS request closed');
372+
return new MongoCryptError('KMS request closed', { cause: closeError });
372373
}
373374

374375
const tlsOptions = this.options.tlsOptions;

test/integration/client-side-encryption/client_side_encryption.prose.06.corpus.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { expect } from 'chai';
55
import * as fs from 'fs';
66
import * as path from 'path';
77

8+
import { type ClientEncryptionEncryptOptions } from '../../../mongodb';
89
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
910
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
1011
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
11-
import { type MongoClient, WriteConcern } from '../../mongodb';
12+
import { type AutoEncryptionOptions, type MongoClient, WriteConcern } from '../../mongodb';
1213
import { getEncryptExtraOptions } from '../../tools/utils';
1314

1415
describe('Client Side Encryption Prose Corpus Test', function () {
@@ -68,7 +69,7 @@ describe('Client Side Encryption Prose Corpus Test', function () {
6869
const algorithmMap = new Map([
6970
['rand', 'AEAD_AES_256_CBC_HMAC_SHA_512-Random'],
7071
['det', 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic']
71-
]);
72+
] as const);
7273
const identifierMap = new Map([
7374
['local', corpusKeyLocal._id],
7475
['aws', corpusKeyAws._id],
@@ -161,7 +162,12 @@ describe('Client Side Encryption Prose Corpus Test', function () {
161162

162163
afterEach(() => client?.close());
163164

164-
function defineCorpusTests(corpus, corpusEncryptedExpected, useClientSideSchema: boolean) {
165+
function defineCorpusTests(
166+
corpus,
167+
corpusEncryptedExpected,
168+
useClientSideSchema: boolean,
169+
i?: number
170+
) {
165171
let clientEncrypted: MongoClient, clientEncryption: ClientEncryption;
166172
beforeEach(async function () {
167173
// 2. Using ``client``, drop and create the collection ``db.coll`` configured with the included JSON schema `corpus/corpus-schema.json <../corpus/corpus-schema.json>`_.
@@ -197,7 +203,7 @@ describe('Client Side Encryption Prose Corpus Test', function () {
197203
}
198204
};
199205
const extraOptions = getEncryptExtraOptions();
200-
const autoEncryption = {
206+
const autoEncryption: AutoEncryptionOptions = {
201207
keyVaultNamespace,
202208
kmsProviders,
203209
tlsOptions,
@@ -221,10 +227,10 @@ describe('Client Side Encryption Prose Corpus Test', function () {
221227
afterEach(() => clientEncrypted.close());
222228

223229
it(
224-
`should pass corpus ${useClientSideSchema ? 'with' : 'without'} client schema`,
230+
`should pass corpus ${useClientSideSchema ? 'with' : 'without'} client schema` + i,
225231
metadata,
226232
async function () {
227-
const corpusCopied = {};
233+
const corpusCopied: Record<string, any> = {};
228234

229235
// 5. Load `corpus/corpus.json <../corpus/corpus.json>`_ to a variable named ``corpus``. The corpus contains subdocuments with the following fields:
230236
//
@@ -262,7 +268,7 @@ describe('Client Side Encryption Prose Corpus Test', function () {
262268
continue;
263269
}
264270
if (field.method === 'explicit') {
265-
const encryptOptions = {
271+
const encryptOptions: ClientEncryptionEncryptOptions = {
266272
algorithm: algorithmMap.get(field.algo)
267273
};
268274
if (field.identifier === 'id') {
@@ -359,7 +365,7 @@ describe('Client Side Encryption Prose Corpus Test', function () {
359365
// });
360366
// });
361367

362-
defineCorpusTests(corpusAll, corpusEncryptedExpectedAll, false);
368+
for (let i = 0; i < 100; i++) defineCorpusTests(corpusAll, corpusEncryptedExpectedAll, false, i);
363369

364370
// 9. Repeat steps 1-8 with a local JSON schema. I.e. amend step 4 to configure the schema on ``client_encrypted`` with the ``schema_map`` option.
365371
defineCorpusTests(corpusAll, corpusEncryptedExpectedAll, true);

0 commit comments

Comments
 (0)