Skip to content

Commit 06eda2d

Browse files
authored
RUST-1926 Support Range Indexes as GA (#1184)
1 parent 66967e6 commit 06eda2d

File tree

79 files changed

+1223
-148
lines changed

Some content is hidden

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

79 files changed

+1223
-148
lines changed

src/action/csfle/encrypt.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,14 @@ pub struct RangeOptions {
131131
/// The maximum value. This option must be set if `precision` is set.
132132
pub max: Option<Bson>,
133133

134-
/// The trim factor.
135-
pub trim_factor: i32,
134+
/// May be used to tune performance. When omitted, a default value is used.
135+
pub trim_factor: Option<i32>,
136136

137-
/// The sparsity.
138-
pub sparsity: i64,
137+
/// May be used to tune performance. When omitted, a default value is used.
138+
pub sparsity: Option<i64>,
139139

140-
/// The precision. This value must only be set for Double and Decimal128 fields.
140+
/// Determines the number of significant digits after the decimal point. This value must only
141+
/// be set for Double and Decimal128 fields.
141142
pub precision: Option<i32>,
142143
}
143144

src/test/csfle.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,6 +3436,69 @@ async fn bind(addr: &str) -> Result<TcpListener> {
34363436
Ok(TcpListener::bind(addr.parse::<std::net::SocketAddr>()?).await?)
34373437
}
34383438

3439+
// Prose test 23. Range explicit encryption applies defaults
3440+
#[tokio::test]
3441+
async fn range_explicit_encryption_defaults() -> Result<()> {
3442+
let name = "range_explicit_encryption_defaults";
3443+
if !check_env(name, false) {
3444+
return Ok(());
3445+
}
3446+
3447+
dbg!(mongocrypt::version());
3448+
3449+
// Setup
3450+
let key_vault_client = Client::test_builder().build().await;
3451+
let client_encryption = ClientEncryption::new(
3452+
key_vault_client.into_client(),
3453+
KV_NAMESPACE.clone(),
3454+
vec![LOCAL_KMS.clone()],
3455+
)?;
3456+
let key_id = client_encryption
3457+
.create_data_key(LocalMasterKey::builder().build())
3458+
.await?;
3459+
let payload_defaults = client_encryption
3460+
.encrypt(123, key_id.clone(), Algorithm::Range)
3461+
.contention_factor(0)
3462+
.range_options(
3463+
RangeOptions::builder()
3464+
.min(Bson::from(0))
3465+
.max(Bson::from(1000))
3466+
.build(),
3467+
)
3468+
.await?;
3469+
3470+
// Case 1: Uses libmongocrypt defaults
3471+
let payload = client_encryption
3472+
.encrypt(123, key_id.clone(), Algorithm::Range)
3473+
.contention_factor(0)
3474+
.range_options(
3475+
RangeOptions::builder()
3476+
.min(Bson::from(0))
3477+
.max(Bson::from(1000))
3478+
.sparsity(2)
3479+
.trim_factor(6)
3480+
.build(),
3481+
)
3482+
.await?;
3483+
assert_eq!(payload_defaults.bytes.len(), payload.bytes.len());
3484+
3485+
// Case 2: Accepts trimFactor 0
3486+
let payload = client_encryption
3487+
.encrypt(123, key_id.clone(), Algorithm::Range)
3488+
.contention_factor(0)
3489+
.range_options(
3490+
RangeOptions::builder()
3491+
.min(Bson::from(0))
3492+
.max(Bson::from(1000))
3493+
.trim_factor(0)
3494+
.build(),
3495+
)
3496+
.await?;
3497+
assert!(payload.bytes.len() > payload_defaults.bytes.len());
3498+
3499+
Ok(())
3500+
}
3501+
34393502
// FLE 2.0 Documentation Example
34403503
#[tokio::test]
34413504
async fn fle2_example() -> Result<()> {

src/test/spec/json/client-side-encryption/README.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2815,11 +2815,12 @@ This test is continuation of the case 1 and provides a way to complete inserting
28152815

28162816
### 22. Range Explicit Encryption
28172817

2818-
The Range Explicit Encryption tests require MongoDB server 8.0+.
2818+
The Range Explicit Encryption tests require MongoDB server 8.0.0-rc14+ for SERVER-91889 and libmongocrypt containing
2819+
MONGOCRYPT-705.
28192820

28202821
> [!NOTE]
28212822
> MongoDB Server 8.0 introduced a backwards breaking change to the Queryable Encryption (QE) range protocol: QE Range V2
2822-
> libmongocrypt 1.10.0 is required to use the QE Range V2.
2823+
> libmongocrypt 1.11.0 is required to use the QE Range V2.
28232824

28242825
> [!NOTE]
28252826
> MongoDB Server 7.0 introduced a backwards breaking change to the Queryable Encryption (QE) protocol: QEv2.
@@ -3210,3 +3211,88 @@ class EncryptOpts {
32103211
```
32113212
32123213
Assert that an error was raised.
3214+
3215+
### 23. Range Explicit Encryption applies defaults
3216+
3217+
This test requires libmongocrypt with changes in
3218+
[14ccd9ce](https://github.com/mongodb/libmongocrypt/commit/14ccd9ce8a030158aec07f63e8139d34b95d88e6)
3219+
([MONGOCRYPT-698](https://jira.mongodb.org/browse/MONGOCRYPT-698)).
3220+
3221+
#### Test Setup
3222+
3223+
Create a MongoClient named `keyVaultClient`.
3224+
3225+
Create a ClientEncryption object named `clientEncryption` with these options:
3226+
3227+
```typescript
3228+
class ClientEncryptionOpts {
3229+
keyVaultClient: keyVaultClient,
3230+
keyVaultNamespace: "keyvault.datakeys",
3231+
kmsProviders: { "local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" } },
3232+
}
3233+
```
3234+
3235+
Create a key with `clientEncryption.createDataKey`. Store the returned key ID in a variable named `keyId`.
3236+
3237+
Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
3238+
3239+
```typescript
3240+
class EncryptOpts {
3241+
keyId : keyId,
3242+
algorithm: "Range",
3243+
contentionFactor: 0,
3244+
rangeOpts: RangeOpts {
3245+
min: 0,
3246+
max: 1000
3247+
}
3248+
}
3249+
```
3250+
3251+
Store the result in a variable named `payload_defaults`.
3252+
3253+
#### Case 1: Uses libmongocrypt defaults
3254+
3255+
Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
3256+
3257+
```typescript
3258+
class EncryptOpts {
3259+
keyId : keyId,
3260+
algorithm: "Range",
3261+
contentionFactor: 0,
3262+
rangeOpts: RangeOpts {
3263+
min: 0,
3264+
max: 1000,
3265+
sparsity: 2,
3266+
trimFactor: 6
3267+
}
3268+
}
3269+
```
3270+
3271+
Assert the returned payload size equals the size of `payload_defaults`.
3272+
3273+
> [!NOTE]
3274+
> Do not compare the payload contents. The payloads include random data. The `trimFactor` and `sparsity` directly affect
3275+
> the payload size.
3276+
3277+
#### Case 2: Accepts `trimFactor` 0
3278+
3279+
Call `clientEncryption.encrypt` to encrypt the int32 value `123` with these options:
3280+
3281+
```typescript
3282+
class EncryptOpts {
3283+
keyId : keyId,
3284+
algorithm: "Range",
3285+
contentionFactor: 0,
3286+
rangeOpts: RangeOpts {
3287+
min: 0,
3288+
max: 1000,
3289+
trimFactor: 0
3290+
}
3291+
}
3292+
```
3293+
3294+
Assert the returned payload size is greater than the size of `payload_defaults`.
3295+
3296+
> [!NOTE]
3297+
> Do not compare the payload contents. The payloads include random data. The `trimFactor` and `sparsity` directly affect
3298+
> the payload size.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@
130130
"command": {
131131
"compactStructuredEncryptionData": "default"
132132
}
133+
},
134+
"result": {
135+
"ok": 1
133136
}
134137
}
135138
],

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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:
33
- minServerVersion: "7.0.0"
44
# Skip QEv2 (also referred to as FLE2v2) tests on Serverless. Unskip once Serverless enables the QEv2 protocol.
@@ -22,6 +22,8 @@ tests:
2222
arguments:
2323
command:
2424
compactStructuredEncryptionData: *collection_name
25+
result:
26+
ok: 1
2527
expectations:
2628
- command_started_event:
2729
command:

0 commit comments

Comments
 (0)