Skip to content

Commit 732b009

Browse files
add csfle prose test 20
1 parent ec82ae9 commit 732b009

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { expect } from 'chai';
2+
import { once } from 'events';
3+
import { createServer, type Server } from 'net';
4+
5+
import { getCSFLEKMSProviders } from '../../csfle-kms-providers';
6+
import { type MongoClient } from '../../mongodb';
7+
import { ClientSideEncryptionFilter } from '../../tools/runner/filters/client_encryption_filter';
8+
import { getEncryptExtraOptions } from '../../tools/utils';
9+
10+
describe('20. Bypass creating mongocryptd client when shared library is loaded', function () {
11+
let server: Server;
12+
let hasConnection = false;
13+
let client: MongoClient;
14+
15+
beforeEach(function () {
16+
if (!ClientSideEncryptionFilter.cryptShared) {
17+
this.currentTest.skipReason =
18+
'test requires that the crypt shared be loaded into the current process.';
19+
this.skip();
20+
}
21+
22+
server = createServer({});
23+
server.listen(27021);
24+
server.on('connection', () => (hasConnection = true));
25+
26+
client = this.configuration.newClient(
27+
{},
28+
{
29+
autoEncryption: {
30+
kmsProviders: { local: getCSFLEKMSProviders().local },
31+
keyVaultNamespace: 'keyvault.datakeys',
32+
extraOptions: {
33+
cryptSharedLibPath: getEncryptExtraOptions().cryptSharedLibPath,
34+
mongocryptdURI: 'mongodb://localhost:27021'
35+
}
36+
}
37+
}
38+
);
39+
});
40+
41+
afterEach(async function () {
42+
server && (await once(server.close(), 'close'));
43+
await client?.close();
44+
});
45+
46+
it(
47+
'does not create or use a mongocryptd client when the shared library is loaded',
48+
{
49+
requires: {
50+
clientSideEncryption: true
51+
}
52+
},
53+
async function () {
54+
await client.db('db').collection('coll').insertOne({ unencrypted: 'test' });
55+
expect(hasConnection).to.be.false;
56+
57+
expect(client.autoEncrypter._mongocryptdClient).to.be.undefined;
58+
}
59+
);
60+
});

0 commit comments

Comments
 (0)