Skip to content

Commit e688cb8

Browse files
committed
wip
1 parent 51244df commit e688cb8

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

test/benchmark/main.mjs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable no-console */
2+
import util from 'node:util';
3+
import process from 'node:process';
4+
import path from 'node:path';
5+
import child_process, { spawn } from 'node:child_process';
6+
import events from 'node:events';
7+
import url from 'node:url';
8+
9+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
10+
11+
/** Resolves to the root of this repository */
12+
function resolveRoot(...paths) {
13+
return path.resolve(__dirname, '..', '..', ...paths);
14+
}
15+
16+
/** `xtrace` style command runner, uses spawn so that stdio is inherited */
17+
async function run(command, args = [], options = {}) {
18+
const commandDetails = `+ ${command} ${args.join(' ')}${options.cwd ? ` (in: ${options.cwd})` : ''}`;
19+
console.error(commandDetails);
20+
const proc = child_process.spawn(command, args, {
21+
shell: process.platform === 'win32',
22+
stdio: 'inherit',
23+
cwd: resolveRoot('.'),
24+
...options
25+
});
26+
await events.once(proc, 'exit');
27+
28+
if (proc.exitCode !== 0) throw new Error(`CRASH(${proc.exitCode}): ${commandDetails}`);
29+
}
30+
31+
function parseArguments() {
32+
const options = {
33+
help: { short: 'h', type: 'boolean', default: false }
34+
};
35+
36+
const args = util.parseArgs({ args: process.argv.slice(2), options, allowPositionals: false });
37+
38+
if (args.values.help) {
39+
console.log(
40+
`${path.basename(process.argv[1])} ${[...Object.keys(options)]
41+
.filter(k => k !== 'help')
42+
.map(k => `[--${k}=${options[k].type}]`)
43+
.join(' ')}`
44+
);
45+
process.exit(0);
46+
}
47+
48+
return {};
49+
}
50+
51+
async function main() {
52+
parseArguments();
53+
bench({ spawn: true });
54+
}
55+
56+
await main();
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import process from 'node:process';
2+
import { MongoClient, ClientEncryption } from 'mongodb';
3+
4+
let { MONGODB_URI = '', CRYPT_SHARED_LIB_PATH = '' } = process.env;
5+
MONGODB_URI.length === 0 ? 'mongodb://127.0.0.1:27017' : MONGODB_URI;
6+
const extraOptions =
7+
CRYPT_SHARED_LIB_PATH.length !== 0 ? { cryptSharedLibPath: CRYPT_SHARED_LIB_PATH } : undefined;
8+
9+
const LOCAL_KEY = Buffer.from(
10+
'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk',
11+
'base64'
12+
);
13+
14+
const $jsonSchema = {
15+
properties: {
16+
encrypted: {
17+
encrypt: {
18+
keyId: [{ $binary: { base64: 'LOCALAAAAAAAAAAAAAAAAA==', subType: '04' } }],
19+
bsonType: 'string',
20+
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'
21+
}
22+
}
23+
},
24+
bsonType: 'object'
25+
};
26+
27+
let client;
28+
29+
let ae = {
30+
autoEncryption: {
31+
keyVaultNamespace: 'keyvault.datakeys',
32+
kmsProviders: { local: { key: LOCAL_KEY } },
33+
bypassAutoEncryption: false,
34+
keyVaultClient: undefined,
35+
extraOptions
36+
}
37+
};
38+
39+
async function setupCollection() {
40+
const client = new MongoClient(MONGODB_URI);
41+
const collectionName = 'test_fle_bench';
42+
const db = client.db('test_fle_bench');
43+
await db.dropCollection(collectionName).catch(() => {});
44+
45+
const clientEncryption = new ClientEncryption(client, {
46+
keyVaultNamespace: 'keyvault.datakeys',
47+
kmsProviders: { local: { key: LOCAL_KEY } }
48+
});
49+
50+
const encryptedFields = {
51+
escCollection: 'esc',
52+
eccCollection: 'ecc',
53+
ecocCollection: 'ecoc',
54+
fields: Array.from({ length: 5000 }, (_, i) => ({
55+
path: `key${i.toString().padStart(4, '0')}`,
56+
bsonType: 'string'
57+
}))
58+
};
59+
60+
const { collection } = await clientEncryption.createEncryptedCollection(db, collectionName, {
61+
provider: 'local',
62+
createCollectionOptions: { encryptedFields }
63+
});
64+
65+
return collection;
66+
}
67+
68+
async function main() {
69+
const collection = await setupCollection();
70+
71+
await client
72+
.db('test_fle_bench')
73+
.createCollection('test_fle_bench', { validator: { $jsonSchema } });
74+
}
75+
76+
export async function bench(options) {}

0 commit comments

Comments
 (0)