Skip to content

Commit 4498947

Browse files
add prose test
1 parent a8c8e58 commit 4498947

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/integration/client-side-encryption/driver.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,76 @@ describe('Client Side Encryption Functional', function () {
405405
}
406406
);
407407
});
408+
409+
describe('Range Explicit Encryption with JS native types', function () {
410+
installNodeDNSWorkaroundHooks();
411+
412+
const metaData: MongoDBMetadataUI = {
413+
requires: {
414+
clientSideEncryption: '>=6.1.0',
415+
416+
// The Range Explicit Encryption tests require MongoDB server 7.0+ for QE v2.
417+
// The tests must not run against a standalone.
418+
//
419+
// `range` is not supported on 8.0+ servers.
420+
mongodb: '>=8.0.0',
421+
topology: '!single'
422+
}
423+
};
424+
425+
const getKmsProviders = (): { local: { key: string } } => {
426+
const result = EJSON.parse(process.env.CSFLE_KMS_PROVIDERS || '{}') as unknown as {
427+
local: { key: string };
428+
};
429+
430+
return { local: result.local };
431+
};
432+
433+
let clientEncryption: ClientEncryption;
434+
let keyId;
435+
let keyVaultClient;
436+
437+
beforeEach(async function () {
438+
keyVaultClient = this.configuration.newClient();
439+
clientEncryption = new ClientEncryption(keyVaultClient, {
440+
keyVaultNamespace: 'keyvault.datakeys',
441+
kmsProviders: getKmsProviders()
442+
});
443+
444+
keyId = await clientEncryption.createDataKey('local');
445+
446+
447+
});
448+
449+
afterEach(async function () {
450+
await keyVaultClient.close();
451+
});
452+
453+
it('supports a js number for trimFactor', metaData, async function () {
454+
await clientEncryption.encrypt(new BSON.Int32(123), {
455+
keyId,
456+
algorithm: 'Range',
457+
contentionFactor: 0,
458+
rangeOptions: {
459+
min: 0,
460+
max: 1000,
461+
trimFactor: 1,
462+
sparsity: new BSON.Long(1)
463+
}
464+
});
465+
});
466+
467+
it('supports a bigint for sparsity', metaData, async function () {
468+
await clientEncryption.encrypt(new BSON.Int32(123), {
469+
keyId,
470+
algorithm: 'Range',
471+
contentionFactor: 0,
472+
rangeOptions: {
473+
min: 0,
474+
max: 1000,
475+
trimFactor: new BSON.Int32(1),
476+
sparsity: 1n
477+
}
478+
});
479+
});
480+
});

0 commit comments

Comments
 (0)