Skip to content

Commit

Permalink
test(NODE-4224): sync fle2 compact tests (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jun 16, 2022
1 parent 517a31b commit 904252c
Show file tree
Hide file tree
Showing 3 changed files with 322 additions and 1 deletion.
232 changes: 232 additions & 0 deletions test/spec/client-side-encryption/tests/fle2-Compact.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
{
"runOn": [
{
"minServerVersion": "6.0.0",
"topology": [
"replicaset",
"sharded"
]
}
],
"database_name": "default",
"collection_name": "default",
"data": [],
"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"
}
]
},
"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"
}
}
],
"tests": [
{
"description": "Compact works",
"clientOptions": {
"autoEncryptOpts": {
"kmsProviders": {
"local": {
"key": {
"$binary": {
"base64": "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk",
"subType": "00"
}
}
}
}
}
},
"operations": [
{
"name": "runCommand",
"object": "database",
"command_name": "compactStructuredEncryptionData",
"arguments": {
"command": {
"compactStructuredEncryptionData": "default"
}
}
}
],
"expectations": [
{
"command_started_event": {
"command": {
"listCollections": 1,
"filter": {
"name": "default"
}
},
"command_name": "listCollections"
}
},
{
"command_started_event": {
"command": {
"find": "datakeys",
"filter": {
"$or": [
{
"_id": {
"$in": [
{
"$binary": {
"base64": "EjRWeBI0mHYSNBI0VniQEg==",
"subType": "04"
}
},
{
"$binary": {
"base64": "q83vqxI0mHYSNBI0VniQEg==",
"subType": "04"
}
}
]
}
},
{
"keyAltNames": {
"$in": []
}
}
]
},
"$db": "keyvault",
"readConcern": {
"level": "majority"
}
},
"command_name": "find"
}
},
{
"command_started_event": {
"command": {
"compactStructuredEncryptionData": "default",
"compactionTokens": {
"encryptedIndexed": {
"$binary": {
"base64": "noN+05JsuO1oDg59yypIGj45i+eFH6HOTXOPpeZ//Mk=",
"subType": "00"
}
},
"encryptedUnindexed": {
"$binary": {
"base64": "SWO8WEoZ2r2Kx/muQKb7+COizy85nIIUFiHh4K9kcvA=",
"subType": "00"
}
}
}
},
"command_name": "compactStructuredEncryptionData"
}
}
]
},
{
"description": "Compact errors on an unencrypted client",
"operations": [
{
"name": "runCommand",
"object": "database",
"command_name": "compactStructuredEncryptionData",
"arguments": {
"command": {
"compactStructuredEncryptionData": "default"
}
},
"result": {
"errorContains": "'compactStructuredEncryptionData.compactionTokens' is missing"
}
}
]
}
]
}
80 changes: 80 additions & 0 deletions test/spec/client-side-encryption/tests/fle2-Compact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
runOn:
- minServerVersion: "6.0.0"
# FLE 2 Encrypted collections are not supported on standalone.
topology: [ "replicaset", "sharded" ]
database_name: &database_name "default"
collection_name: &collection_name "default"
data: []
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'}]}
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'}} ]
tests:
- description: "Compact works"
clientOptions:
autoEncryptOpts:
kmsProviders:
local: {'key': {'$binary': {'base64': 'Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk', 'subType': '00'}}}
operations:
- name: runCommand
object: database
command_name: compactStructuredEncryptionData
arguments:
command:
compactStructuredEncryptionData: *collection_name
expectations:
- command_started_event:
command:
listCollections: 1
filter:
name: *collection_name
command_name: listCollections
- command_started_event:
command:
find: datakeys
filter: {
"$or": [
{
"_id": {
"$in": [
{'$binary': {'base64': 'EjRWeBI0mHYSNBI0VniQEg==', 'subType': '04'}},
{'$binary': {'base64': 'q83vqxI0mHYSNBI0VniQEg==', 'subType': '04'}}
]
}
},
{
"keyAltNames": {
"$in": []
}
}
]
}
$db: keyvault
readConcern: { level: "majority" }
command_name: find
- command_started_event:
command:
compactStructuredEncryptionData: *collection_name
compactionTokens: {
"encryptedIndexed": {
"$binary": {
"base64": "noN+05JsuO1oDg59yypIGj45i+eFH6HOTXOPpeZ//Mk=",
"subType": "00"
}
},
"encryptedUnindexed": {
"$binary": {
"base64": "SWO8WEoZ2r2Kx/muQKb7+COizy85nIIUFiHh4K9kcvA=",
"subType": "00"
}
}
}
command_name: compactStructuredEncryptionData
- description: "Compact errors on an unencrypted client"
operations:
- name: runCommand
object: database
command_name: compactStructuredEncryptionData
arguments:
command:
compactStructuredEncryptionData: *collection_name
result:
errorContains: "'compactStructuredEncryptionData.compactionTokens' is missing"
11 changes: 10 additions & 1 deletion test/tools/spec-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ function prepareDatabaseForSuite(suite, context) {

const coll = db.collection(context.collectionName);
return setupPromise
.then(() => coll.drop({ writeConcern: { w: 'majority' } }))
.then(() => {
const options = { writeConcern: { w: 'majority' } };
if (suite.encrypted_fields) {
options.encryptedFields = suite.encrypted_fields;
}
return coll.drop(options);
})
.catch(err => {
if (!err.message.match(/ns not found/)) throw err;
})
Expand Down Expand Up @@ -289,6 +295,9 @@ function prepareDatabaseForSuite(suite, context) {
if (suite.json_schema) {
options.validator = { $jsonSchema: suite.json_schema };
}
if (suite.encrypted_fields) {
options.encryptedFields = suite.encrypted_fields;
}

return db.createCollection(context.collectionName, options);
})
Expand Down

0 comments on commit 904252c

Please sign in to comment.