Skip to content

Commit e7b80ea

Browse files
authored
RUST-1629 Sync testdata updates for csfle (#869)
1 parent abad47a commit e7b80ea

File tree

117 files changed

+1767
-919
lines changed

Some content is hidden

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

117 files changed

+1767
-919
lines changed

etc/update-spec-tests.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,16 @@ curl -sL "https://github.com/mongodb/specifications/archive/$REF.zip" -o "$tmpdi
2828
unzip -q -d "$tmpdir" "$tmpdir/specs.zip"
2929
mkdir -p "src/test/spec/json/$1"
3030
rsync -ah "$tmpdir/specifications-$REF"*"/source/$1/tests/" "src/test/spec/json/$1" --delete
31+
32+
if [ "$1" = "client-side-encryption" ]; then
33+
mkdir -p "src/test/spec/json/testdata/$1/data"
34+
rsync -ah "$tmpdir/specifications-$REF"*"/source/$1/etc/data/" "src/test/spec/json/testdata/$1/data" --delete
35+
mkdir -p "src/test/spec/json/testdata/$1/corpus"
36+
rsync -ah "$tmpdir/specifications-$REF"*"/source/$1/corpus/" "src/test/spec/json/testdata/$1/corpus" --delete
37+
mkdir -p "src/test/spec/json/testdata/$1/external"
38+
rsync -ah "$tmpdir/specifications-$REF"*"/source/$1/external/" "src/test/spec/json/testdata/$1/external" --delete
39+
mkdir -p "src/test/spec/json/testdata/$1/limits"
40+
rsync -ah "$tmpdir/specifications-$REF"*"/source/$1/limits/" "src/test/spec/json/testdata/$1/limits" --delete
41+
fi
42+
3143
rm -rf "$tmpdir"

src/test/csfle.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ async fn external_key_vault() -> Result<()> {
455455
// Setup: initialize db.
456456
let (client, datakeys) = init_client().await?;
457457
datakeys
458-
.insert_one(load_testdata("external-key.json")?, None)
458+
.insert_one(load_testdata("external/external-key.json")?, None)
459459
.await?;
460460

461461
// Setup: test options.
@@ -479,7 +479,7 @@ async fn external_key_vault() -> Result<()> {
479479
LOCAL_KMS.clone(),
480480
)?
481481
.key_vault_client(kv_client.clone())
482-
.schema_map([("db.coll", load_testdata("external-schema.json")?)])
482+
.schema_map([("db.coll", load_testdata("external/external-schema.json")?)])
483483
.extra_options(EXTRA_OPTIONS.clone())
484484
.disable_crypt_shared(*DISABLE_CRYPT_SHARED)
485485
.build()
@@ -562,12 +562,12 @@ async fn bson_size_limits() -> Result<()> {
562562
.create_collection(
563563
"coll",
564564
CreateCollectionOptions::builder()
565-
.validator(doc! { "$jsonSchema": load_testdata("limits-schema.json")? })
565+
.validator(doc! { "$jsonSchema": load_testdata("limits/limits-schema.json")? })
566566
.build(),
567567
)
568568
.await?;
569569
datakeys
570-
.insert_one(load_testdata("limits-key.json")?, None)
570+
.insert_one(load_testdata("limits/limits-key.json")?, None)
571571
.await?;
572572

573573
// Setup: encrypted client.
@@ -597,7 +597,7 @@ async fn bson_size_limits() -> Result<()> {
597597
.await?;
598598

599599
// Test operation 2
600-
let mut doc: Document = load_testdata("limits-doc.json")?;
600+
let mut doc: Document = load_testdata("limits/limits-doc.json")?;
601601
doc.insert("_id", "encryption_exceeds_2mib");
602602
doc.insert("unencrypted", "a".repeat(2_097_152 - 2_000));
603603
coll.insert_one(doc, None).await?;
@@ -631,7 +631,7 @@ async fn bson_size_limits() -> Result<()> {
631631
assert_eq!(2, inserts.len());
632632

633633
// Test operation 4
634-
let mut doc = load_testdata("limits-doc.json")?;
634+
let mut doc = load_testdata("limits/limits-doc.json")?;
635635
doc.insert("_id", "encryption_exceeds_2mib_1");
636636
doc.insert("unencrypted", "a".repeat(2_097_152 - 2_000));
637637
let mut doc2 = doc.clone();
@@ -657,7 +657,7 @@ async fn bson_size_limits() -> Result<()> {
657657
coll.insert_one(doc, None).await?;
658658

659659
// Test operation 6
660-
let mut doc: Document = load_testdata("limits-doc.json")?;
660+
let mut doc: Document = load_testdata("limits/limits-doc.json")?;
661661
doc.insert("_id", "encryption_exceeds_16mib");
662662
doc.insert("unencrypted", "a".repeat(16_777_216 - 2_000));
663663
let result = coll.insert_one(doc, None).await;
@@ -1347,7 +1347,7 @@ async fn bypass_mongocryptd_via_shared_library() -> Result<()> {
13471347
KV_NAMESPACE.clone(),
13481348
LOCAL_KMS.clone(),
13491349
)?
1350-
.schema_map([("db.coll", load_testdata("external-schema.json")?)])
1350+
.schema_map([("db.coll", load_testdata("external/external-schema.json")?)])
13511351
.extra_options(doc! {
13521352
"mongocryptdURI": "mongodb://localhost:27021/db?serverSelectionTimeoutMS=1000",
13531353
"mongocryptdSpawnArgs": ["--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=27021"],
@@ -1394,7 +1394,7 @@ async fn bypass_mongocryptd_via_bypass_spawn() -> Result<()> {
13941394
KV_NAMESPACE.clone(),
13951395
LOCAL_KMS.clone(),
13961396
)?
1397-
.schema_map([("db.coll", load_testdata("external-schema.json")?)])
1397+
.schema_map([("db.coll", load_testdata("external/external-schema.json")?)])
13981398
.extra_options(extra_options)
13991399
.disable_crypt_shared(true)
14001400
.build()
@@ -1617,7 +1617,7 @@ impl DeadlockTestCase {
16171617
.database("keyvault")
16181618
.collection::<Document>("datakeys")
16191619
.insert_one(
1620-
load_testdata("external-key.json")?,
1620+
load_testdata("external/external-key.json")?,
16211621
InsertOneOptions::builder()
16221622
.write_concern(WriteConcern::MAJORITY)
16231623
.build(),
@@ -1628,7 +1628,9 @@ impl DeadlockTestCase {
16281628
.create_collection(
16291629
"coll",
16301630
CreateCollectionOptions::builder()
1631-
.validator(doc! { "$jsonSchema": load_testdata("external-schema.json")? })
1631+
.validator(
1632+
doc! { "$jsonSchema": load_testdata("external/external-schema.json")? },
1633+
)
16321634
.build(),
16331635
)
16341636
.await?;
@@ -2363,8 +2365,8 @@ async fn explicit_encryption_setup() -> Result<Option<ExplicitEncryptionTestData
23632365
return Ok(None);
23642366
}
23652367

2366-
let encrypted_fields = load_testdata("encryptedFields.json")?;
2367-
let key1_document = load_testdata("key1-document.json")?;
2368+
let encrypted_fields = load_testdata("data/encryptedFields.json")?;
2369+
let key1_document = load_testdata("data/keys/key1-document.json")?;
23682370
let key1_id = match key1_document.get("_id").unwrap() {
23692371
Bson::Binary(b) => b.clone(),
23702372
v => return Err(failure!("expected binary _id, got {:?}", v)),
@@ -3130,9 +3132,10 @@ async fn range_explicit_encryption_test(
31303132
let _guard = LOCK.run_exclusively().await;
31313133
let util_client = TestClient::new().await;
31323134

3133-
let encrypted_fields = load_testdata(&format!("range-encryptedFields-{}.json", bson_type))?;
3135+
let encrypted_fields =
3136+
load_testdata(&format!("data/range-encryptedFields-{}.json", bson_type))?;
31343137

3135-
let key1_document = load_testdata("key1-document.json")?;
3138+
let key1_document = load_testdata("data/keys/key1-document.json")?;
31363139
let key1_id = match key1_document.get("_id").unwrap() {
31373140
Bson::Binary(binary) => binary,
31383141
_ => unreachable!(),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,7 @@ Each test listed in the cases below must pass for all supported data types unles
28072807
28082808
Case 1: can decrypt a payload
28092809
`````````````````````````````
2810-
Use ``clientEncryption.encrypt()`` to encrypt the value 6. Ensure the type matches with the type of the encrypted field. For example, if the encrypted field is ``encryptedDoubleNoPrecision`` encrypt the double value 6.0.
2810+
Use ``clientEncryption.encrypt()`` to encrypt the value 6. Ensure the encoded BSON type matches the type of the encrypted field. For example, if the encrypted field is ``encryptedLong`` encrypt the 64-bit BSON long value 6, not the 32-bit BSON int value 6.
28112811

28122812
Store the result in ``insertPayload``.
28132813

@@ -2823,6 +2823,11 @@ Encrypt with the matching ``RangeOpts`` listed in `Test Setup: RangeOpts`_ and t
28232823
28242824
Use ``clientEncryption`` to decrypt ``insertPayload``. Assert the returned value equals 6.
28252825

2826+
.. note::
2827+
2828+
The type returned by ``clientEncryption.decrypt()`` may differ from the input type to ``clientEncryption.encrypt()`` depending on how the driver unmarshals BSON numerics to language native types.
2829+
Example: a driver may unmarshal a BSON long to a numeric type that does not distinguish between int64 and int32.
2830+
28262831
Case 2: can find encrypted range and return the maximum
28272832
```````````````````````````````````````````````````````
28282833
Use ``clientEncryption.encryptExpression()`` to encrypt this query:

src/test/spec/json/client-side-encryption/legacy/bypassedCommand.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
]
7979
},
8080
{
81-
"description": "current op is not bypassed",
81+
"description": "kill op is not bypassed",
8282
"clientOptions": {
8383
"autoEncryptOpts": {
8484
"kmsProviders": {
@@ -90,14 +90,15 @@
9090
{
9191
"name": "runCommand",
9292
"object": "database",
93-
"command_name": "currentOp",
93+
"command_name": "killOp",
9494
"arguments": {
9595
"command": {
96-
"currentOp": 1
96+
"killOp": 1,
97+
"op": 1234
9798
}
9899
},
99100
"result": {
100-
"errorContains": "command not supported for auto encryption: currentOp"
101+
"errorContains": "command not supported for auto encryption: killOp"
101102
}
102103
}
103104
]

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ tests:
2626
command:
2727
ping: 1
2828
command_name: ping
29-
- description: "current op is not bypassed"
29+
- description: "kill op is not bypassed"
3030
clientOptions:
3131
autoEncryptOpts:
3232
kmsProviders:
3333
aws: {} # Credentials filled in from environment.
3434
operations:
3535
- name: runCommand
3636
object: database
37-
command_name: currentOp
37+
command_name: killOp
3838
arguments:
3939
command:
40-
currentOp: 1
40+
killOp: 1
41+
op: 1234
4142
result:
42-
errorContains: "command not supported for auto encryption: currentOp"
43+
errorContains: "command not supported for auto encryption: killOp"

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,44 @@
150150
}
151151
}
152152
],
153-
"ordered": true
153+
"ordered": true,
154+
"encryptionInformation": {
155+
"type": 1,
156+
"schema": {
157+
"default.default": {
158+
"escCollection": "enxcol_.default.esc",
159+
"ecocCollection": "enxcol_.default.ecoc",
160+
"fields": [
161+
{
162+
"keyId": {
163+
"$binary": {
164+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
165+
"subType": "04"
166+
}
167+
},
168+
"path": "encryptedIndexed",
169+
"bsonType": "string",
170+
"queries": {
171+
"queryType": "equality",
172+
"contention": {
173+
"$numberLong": "0"
174+
}
175+
}
176+
},
177+
{
178+
"keyId": {
179+
"$binary": {
180+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
181+
"subType": "04"
182+
}
183+
},
184+
"path": "encryptedUnindexed",
185+
"bsonType": "string"
186+
}
187+
]
188+
}
189+
}
190+
}
154191
},
155192
"command_name": "insert"
156193
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ tests:
4848
documents:
4949
- *doc0_encrypted
5050
ordered: true
51+
encryptionInformation:
52+
type: 1
53+
schema:
54+
"default.default":
55+
# libmongocrypt applies escCollection and ecocCollection to outgoing command.
56+
escCollection: "enxcol_.default.esc"
57+
ecocCollection: "enxcol_.default.ecoc"
58+
<<: *encrypted_fields
5159
command_name: insert
5260
- command_started_event:
5361
command:

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
"type": 1,
177177
"schema": {
178178
"default.default": {
179+
"escCollection": "enxcol_.default.esc",
180+
"ecocCollection": "enxcol_.default.ecoc",
179181
"fields": [
180182
{
181183
"keyId": {
@@ -230,10 +232,13 @@
230232
"limit": 1
231233
}
232234
],
235+
"ordered": true,
233236
"encryptionInformation": {
234237
"type": 1,
235238
"schema": {
236239
"default.default": {
240+
"escCollection": "enxcol_.default.esc",
241+
"ecocCollection": "enxcol_.default.ecoc",
237242
"fields": [
238243
{
239244
"keyId": {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ tests:
6363
encryptionInformation:
6464
type: 1
6565
schema:
66-
"default.default": *encrypted_fields
66+
"default.default":
67+
# libmongocrypt applies escCollection and ecocCollection to outgoing command.
68+
escCollection: "enxcol_.default.esc"
69+
ecocCollection: "enxcol_.default.ecoc"
70+
<<: *encrypted_fields
6771
command_name: insert
6872
- command_started_event:
6973
command:
@@ -82,10 +86,15 @@ tests:
8286
},
8387
"limit": 1
8488
}
89+
ordered: true
8590
encryptionInformation:
8691
type: 1
8792
schema:
88-
"default.default": *encrypted_fields
93+
"default.default":
94+
# libmongocrypt applies escCollection and ecocCollection to outgoing command.
95+
escCollection: "enxcol_.default.esc"
96+
ecocCollection: "enxcol_.default.ecoc"
97+
<<: *encrypted_fields
8998
command_name: delete
9099
outcome:
91100
collection:

src/test/spec/json/client-side-encryption/legacy/fle2v2-EncryptedFields-vs-jsonSchema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@
183183
"type": 1,
184184
"schema": {
185185
"default.default": {
186+
"escCollection": "enxcol_.default.esc",
187+
"ecocCollection": "enxcol_.default.ecoc",
186188
"fields": [
187189
{
188190
"keyId": {
@@ -236,6 +238,8 @@
236238
"type": 1,
237239
"schema": {
238240
"default.default": {
241+
"escCollection": "enxcol_.default.esc",
242+
"ecocCollection": "enxcol_.default.ecoc",
239243
"fields": [
240244
{
241245
"keyId": {

0 commit comments

Comments
 (0)