Skip to content

Commit b9d141e

Browse files
add back install dir
1 parent b26c328 commit b9d141e

File tree

80 files changed

+1229
-153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1229
-153
lines changed

.evergreen/install-mongodb-client-encryption.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env bash
2-
set +o xtrace # Do not write AWS credentials to stderr
2+
set +o xtrace
33

44
# Initial checks for running these tests
55
if [ -z ${PROJECT_DIRECTORY+omitted} ]; then echo "PROJECT_DIRECTORY is unset" && exit 1; fi
@@ -9,20 +9,19 @@ source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
99
set -o xtrace # Write all commands first to stderr
1010
set -o errexit # Exit the script with error if any of the commands fail
1111

12-
rm -rf $INSTALL_DIR
12+
rm -rf mongodb-client-encryption
1313
git clone https://github.com/mongodb-js/mongodb-client-encryption.git
1414
pushd mongodb-client-encryption
1515

1616
if [ -n "${LIBMONGOCRYPT_VERSION}" ]; then
1717
# nightly tests test with `latest` to test against the laster FLE build.
18-
npm run install:libmongocrypt -- --libVersion $LIBMONGOCRYPT_VERSION
18+
npm run install:libmongocrypt -- --build --libVersion $LIBMONGOCRYPT_VERSION
1919
else
2020
# otherwise use whatever is specified in the package.json.
2121
npm run install:libmongocrypt
2222
fi
2323

2424
echo "finished installing libmongocrypt"
25-
BINDINGS_DIR=$(pwd)
2625

2726
popd
2827

src/client-side-encryption/client_encryption.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import type {
55
MongoCryptOptions
66
} from 'mongodb-client-encryption';
77

