diff options
Diffstat (limited to 'jstests')
-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}); +})(); })(); |