Skip to content

Commit 904252c

Browse files
authored
test(NODE-4224): sync fle2 compact tests (#3292)
1 parent 517a31b commit 904252c

File tree

3 files changed

+322
-1
lines changed

3 files changed

+322
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "6.0.0",
5+
"topology": [
6+
"replicaset",
7+
"sharded"
8+
]
9+
}
10+
],
11+
"database_name": "default",
12+
"collection_name": "default",
13+
"data": [],
14+
"encrypted_fields": {
15+
"escCollection": "enxcol_.default.esc",
16+
"eccCollection": "enxcol_.default.ecc",
17+
"ecocCollection": "enxcol_.default.ecoc",
18+
"fields": [
19+
{
20+
"keyId": {
21+
"$binary": {
22+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
23+
"subType": "04"
24+
}
25+
},
26+
"path": "encryptedIndexed",
27+
"bsonType": "string",
28+
"queries": {
29+
"queryType": "equality",
30+
"contention": {
31+
"$numberLong": "0"
32+
}
33+
}
34+
},
35+
{
36+
"keyId": {
37+
"$binary": {
38+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
39+
"subType": "04"
40+
}
41+
},
42+
"path": "encryptedUnindexed",
43+
"bsonType": "string"
44+
}
45+
]
46+
},
47+
"key_vault_data": [
48+
{
49+
"_id": {
50+
"$binary": {
51+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
52+
"subType": "04"
53+
}
54+
},
55+
"keyMaterial": {
56+
"$binary": {
57+
"base64": "sHe0kz57YW7v8g9VP9sf/+K1ex4JqKc5rf/URX3n3p8XdZ6+15uXPaSayC6adWbNxkFskuMCOifDoTT+rkqMtFkDclOy884RuGGtUysq3X7zkAWYTKi8QAfKkajvVbZl2y23UqgVasdQu3OVBQCrH/xY00nNAs/52e958nVjBuzQkSb1T8pKJAyjZsHJ60+FtnfafDZSTAIBJYn7UWBCwQ==",
58+
"subType": "00"
59+
}
60+
},
61+
"creationDate": {
62+
"$date": {
63+
"$numberLong": "1648914851981"
64+
}
65+
},
66+
"updateDate": {
67+
"$date": {
68+
"$numberLong": "1648914851981"
69+
}
70+
},
71+
"status": {
72+
"$numberInt": "0"
73+
},
74+
"masterKey": {
75+
"provider": "local"
76+
}
77+
},
78+
{
79+
"_id": {
80+
"$binary": {
81+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
82+
"subType": "04"
83+
}
84+
},
85+
"keyMaterial": {
86+
"$binary": {
87+
"base64": "HBk9BWihXExNDvTp1lUxOuxuZK2Pe2ZdVdlsxPEBkiO1bS4mG5NNDsQ7zVxJAH8BtdOYp72Ku4Y3nwc0BUpIKsvAKX4eYXtlhv5zUQxWdeNFhg9qK7qb8nqhnnLeT0f25jFSqzWJoT379hfwDeu0bebJHr35QrJ8myZdPMTEDYF08QYQ48ShRBli0S+QzBHHAQiM2iJNr4svg2WR8JSeWQ==",
88+
"subType": "00"
89+
}
90+
},
91+
"creationDate": {
92+
"$date": {
93+
"$numberLong": "1648914851981"
94+
}
95+
},
96+
"updateDate": {
97+
"$date": {
98+
"$numberLong": "1648914851981"
99+
}
100+
},
101+
"status": {
102+
"$numberInt": "0"
103+
},
104+
"masterKey": {
105+
"provider": "local"
106+
}
107+
}
108+
],
109+
"tests": [
110+
{
111+
"description": "Compact works",
112+
"clientOptions": {
113+
"autoEncryptOpts": {
114+
"kmsProviders": {
115+
"local": {
116+
"key": {
117+
"$binary": {
118+
"base64": "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk",
119+
"subType": "00"
120+
}
121+
}
122+
}
123+
}
124+
}
125+
},
126+
"operations": [
127+
{
128+
"name": "runCommand",
129+
"object": "database",
130+
"command_name": "compactStructuredEncryptionData",
131+
"arguments": {
132+
"command": {
133+
"compactStructuredEncryptionData": "default"
134+
}
135+
}
136+
}
137+
],
138+
"expectations": [
139+
{
140+
"command_started_event": {
141+
"command": {
142+
"listCollections": 1,
143+
"filter": {
144+
"name": "default"
145+
}
146+
},
147+
"command_name": "listCollections"
148+
}
149+
},
150+
{
151+
"command_started_event": {
152+
"command": {
153+
"find": "datakeys",
154+
"filter": {
155+
"$or": [
156+
{
157+
"_id": {
158+
"$in": [
159+
{
160+
"$binary": {
161+
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
162+
"subType": "04"
163+
}
164+
},
165+
{
166+
"$binary": {
167+
"base64": "q83vqxI0mHYSNBI0VniQEg==",
168+
"subType": "04"
169+
}
170+
}
171+
]
172+
}
173+
},
174+
{
175+
"keyAltNames": {
176+
"$in": []
177+
}
178+
}
179+
]
180+
},
181+
"$db": "keyvault",
182+
"readConcern": {
183+
"level": "majority"
184+
}
185+
},
186+
"command_name": "find"
187+
}
188+
},
189+
{
190+
"command_started_event": {
191+
"command": {
192+
"compactStructuredEncryptionData": "default",
193+
"compactionTokens": {
194+
"encryptedIndexed": {
195+
"$binary": {
196+
"base64": "noN+05JsuO1oDg59yypIGj45i+eFH6HOTXOPpeZ//Mk=",
197+
"subType": "00"
198+
}
199+
},
200+
"encryptedUnindexed": {
201+
"$binary": {
202+
"base64": "SWO8WEoZ2r2Kx/muQKb7+COizy85nIIUFiHh4K9kcvA=",
203+
"subType": "00"
204+
}
205+
}
206+
}
207+
},
208+
"command_name": "compactStructuredEncryptionData"
209+
}
210+
}
211+
]
212+
},
213+
{
214+
"description": "Compact errors on an unencrypted client",
215+
"operations": [
216+
{
217+
"name": "runCommand",
218+
"object": "database",
219+
"command_name": "compactStructuredEncryptionData",
220+
"arguments": {
221+
"command": {
222+
"compactStructuredEncryptionData": "default"
223+
}
224+
},
225+
"result": {
226+
"errorContains": "'compactStructuredEncryptionData.compactionTokens' is missing"
227+
}
228+
}
229+
]
230+
}
231+
]
232+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
runOn:
2+
- minServerVersion: "6.0.0"
3+
# FLE 2 Encrypted collections are not supported on standalone.
4+
topology: [ "replicaset", "sharded" ]
5+
database_name: &database_name "default"
6+
collection_name: &collection_name "default"
7+
data: []
8+
encrypted_fields: &encrypted_fields {'escCollection': 'enxcol_.default.esc', 'eccCollection': 'enxcol_.default.ecc', 'ecocCollection': 'enxcol_.default.ecoc', 'fields': [{'keyId': {'$binary': {'base64': 'EjRWeBI0mHYSNBI0VniQEg==', 'subType': '04'}}, 'path': 'encryptedIndexed', 'bsonType': 'string', 'queries': {'queryType': 'equality', 'contention': {'$numberLong': '0'}}}, {'keyId': {'$binary': {'base64': 'q83vqxI0mHYSNBI0VniQEg==', 'subType': '04'}}, 'path': 'encryptedUnindexed', 'bsonType': 'string'}]}
9+
key_vault_data: [ {'_id': {'$binary': {'base64': 'EjRWeBI0mHYSNBI0VniQEg==', 'subType': '04'}}, 'keyMaterial': {'$binary': {'base64': 'sHe0kz57YW7v8g9VP9sf/+K1ex4JqKc5rf/URX3n3p8XdZ6+15uXPaSayC6adWbNxkFskuMCOifDoTT+rkqMtFkDclOy884RuGGtUysq3X7zkAWYTKi8QAfKkajvVbZl2y23UqgVasdQu3OVBQCrH/xY00nNAs/52e958nVjBuzQkSb1T8pKJAyjZsHJ60+FtnfafDZSTAIBJYn7UWBCwQ==', 'subType': '00'}}, 'creationDate': {'$date': {'$numberLong': '1648914851981'}}, 'updateDate': {'$date': {'$numberLong': '1648914851981'}}, 'status': {'$numberInt': '0'}, 'masterKey': {'provider': 'local'}}, {'_id': {'$binary': {'base64': 'q83vqxI0mHYSNBI0VniQEg==', 'subType': '04'}}, 'keyMaterial': {'$binary': {'base64': 'HBk9BWihXExNDvTp1lUxOuxuZK2Pe2ZdVdlsxPEBkiO1bS4mG5NNDsQ7zVxJAH8BtdOYp72Ku4Y3nwc0BUpIKsvAKX4eYXtlhv5zUQxWdeNFhg9qK7qb8nqhnnLeT0f25jFSqzWJoT379hfwDeu0bebJHr35QrJ8myZdPMTEDYF08QYQ48ShRBli0S+QzBHHAQiM2iJNr4svg2WR8JSeWQ==', 'subType': '00'}}, 'creationDate': {'$date': {'$numberLong': '1648914851981'}}, 'updateDate': {'$date': {'$numberLong': '1648914851981'}}, 'status': {'$numberInt': '0'}, 'masterKey': {'provider': 'local'}} ]
10+
tests:
11+
- description: "Compact works"
12+
clientOptions:
13+
autoEncryptOpts:
14+
kmsProviders:
15+
local: {'key': {'$binary': {'base64': 'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', 'subType': '00'}}}
16+
operations:
17+
- name: runCommand
18+
object: database
19+
command_name: compactStructuredEncryptionData
20+
arguments:
21+
command:
22+
compactStructuredEncryptionData: *collection_name
23+
expectations:
24+
- command_started_event:
25+
command:
26+
listCollections: 1
27+
filter:
28+
name: *collection_name
29+
command_name: listCollections
30+
- command_started_event:
31+
command:
32+
find: datakeys
33+
filter: {
34+
"$or": [
35+
{
36+
"_id": {
37+
"$in": [
38+
{'$binary': {'base64': 'EjRWeBI0mHYSNBI0VniQEg==', 'subType': '04'}},
39+
{'$binary': {'base64': 'q83vqxI0mHYSNBI0VniQEg==', 'subType': '04'}}
40+
]
41+
}
42+
},
43+
{
44+
"keyAltNames": {
45+
"$in": []
46+
}
47+
}
48+
]
49+
}
50+
$db: keyvault
51+
readConcern: { level: "majority" }
52+
command_name: find
53+
- command_started_event:
54+
command:
55+
compactStructuredEncryptionData: *collection_name
56+
compactionTokens: {
57+
"encryptedIndexed": {
58+
"$binary": {
59+
"base64": "noN+05JsuO1oDg59yypIGj45i+eFH6HOTXOPpeZ//Mk=",
60+
"subType": "00"
61+
}
62+
},
63+
"encryptedUnindexed": {
64+
"$binary": {
65+
"base64": "SWO8WEoZ2r2Kx/muQKb7+COizy85nIIUFiHh4K9kcvA=",
66+
"subType": "00"
67+
}
68+
}
69+
}
70+
command_name: compactStructuredEncryptionData
71+
- description: "Compact errors on an unencrypted client"
72+
operations:
73+
- name: runCommand
74+
object: database
75+
command_name: compactStructuredEncryptionData
76+
arguments:
77+
command:
78+
compactStructuredEncryptionData: *collection_name
79+
result:
80+
errorContains: "'compactStructuredEncryptionData.compactionTokens' is missing"

test/tools/spec-runner/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,13 @@ function prepareDatabaseForSuite(suite, context) {
261261

262262
const coll = db.collection(context.collectionName);
263263
return setupPromise
264-
.then(() => coll.drop({ writeConcern: { w: 'majority' } }))
264+
.then(() => {
265+
const options = { writeConcern: { w: 'majority' } };
266+
if (suite.encrypted_fields) {
267+
options.encryptedFields = suite.encrypted_fields;
268+
}
269+
return coll.drop(options);
270+
})
265271
.catch(err => {
266272
if (!err.message.match(/ns not found/)) throw err;
267273
})
@@ -289,6 +295,9 @@ function prepareDatabaseForSuite(suite, context) {
289295
if (suite.json_schema) {
290296
options.validator = { $jsonSchema: suite.json_schema };
291297
}
298+
if (suite.encrypted_fields) {
299+
options.encryptedFields = suite.encrypted_fields;
300+
}
292301

293302
return db.createCollection(context.collectionName, options);
294303
})

0 commit comments

Comments
 (0)