8-
import { type Binary, deserialize, type Document, type Long, serialize, type UUID } from '../bson';
8+
import {
9+
type Binary,
10+
deserialize,
11+
type Document,
12+
type Int32,
13+
type Long,
14+
serialize,
15+
type UUID
16+
} from '../bson';
917
import { type AnyBulkWriteOperation, type BulkWriteResult } from '../bulk/common';
1018
import { type ProxyOptions } from '../cmap/connection';
1119
import { type Collection } from '../collection';
@@ -948,12 +956,13 @@ export interface ClientEncryptionRewrapManyDataKeyResult {
948956
/**
949957
* @public
950958
* RangeOptions specifies index options for a Queryable Encryption field supporting "rangePreview" queries.
951-
* min, max, sparsity, and range must match the values set in the encryptedFields of the destination collection.
959+
* min, max, sparsity, trimFactor and range must match the values set in the encryptedFields of the destination collection.
952960
* For double and decimal128, min/max/precision must all be set, or all be unset.
953961
*/
954962
export interface RangeOptions {
955963
min?: any;
956964
max?: any;
957-
sparsity: Long;
965+
sparsity?: Long;
966+
trimFactor?: Int32;
958967
precision?: number;
959968
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import { type Binary, EJSON, Int32, Long } from 'bson';
2+
import { expect } from 'chai';
3+
4+
/* eslint-disable @typescript-eslint/no-restricted-imports */
5+
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption';
6+
import { installNodeDNSWorkaroundHooks } from '../../tools/runner/hooks/configuration';
7+
8+
const metaData: MongoDBMetadataUI = {
9+
requires: {
10+
clientSideEncryption: '>=6.1.0',
11+
12+
// The Range Explicit Encryption tests require MongoDB server 7.0+ for QE v2.
13+
// The tests must not run against a standalone.
14+
//
15+
// `range` is not supported on 8.0+ servers.
16+
mongodb: '>=8.0.0',
17+
topology: '!single'
18+
}
19+
};
20+
21+
const getKmsProviders = (): { local: { key: string } } => {
22+
const result = EJSON.parse(process.env.CSFLE_KMS_PROVIDERS || '{}') as unknown as {
23+
local: { key: string };
24+
};
25+
26+
return { local: result.local };
27+
};
28+
29+
describe('Range Explicit Encryption Defaults', function () {
30+
installNodeDNSWorkaroundHooks();
31+
32+
let clientEncryption: ClientEncryption;
33+
let keyId;
34+
let keyVaultClient;
35+
let payload_defaults: Binary;
36+
37+
beforeEach(async function () {
38+
// Create a MongoClient named `keyVaultClient`.
39+
keyVaultClient = this.configuration.newClient();
40+
41+
// Create a ClientEncryption object named `clientEncryption` with these options:
42+
// ```typescript
43+
// class ClientEncryptionOpts {
44+
// keyVaultClient: keyVaultClient,
45+
// keyVaultNamespace: "keyvault.datakeys",
46+
// kmsProviders: { "local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" } },
47+
// }
48+
// ```
49+
clientEncryption = new ClientEncryption(keyVaultClient, {
50+
keyVaultNamespace: 'keyvault.datakeys',
51+
kmsProviders: getKmsProviders()
52+
});
53+
54+
// Create a key with `clientEncryption.createDataKey`. Store the returned key ID in a variable named `keyId`.
55+
keyId = await clientEncryption.createDataKey('local');
56+
57+
// Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
58+
// ```typescript
59+
// class EncryptOpts {
60+
// keyId : keyId,
61+
// algorithm: "Range",
62+
// contentionFactor: 0,
63+
// rangeOpts: RangeOpts {
64+
// min: 0,
65+
// max: 1000
66+
// }
67+
// }
68+
// ```
69+
// Store the result in a variable named `payload_defaults`.
70+
payload_defaults = await clientEncryption.encrypt(new Int32(123), {
71+
keyId,
72+
algorithm: 'Range',
73+
contentionFactor: 0,
74+
rangeOptions: {
75+
min: 0,
76+
max: 1000
77+
}
78+
});
79+
});
80+
81+
afterEach(async function () {
82+
await keyVaultClient.close();
83+
});
84+
85+
it('Case 1: Uses libmongocrypt defaults', metaData, async function () {
86+
// Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
87+
// ```typescript
88+
// class EncryptOpts {
89+
// keyId : keyId,
90+
// algorithm: "Range",
91+
// contentionFactor: 0,
92+
// rangeOpts: RangeOpts {
93+
// min: 0,
94+
// max: 1000,
95+
// sparsity: 2,
96+
// trimFactor: 6
97+
// }
98+
// }
99+
// ```
100+
const encrypted = await clientEncryption.encrypt(new Int32(123), {
101+
keyId: keyId,
102+
algorithm: 'Range',
103+
contentionFactor: 0,
104+
rangeOptions: {
105+
min: 0,
106+
max: 1000,
107+
sparsity: new Long(2),
108+
trimFactor: new Int32(6)
109+
}
110+
});
111+
112+
// Assert the returned payload size equals the size of `payload_defaults`.
113+
expect(encrypted.length()).to.equal(payload_defaults.length());
114+
});
115+
116+
it('Case 2: can find encrypted range and return the maximum', metaData, async function () {
117+
// Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
118+
// ```typescript
119+
// class EncryptOpts {
120+
// keyId : keyId,
121+
// algorithm: "Range",
122+
// contentionFactor: 0,
123+
// rangeOpts: RangeOpts {
124+
// min: 0,
125+
// max: 1000,
126+
// trimFactor: 0
127+
// }
128+
// }
129+
// ```
130+
const encrypted = await clientEncryption.encrypt(new Int32(123), {
131+
keyId: keyId,
132+
algorithm: 'Range',
133+
contentionFactor: 0,
134+
rangeOptions: {
135+
min: 0,
136+
max: 1000,
137+
trimFactor: new Int32(0)
138+
}
139+
});
140+
141+
// Assert the returned payload size is greater than the size of `payload_defaults`.
142+
expect(encrypted.length()).to.be.greaterThan(payload_defaults.length());
143+
});
144+
});

test/spec/client-side-encryption/tests/legacy/fle2v2-Compact.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"runOn": [
33
{
4-
"minServerVersion": "8.0.0",
4+
"minServerVersion": "7.0.0",
55
"topology": [
66
"replicaset",
77
"sharded",
@@ -130,6 +130,9 @@
130130
"command": {
131131
"compactStructuredEncryptionData": "default"
132132
}
133+
},
134+
"result": {
135+
"ok": 1
133136
}
134137
}
135138
],

test/spec/client-side-encryption/tests/legacy/fle2v2-Compact.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# Requires libmongocrypt 1.8.0.
1+
# Requires libmongocrypt 1.8.0. libmongocrypt 1.10.0 has a bug (MONGOCRYPT-699) that may cause this test to fail on server version 7.
22
runOn:
3-
# TODO(NODE-6128): lower server version to 7.0.0
4-
- minServerVersion: "8.0.0"
3+
- minServerVersion: "7.0.0"
54
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
65
# FLE 2 Encrypted collections are not supported on standalone.
76
topology: [ "replicaset", "sharded", "load-balanced" ]
@@ -23,6 +22,8 @@ tests:
2322
arguments:
2423
command:
2524
compactStructuredEncryptionData: *collection_name
25+
result:
26+
ok: 1
2627
expectations:
2728
- command_started_event:
2829
command:
@@ -80,4 +81,4 @@ tests:
8081
command:
8182
compactStructuredEncryptionData: *collection_name
8283
result:
83-
errorContains: "'compactStructuredEncryptionData.compactionTokens' is missing"
84+
errorContains: "'compactStructuredEncryptionData.compactionTokens' is missing"

0 commit comments

Comments
 (0)