Skip to content

Commit d68e85c

Browse files
Divjot AroraShaneHarvey
Divjot Arora
andauthored
DRIVERS-555 Add spec and prose tests for CSOT (#960)
Co-authored-by: Shane Harvey <[email protected]>
1 parent 5dbdfdb commit d68e85c

File tree

74 files changed

+63102
-11
lines changed

Some content is hidden

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

74 files changed

+63102
-11
lines changed

.github/workflows/json-regenerate-check.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ jobs:
2929
python3 ./source/server-discovery-and-monitoring/tests/errors/generate-error-tests.py
3030
python3 ./source/client-side-encryption/etc/generate-corpus.py ./source/client-side-encryption/corpus
3131
python3 ./source/client-side-encryption/etc/generate-test.py ./source/client-side-encryption/etc/test-templates/*.template ./source/client-side-encryption/tests
32+
python3 ./source/client-side-operations-timeout/etc/generate-basic-tests.py ./source/client-side-operations-timeout/etc/templates ./source/client-side-operations-timeout/tests
3233
cd source && make && git diff --exit-code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
runOn:
2+
- minServerVersion: "4.4"
3+
database_name: &database_name "cse-timeouts-db"
4+
collection_name: &collection_name "cse-timeouts-coll"
5+
6+
data: []
7+
json_schema: {{schema()}}
8+
key_vault_data: [{{key()}}]
9+
10+
tests:
11+
- description: "timeoutMS applied to listCollections to get collection schema"
12+
failPoint:
13+
configureFailPoint: failCommand
14+
mode: { times: 1 }
15+
data:
16+
failCommands: ["listCollections"]
17+
blockConnection: true
18+
blockTimeMS: 60
19+
clientOptions:
20+
autoEncryptOpts:
21+
kmsProviders:
22+
aws: {} # Credentials filled in from environment.
23+
timeoutMS: 50
24+
operations:
25+
- name: insertOne
26+
arguments:
27+
document: &doc0 { _id: 1, encrypted_string: "string0", random: "abc" }
28+
result:
29+
isTimeoutError: true
30+
expectations:
31+
# Auto encryption will request the collection info.
32+
- command_started_event:
33+
command:
34+
listCollections: 1
35+
filter:
36+
name: *collection_name
37+
maxTimeMS: { $$type: ["int", "long"] }
38+
command_name: listCollections
39+
40+
# Test that timeoutMS applies to the sum of all operations done for client-side encryption. This is done by blocking
41+
# listCollections and find for 20ms each and running an insertOne with timeoutMS=50. There should be two
42+
# listCollections commands and one "find" command, so the sum should take more than timeoutMS.
43+
#
44+
# This test does not include command monitoring expectations because the exact command sequence is dependent on the
45+
# amount of time taken by mongocryptd communication. In slow runs, mongocryptd communication can breach the timeout
46+
# and result in the final "find" not being sent.
47+
- description: "remaining timeoutMS applied to find to get keyvault data"
48+
failPoint:
49+
configureFailPoint: failCommand
50+
mode: { times: 3 }
51+
data:
52+
failCommands: ["listCollections", "find"]
53+
blockConnection: true
54+
blockTimeMS: 20
55+
clientOptions:
56+
autoEncryptOpts:
57+
kmsProviders:
58+
aws: {} # Credentials filled in from environment.
59+
timeoutMS: 50
60+
operations:
61+
- name: insertOne
62+
arguments:
63+
document: *doc0
64+
result:
65+
isTimeoutError: true

source/client-side-encryption/tests/README.rst

+28-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ Client Side Encryption Tests
99
Introduction
1010
============
1111

12-
This document describes the format of the driver spec tests included in the JSON
13-
and YAML files included in this directory.
12+
This document describes the format of the driver spec tests included in the
13+
JSON and YAML files included in this directory. The
14+
``timeoutMS.yml``/``timeoutMS.json`` files in this directory contain tests
15+
for the ``timeoutMS`` option and its application to the client-side
16+
encryption feature. Drivers MUST only run these tests after implementing the
17+
`Client Side Operations Timeout
18+
<../client-side-operations-timeout/client-side-operations-timeout.rst>`__
19+
specification.
1420

1521
Additional prose tests, that are not represented in the spec tests, are described
1622
and MUST be implemented by all drivers.
@@ -32,7 +38,8 @@ The spec tests format is an extension of `transactions spec tests <https://githu
3238

3339
- Addition of `$$type` to command_started_event and outcome.
3440

35-
The semantics of `$$type` is that any actual value matching the BSON type indicated by the BSON type string is considered a match.
41+
The semantics of `$$type` is that any actual value matching one of the types indicated by either a BSON type string
42+
or an array of BSON type strings is considered a match.
3643

3744
For example, the following matches a command_started_event for an insert of a document where `random` must be of type ``binData``::
3845

@@ -44,6 +51,16 @@ For example, the following matches a command_started_event for an insert of a do
4451
ordered: true
4552
command_name: insert
4653

54+
The following matches a command_started_event for an insert of a document where ``random`` must be of type
55+
``binData`` or ``string``::
56+
57+
- command_started_event:
58+
command:
59+
insert: *collection_name
60+
documents:
61+
- { random: { $$type: ["binData", "string"] } }
62+
ordered: true
63+
command_name: insert
4764

4865
The values of `$$type` correspond to `these documented string representations of BSON types <https://www.mongodb.com/docs/manual/reference/bson-types/>`_.
4966

@@ -73,6 +90,10 @@ Each YAML file has the following keys:
7390

7491
- ``skipReason``: |txn|
7592

93+
- ``useMultipleMongoses``: |txn|
94+
95+
- ``failPoint``: |txn|
96+
7697
- ``clientOptions``: Optional, parameters to pass to MongoClient().
7798

7899
- ``autoEncryptOpts``: Optional
@@ -112,7 +133,10 @@ Each YAML file has the following keys:
112133

113134
- ``arguments``: |txn|
114135

115-
- ``result``: |txn|
136+
- ``result``: Same as the Transactions spec test format with one addition: if the operation is expected to return
137+
an error, the ``result`` document may contain an ``isTimeoutError`` boolean field. If ``true``, the test runner
138+
MUST assert that the error represents a timeout due to the use of the ``timeoutMS`` option. If ``false``, the
139+
test runner MUST assert that the error does not represent a timeout.
116140

117141
- ``expectations``: |txn|
118142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.4"
5+
}
6+
],
7+
"database_name": "cse-timeouts-db",
8+
"collection_name": "cse-timeouts-coll",
9+
"data": [],
10+
"json_schema": {
11+
"properties": {
12+
"encrypted_w_altname": {
13+
"encrypt": {
14+
"keyId": "/altname",
15+
"bsonType": "string",
16+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
17+
}
18+
},
19+
"encrypted_string": {
20+
"encrypt": {
21+
"keyId": [
22+
{
23+
"$binary": {
24+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
25+
"subType": "04"
26+
}
27+
}
28+
],
29+
"bsonType": "string",
30+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
31+
}
32+
},
33+
"random": {
34+
"encrypt": {
35+
"keyId": [
36+
{
37+
"$binary": {
38+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
39+
"subType": "04"
40+
}
41+
}
42+
],
43+
"bsonType": "string",
44+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
45+
}
46+
},
47+
"encrypted_string_equivalent": {
48+
"encrypt": {
49+
"keyId": [
50+
{
51+
"$binary": {
52+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
53+
"subType": "04"
54+
}
55+
}
56+
],
57+
"bsonType": "string",
58+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
59+
}
60+
}
61+
},
62+
"bsonType": "object"
63+
},
64+
"key_vault_data": [
65+
{
66+
"status": 1,
67+
"_id": {
68+
"$binary": {
69+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
70+
"subType": "04"
71+
}
72+
},
73+
"masterKey": {
74+
"provider": "aws",
75+
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
76+
"region": "us-east-1"
77+
},
78+
"updateDate": {
79+
"$date": {
80+
"$numberLong": "1552949630483"
81+
}
82+
},
83+
"keyMaterial": {
84+
"$binary": {
85+
"base64": "AQICAHhQNmWG2CzOm1dq3kWLM+iDUZhEqnhJwH9wZVpuZ94A8gEqnsxXlR51T5EbEVezUqqKAAAAwjCBvwYJKoZIhvcNAQcGoIGxMIGuAgEAMIGoBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDHa4jo6yp0Z18KgbUgIBEIB74sKxWtV8/YHje5lv5THTl0HIbhSwM6EqRlmBiFFatmEWaeMk4tO4xBX65eq670I5TWPSLMzpp8ncGHMmvHqRajNBnmFtbYxN3E3/WjxmdbOOe+OXpnGJPcGsftc7cB2shRfA4lICPnE26+oVNXT6p0Lo20nY5XC7jyCO",
86+
"subType": "00"
87+
}
88+
},
89+
"creationDate": {
90+
"$date": {
91+
"$numberLong": "1552949630483"
92+
}
93+
},
94+
"keyAltNames": [
95+
"altname",
96+
"another_altname"
97+
]
98+
}
99+
],
100+
"tests": [
101+
{
102+
"description": "timeoutMS applied to listCollections to get collection schema",
103+
"failPoint": {
104+
"configureFailPoint": "failCommand",
105+
"mode": {
106+
"times": 1
107+
},
108+
"data": {
109+
"failCommands": [
110+
"listCollections"
111+
],
112+
"blockConnection": true,
113+
"blockTimeMS": 60
114+
}
115+
},
116+
"clientOptions": {
117+
"autoEncryptOpts": {
118+
"kmsProviders": {
119+
"aws": {}
120+
}
121+
},
122+
"timeoutMS": 50
123+
},
124+
"operations": [
125+
{
126+
"name": "insertOne",
127+
"arguments": {
128+
"document": {
129+
"_id": 1,
130+
"encrypted_string": "string0",
131+
"random": "abc"
132+
}
133+
},
134+
"result": {
135+
"isTimeoutError": true
136+
}
137+
}
138+
],
139+
"expectations": [
140+
{
141+
"command_started_event": {
142+
"command": {
143+
"listCollections": 1,
144+
"filter": {
145+
"name": "cse-timeouts-coll"
146+
},
147+
"maxTimeMS": {
148+
"$$type": [
149+
"int",
150+
"long"
151+
]
152+
}
153+
},
154+
"command_name": "listCollections"
155+
}
156+
}
157+
]
158+
},
159+
{
160+
"description": "remaining timeoutMS applied to find to get keyvault data",
161+
"failPoint": {
162+
"configureFailPoint": "failCommand",
163+
"mode": {
164+
"times": 3
165+
},
166+
"data": {
167+
"failCommands": [
168+
"listCollections",
169+
"find"
170+
],
171+
"blockConnection": true,
172+
"blockTimeMS": 20
173+
}
174+
},
175+
"clientOptions": {
176+
"autoEncryptOpts": {
177+
"kmsProviders": {
178+
"aws": {}
179+
}
180+
},
181+
"timeoutMS": 50
182+
},
183+
"operations": [
184+
{
185+
"name": "insertOne",
186+
"arguments": {
187+
"document": {
188+
"_id": 1,
189+
"encrypted_string": "string0",
190+
"random": "abc"
191+
}
192+
},
193+
"result": {
194+
"isTimeoutError": true
195+
}
196+
}
197+
]
198+
}
199+
]
200+
}

0 commit comments

Comments
 (0)