Skip to content

Commit 227b904

Browse files
committed
chore: comments
1 parent d7089c2 commit 227b904

File tree

5 files changed

+53
-76
lines changed

5 files changed

+53
-76
lines changed

test/integration/client-side-encryption/client_side_encryption.prose.25.lookup.test.ts

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as fs from 'node:fs/promises';
22
import * as path from 'node:path';
33

44
import { expect } from 'chai';
5-
import { type Test } from 'mocha';
65
import { type MongoCryptOptions } from 'mongodb-client-encryption';
76
import * as sinon from 'sinon';
87

@@ -15,7 +14,7 @@ const defaultMetadata: MongoDBMetadataUI = {
1514
requires: {
1615
topology: '!single',
1716
clientSideEncryption: '>=6.3.0',
18-
mongodb: '>=8.1.0'
17+
mongodb: '>=7.0.0'
1918
}
2019
};
2120

@@ -31,6 +30,7 @@ const newEncryptedClient = ({ configuration }: { configuration: TestConfiguratio
3130
configuration.newClient(
3231
{},
3332
{
33+
writeConcern: { w: 'majority' },
3434
autoEncryption: {
3535
keyVaultNamespace: 'db.keyvault',
3636
kmsProviders: { local: getCSFLEKMSProviders().local },
@@ -41,9 +41,7 @@ const newEncryptedClient = ({ configuration }: { configuration: TestConfiguratio
4141

4242
describe('$lookup support', defaultMetadata, function () {
4343
before(async function () {
44-
const mochaTest = {
45-
metadata: defaultMetadata
46-
} as unknown as Test;
44+
const mochaTest = { metadata: defaultMetadata };
4745

4846
if (!this.configuration.filters.MongoDBVersionFilter.filter(mochaTest)) {
4947
return;
@@ -57,16 +55,26 @@ describe('$lookup support', defaultMetadata, function () {
5755
return;
5856
}
5957

60-
let client: MongoClient, encryptedClient: MongoClient;
58+
let unencryptedClient: MongoClient, encryptedClient: MongoClient;
6159
try {
62-
/** Create an unencrypted MongoClient. */
63-
client = this.configuration.newClient();
60+
/**
61+
* Create an encrypted MongoClient configured with:
62+
*
63+
* ```txt
64+
* AutoEncryptionOpts(
65+
* keyVaultNamespace="db.keyvault",
66+
* kmsProviders={"local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" }}
67+
* )
68+
* ```
69+
*/
70+
encryptedClient = newEncryptedClient(this);
71+
6472
/** Drop database db. */
65-
await client.db('db').dropDatabase();
73+
await encryptedClient.db('db').dropDatabase();
6674

6775
/** Insert `key-doc.json` into db.keyvault. */
6876
const keyDoc = await readFixture('key-doc.json');
69-
await client.db('db').collection('keyvault').insertOne(keyDoc);
77+
await encryptedClient.db('db').collection('keyvault').insertOne(keyDoc);
7078

7179
/**
7280
* Create the following collections:
@@ -113,20 +121,11 @@ describe('$lookup support', defaultMetadata, function () {
113121
];
114122

115123
for (const { name, options } of collections) {
116-
await client.db('db').createCollection(name, options);
124+
await encryptedClient.db('db').createCollection(name, options);
117125
}
118126

119-
/**
120-
* Create an encrypted MongoClient configured with:
121-
*
122-
* ```txt
123-
* AutoEncryptionOpts(
124-
* keyVaultNamespace="db.keyvault",
125-
* kmsProviders={"local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" }}
126-
* )
127-
* ```
128-
*/
129-
encryptedClient = newEncryptedClient(this);
127+
/** Create an unencrypted MongoClient. */
128+
unencryptedClient = this.configuration.newClient({}, { writeConcern: { w: 'majority' } });
130129

131130
/**
132131
* ```
@@ -147,12 +146,12 @@ describe('$lookup support', defaultMetadata, function () {
147146

148147
if (name.startsWith('no_')) continue;
149148

150-
expect(await client.db('db').collection(name).findOne(insertedId))
149+
expect(await unencryptedClient.db('db').collection(name).findOne(insertedId))
151150
.to.have.property(Object.keys(document)[0])
152151
.that.has.property('_bsontype', 'Binary');
153152
}
154153
} finally {
155-
await client?.close();
154+
await unencryptedClient?.close();
156155
await encryptedClient?.close();
157156
}
158157
});
@@ -161,7 +160,7 @@ describe('$lookup support', defaultMetadata, function () {
161160
title: string,
162161
collName: string,
163162
pipeline: Document[],
164-
expected: Document,
163+
expected: Document | RegExp,
165164
metadata?: MongoDBMetadataUI
166165
) {
167166
describe(title.slice(0, title.indexOf(':')), function () {
@@ -182,12 +181,11 @@ describe('$lookup support', defaultMetadata, function () {
182181
.toArray()
183182
.catch(error => error);
184183

185-
const expectedError = expected instanceof Error;
184+
const expectedError = expected instanceof RegExp;
186185

187186
if (expectedError) {
188187
expect(actual).to.be.instanceOf(Error);
189-
const expectedErrorMessage = new RegExp(expected.message, 'i');
190-
if (!expectedErrorMessage.test(actual.message)) {
188+
if (!expected.test(actual.message)) {
191189
throw actual;
192190
}
193191
} else if (actual instanceof Error) {
@@ -214,7 +212,8 @@ describe('$lookup support', defaultMetadata, function () {
214212
},
215213
{ $project: { _id: 0 } }
216214
],
217-
{ csfle: 'csfle', matched: [{ no_schema: 'no_schema' }] }
215+
{ csfle: 'csfle', matched: [{ no_schema: 'no_schema' }] },
216+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
218217
);
219218

220219
test(
@@ -234,7 +233,8 @@ describe('$lookup support', defaultMetadata, function () {
234233
},
235234
{ $project: { _id: 0, __safeContent__: 0 } }
236235
],
237-
{ qe: 'qe', matched: [{ no_schema: 'no_schema' }] }
236+
{ qe: 'qe', matched: [{ no_schema: 'no_schema' }] },
237+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
238238
);
239239

240240
test(
@@ -251,7 +251,8 @@ describe('$lookup support', defaultMetadata, function () {
251251
},
252252
{ $project: { _id: 0 } }
253253
],
254-
{ no_schema: 'no_schema', matched: [{ csfle: 'csfle' }] }
254+
{ no_schema: 'no_schema', matched: [{ csfle: 'csfle' }] },
255+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
255256
);
256257

257258
test(
@@ -268,7 +269,8 @@ describe('$lookup support', defaultMetadata, function () {
268269
},
269270
{ $project: { _id: 0 } }
270271
],
271-
{ no_schema: 'no_schema', matched: [{ qe: 'qe' }] }
272+
{ no_schema: 'no_schema', matched: [{ qe: 'qe' }] },
273+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
272274
);
273275

274276
test(
@@ -285,7 +287,8 @@ describe('$lookup support', defaultMetadata, function () {
285287
},
286288
{ $project: { _id: 0 } }
287289
],
288-
{ csfle: 'csfle', matched: [{ csfle2: 'csfle2' }] }
290+
{ csfle: 'csfle', matched: [{ csfle2: 'csfle2' }] },
291+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
289292
);
290293

291294
test(
@@ -302,7 +305,8 @@ describe('$lookup support', defaultMetadata, function () {
302305
},
303306
{ $project: { _id: 0, __safeContent__: 0 } }
304307
],
305-
{ qe: 'qe', matched: [{ qe2: 'qe2' }] }
308+
{ qe: 'qe', matched: [{ qe2: 'qe2' }] },
309+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
306310
);
307311

308312
test(
@@ -319,7 +323,8 @@ describe('$lookup support', defaultMetadata, function () {
319323
},
320324
{ $project: { _id: 0 } }
321325
],
322-
{ no_schema: 'no_schema', matched: [{ no_schema2: 'no_schema2' }] }
326+
{ no_schema: 'no_schema', matched: [{ no_schema2: 'no_schema2' }] },
327+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
323328
);
324329

325330
test(
@@ -336,7 +341,8 @@ describe('$lookup support', defaultMetadata, function () {
336341
},
337342
{ $project: { _id: 0 } }
338343
],
339-
new Error('not supported')
344+
/not supported/i,
345+
{ requires: { ...defaultMetadata.requires, mongodb: '>=8.1.0' } }
340346
);
341347

342348
test(
@@ -353,7 +359,7 @@ describe('$lookup support', defaultMetadata, function () {
353359
},
354360
{ $project: { _id: 0 } }
355361
],
356-
new Error('Upgrade'),
362+
/Upgrade/i,
357363
{ requires: { ...defaultMetadata.requires, mongodb: '<8.1.0' } }
358364
);
359365

@@ -362,9 +368,7 @@ describe('$lookup support', defaultMetadata, function () {
362368
let client: MongoClient;
363369

364370
beforeEach(async function () {
365-
const mochaTest = {
366-
metadata: defaultMetadata
367-
} as unknown as Test;
371+
const mochaTest = { metadata: defaultMetadata };
368372

369373
if (!this.configuration.filters.MongoDBVersionFilter.filter(mochaTest)) {
370374
return;
@@ -390,16 +394,7 @@ describe('$lookup support', defaultMetadata, function () {
390394
};
391395
});
392396

393-
client = this.configuration.newClient(
394-
{},
395-
{
396-
autoEncryption: {
397-
keyVaultNamespace: 'db.keyvault',
398-
kmsProviders: { local: getCSFLEKMSProviders().local },
399-
extraOptions: getEncryptExtraOptions()
400-
}
401-
}
402-
);
397+
client = newEncryptedClient(this);
403398
});
404399

405400
afterEach(async function () {

test/integration/client-side-encryption/client_side_encryption.prose.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,9 +1703,7 @@ describe('Client Side Encryption Prose Tests', metadata, function () {
17031703
context('Case 6: named KMS providers apply TLS options', function () {
17041704
afterEach(() => keyvaultClient?.close());
17051705
beforeEach(async function () {
1706-
const filter = new ClientSideEncryptionFilter();
1707-
await filter.initializeFilter({}, {});
1708-
const shouldSkip = filter.filter({
1706+
const shouldSkip = this.configuration.filters.ClientSideEncryptionFilter.filter({
17091707
metadata: {
17101708
requires: {
17111709
// 6.0.1 includes libmongocrypt 1.10.

test/integration/client-side-encryption/client_side_encryption.spec.test.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'path';
22

33
import { loadSpecTests } from '../../spec';
4-
import { ClientSideEncryptionFilter } from '../../tools/runner/filters/client_encryption_filter';
54
import {
65
gatherTestSuites,
76
generateTopologyTests,
@@ -60,8 +59,6 @@ const SKIPPED_TESTS = new Set([
6059

6160
const isServerless = !!process.env.SERVERLESS;
6261

63-
const filter = new ClientSideEncryptionFilter();
64-
6562
describe('Client Side Encryption (Legacy)', function () {
6663
const testContext = new TestRunnerContext({ requiresCSFLE: true });
6764
const testSuites = gatherTestSuites(
@@ -75,11 +72,7 @@ describe('Client Side Encryption (Legacy)', function () {
7572
return testContext.setup(this.configuration);
7673
});
7774

78-
before(async function () {
79-
await filter.initializeFilter({} as any, {});
80-
});
81-
82-
generateTopologyTests(testSuites, testContext, test => {
75+
generateTopologyTests(testSuites, testContext, (test, configuration) => {
8376
const { description } = test;
8477
if (SKIPPED_TESTS.has(description)) {
8578
return 'Skipped by generic test name skip filter.';
@@ -109,7 +102,7 @@ describe('Client Side Encryption (Legacy)', function () {
109102
'Automatically encrypt and decrypt with a named KMS provider'
110103
].includes(description)
111104
) {
112-
const result = filter.filter({
105+
const result = configuration.filters.ClientSideEncryptionFilter.filter({
113106
metadata: { requires: { clientSideEncryption: '>=6.0.1' } }
114107
});
115108

@@ -121,13 +114,9 @@ describe('Client Side Encryption (Legacy)', function () {
121114
});
122115

123116
describe('Client Side Encryption (Unified)', function () {
124-
before(async function () {
125-
await filter.initializeFilter({} as any, {});
126-
});
127-
128117
runUnifiedSuite(
129118
loadSpecTests(path.join('client-side-encryption', 'tests', 'unified')),
130-
({ description }) => {
119+
({ description }, configuration) => {
131120
const delegatedKMIPTests = [
132121
'rewrap with current KMS provider',
133122
'rewrap with new local KMS provider',
@@ -154,7 +143,7 @@ describe('Client Side Encryption (Unified)', function () {
154143
'can explicitly encrypt with a named KMS provider'
155144
];
156145
if (delegatedKMIPTests.includes(description)) {
157-
const shouldSkip = filter.filter({
146+
const shouldSkip = configuration.filters.ClientSideEncryptionFilter.filter({
158147
metadata: { requires: { clientSideEncryption: '>=6.0.1' } }
159148
});
160149
if (typeof shouldSkip === 'string') return shouldSkip;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { type Test } from 'mocha';
2-
31
import { type MongoClient } from '../../../mongodb';
42

53
export abstract class Filter {
64
async initializeFilter(_client: MongoClient, _context: Record<string, any>): Promise<void> {
75
return;
86
}
97

10-
abstract filter(test: Test): string | boolean;
8+
abstract filter(test: { metadata?: MongoDBMetadataUI }): string | boolean;
119
}

test/tools/spec-runner/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const {
1515
HEARTBEAT_EVENTS
1616
} = require('../../mongodb');
1717
const { isAnyRequirementSatisfied } = require('../unified-spec-runner/unified-utils');
18-
const { ClientSideEncryptionFilter } = require('../runner/filters/client_encryption_filter');
1918
const { getCSFLEKMSProviders } = require('../../csfle-kms-providers');
2019

2120
// Promise.try alternative https://stackoverflow.com/questions/60624081/promise-try-without-bluebird/60624164?noredirect=1#comment107255389_60624164
@@ -153,7 +152,7 @@ function legacyRunOnToRunOnRequirement(runOn) {
153152
}
154153

155154
/**
156-
* @param {((test: { description: string }) => true | string)?} filter a function that returns true for any tests that should run, false otherwise.
155+
* @param {((test: { description: string }, configuration: TestConfiguration) => true | string)?} filter a function that returns true for any tests that should run, false otherwise.
157156
*/
158157
function generateTopologyTests(testSuites, testContext, filter) {
159158
for (const testSuite of testSuites) {
@@ -198,10 +197,8 @@ function generateTopologyTests(testSuites, testContext, filter) {
198197

199198
let csfleFilterError = null;
200199
if (shouldRun && testContext.requiresCSFLE) {
201-
const csfleFilter = new ClientSideEncryptionFilter();
202-
await csfleFilter.initializeFilter(null, {});
203200
try {
204-
const filterResult = csfleFilter.filter({
201+
const filterResult = this.configuration.filters.ClientSideEncryptionFilter.filter({
205202
metadata: { requires: { clientSideEncryption: true } }
206203
});
207204
if (typeof filterResult === 'string') {

0 commit comments

Comments
 (0)