diff options
author | Yuhong Zhang <yuhong.zhang@mongodb.com> | 2022-09-01 19:16:42 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-01 20:38:13 +0000 |
commit | 8834bd03c22a3a0d21227def26d7a474dafaabc8 (patch) | |
tree | c6ea3dc392e8575782d9210745ab923b5474cb8a /jstests/disk/validate_bson_inconsistency.js | |
parent | d2979f3ee500ed4dfd5f67fe2c9412f44c9ceb62 (diff) | |
download | mongo-8834bd03c22a3a0d21227def26d7a474dafaabc8.tar.gz |
SERVER-67879 Check encrypted BSON value's structural consistency
Diffstat (limited to 'jstests/disk/validate_bson_inconsistency.js')
-rw-r--r-- | jstests/disk/validate_bson_inconsistency.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/jstests/disk/validate_bson_inconsistency.js b/jstests/disk/validate_bson_inconsistency.js index 663354b93c4..b7b03062a28 100644 --- a/jstests/disk/validate_bson_inconsistency.js +++ b/jstests/disk/validate_bson_inconsistency.js @@ -278,4 +278,46 @@ resetDbpath(dbpath); MongoRunner.stopMongod(mongod, null, {skipValidation: true}); })(); + +(function validateDocumentsInvalidEncryptedBSONValue() { + jsTestLog("Validate documents with invalid Encrypted BSON Value"); + + let mongod = startMongodOnExistingPath(dbpath); + let db = mongod.getDB(baseName); + const collName = collNamePrefix + count++; + + db.createCollection(collName); + let testColl = db[collName]; + // A valid Encrypted BSON document with the type byte, 16-byte key uuid, original BSON type + // byte, and an empty cipher text. + const properFLE = HexData(6, "060102030405060708091011121314151610"); + // Invalid Encrypted BSON Value subtype 3. + const improperFLE1 = HexData(6, "030102030405060708091011121314151610"); + // Invalid original BSON type MinKey. + const improperFLE2 = HexData(6, "0601020304050607080910111213141516ff"); + // Empty Encrypted BSON Value. + const improperFLE3 = HexData(6, ""); + // Short Encrypted BSON Value. + const improperFLE4 = HexData(6, "0601"); + + assert.commandWorked(testColl.insertMany([ + {"fle": properFLE}, + {"fle": improperFLE1}, + {"fle": improperFLE2}, + {"fle": improperFLE3}, + {"fle": improperFLE4}, + ])); + + let res = assert.commandWorked(testColl.validate()); + assert(res.valid, tojson(res)); + assert.eq(res.nNonCompliantDocuments, 4); + assert.eq(res.warnings.length, 1); + + res = assert.commandWorked(testColl.validate({checkBSONConformance: true})); + assert(res.valid, tojson(res)); + assert.eq(res.nNonCompliantDocuments, 4); + assert.eq(res.warnings.length, 1); + + MongoRunner.stopMongod(mongod, null, {skipValidation: true}); +})(); })(); |