Skip to content

Commit 4ffea6b

Browse files
committed
test: multiple collection fails with a specific error when not enabled
1 parent 16d6dff commit 4ffea6b

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

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

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import * as fs from 'node:fs/promises';
22
import * as path from 'node:path';
33

44
import { expect } from 'chai';
5+
import { type MongoCryptOptions } from 'mongodb-client-encryption';
6+
import * as sinon from 'sinon';
57

68
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
7-
import { BSON, type Document, type MongoClient } from '../../mongodb';
9+
import { AutoEncrypter, BSON, type Document, type MongoClient } from '../../mongodb';
810
import { type TestConfiguration } from '../../tools/runner/config';
911
import { getEncryptExtraOptions } from '../../tools/utils';
1012

@@ -342,4 +344,70 @@ describe.only('$lookup support', function () {
342344
new Error('Upgrade'),
343345
{ requires: { ...defaultMetadata.requires, mongodb: '<8.1.0' } }
344346
);
347+
348+
describe('Node.js custom test', function () {
349+
describe('when enableMultipleCollinfo is off and a $lookup is run', function () {
350+
let client: MongoClient;
351+
352+
beforeEach(async function () {
353+
const getMongoCrypt = sinon.stub(AutoEncrypter, 'getMongoCrypt').callsFake(function () {
354+
const MongoCrypt = getMongoCrypt.wrappedMethod.call(this);
355+
return class extends MongoCrypt {
356+
constructor(options: MongoCryptOptions) {
357+
//@ts-expect-error: not yet in the defs
358+
options.enableMultipleCollinfo = false;
359+
super(options);
360+
}
361+
};
362+
});
363+
364+
client = this.configuration.newClient(
365+
{},
366+
{
367+
autoEncryption: {
368+
keyVaultNamespace: 'db.keyvault',
369+
kmsProviders: { local: getCSFLEKMSProviders().local },
370+
extraOptions: {
371+
cryptSharedLibPath: getEncryptExtraOptions().cryptSharedLibPath,
372+
mongocryptdBypassSpawn: true,
373+
cryptSharedLibRequired: true
374+
}
375+
}
376+
}
377+
);
378+
});
379+
380+
afterEach(async function () {
381+
sinon.restore();
382+
await client.close();
383+
});
384+
385+
it(
386+
'throws a TypeError about libmongocrypt not enabled to support multiple collections',
387+
defaultMetadata,
388+
async () => {
389+
const collection = client.db('db').collection('csfle');
390+
const actual = await collection
391+
.aggregate([
392+
{ $match: { csfle: 'csfle' } },
393+
{
394+
$lookup: {
395+
from: 'csfle2',
396+
as: 'matched',
397+
pipeline: [{ $match: { csfle2: 'csfle2' } }, { $project: { _id: 0 } }]
398+
}
399+
},
400+
{ $project: { _id: 0 } }
401+
])
402+
.toArray()
403+
.catch(error => error);
404+
405+
expect(actual).to.be.instanceOf(TypeError);
406+
expect(actual.message).to.match(
407+
/libmongocrypt is not configured to support encrypting a command with multiple collections/i
408+
);
409+
}
410+
);
411+
});
412+
});
345413
});

0 commit comments

Comments
 (0)