diff options
author | Eric Cox <eric.cox@mongodb.com> | 2022-06-22 16:58:08 +0000 |
---|---|---|
committer | Eric Cox <eric.cox@mongodb.com> | 2022-06-22 16:58:08 +0000 |
commit | dce8e9938f02f7cc18744050442c64ca69091558 (patch) | |
tree | 630fdee303fd190f8a3e75779910ba9e45c90b55 /src/mongo/db/fle_crud_test.cpp | |
parent | 44385b89a690f1feda55d8e888a08f33eab0a020 (diff) | |
download | mongo-dce8e9938f02f7cc18744050442c64ca69091558.tar.gz |
Revert "Revert "Merge branch 'v6.0' of github.com:10gen/mongo into v6.0""
This reverts commit 44385b89a690f1feda55d8e888a08f33eab0a020.
Diffstat (limited to 'src/mongo/db/fle_crud_test.cpp')
-rw-r--r-- | src/mongo/db/fle_crud_test.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/src/mongo/db/fle_crud_test.cpp b/src/mongo/db/fle_crud_test.cpp index 527dd5bca11..0a5d7dfc37c 100644 --- a/src/mongo/db/fle_crud_test.cpp +++ b/src/mongo/db/fle_crud_test.cpp @@ -27,6 +27,7 @@ * it in the license file. */ +#include "mongo/base/error_codes.h" #include "mongo/platform/basic.h" #include <algorithm> @@ -153,8 +154,12 @@ protected: void assertDocumentCounts(uint64_t edc, uint64_t esc, uint64_t ecc, uint64_t ecoc); - void doSingleInsert(int id, BSONElement element); - void doSingleInsert(int id, BSONObj obj); + void testValidateEncryptedFieldInfo(BSONObj obj, bool bypassValidation); + + void testValidateTags(BSONObj obj); + + void doSingleInsert(int id, BSONElement element, bool bypassDocumentValidation = false); + void doSingleInsert(int id, BSONObj obj, bool bypassDocumentValidation = false); void doSingleInsertWithContention( int id, BSONElement element, int64_t cm, uint64_t cf, EncryptedFieldConfig efc); @@ -406,7 +411,7 @@ void FleCrudTest::doSingleWideInsert(int id, uint64_t fieldCount, ValueGenerator auto efc = getTestEncryptedFieldConfig(); - uassertStatusOK(processInsert(_queryImpl.get(), _edcNs, serverPayload, efc, 0, result)); + uassertStatusOK(processInsert(_queryImpl.get(), _edcNs, serverPayload, efc, 0, result, false)); } @@ -451,7 +456,16 @@ std::vector<char> generateSinglePlaceholder(BSONElement value, int64_t cm = 0) { return v; } -void FleCrudTest::doSingleInsert(int id, BSONElement element) { +void FleCrudTest::testValidateEncryptedFieldInfo(BSONObj obj, bool bypassValidation) { + auto efc = getTestEncryptedFieldConfig(); + EDCServerCollection::validateEncryptedFieldInfo(obj, efc, bypassValidation); +} + +void FleCrudTest::testValidateTags(BSONObj obj) { + FLEClientCrypto::validateTagsArray(obj); +} + +void FleCrudTest::doSingleInsert(int id, BSONElement element, bool bypassDocumentValidation) { auto buf = generateSinglePlaceholder(element); BSONObjBuilder builder; builder.append("_id", id); @@ -467,10 +481,10 @@ void FleCrudTest::doSingleInsert(int id, BSONElement element) { auto efc = getTestEncryptedFieldConfig(); - uassertStatusOK(processInsert(_queryImpl.get(), _edcNs, serverPayload, efc, 0, result)); + uassertStatusOK(processInsert(_queryImpl.get(), _edcNs, serverPayload, efc, 0, result, false)); } -void FleCrudTest::doSingleInsert(int id, BSONObj obj) { +void FleCrudTest::doSingleInsert(int id, BSONObj obj, bool bypassDocumentValidation) { doSingleInsert(id, obj.firstElement()); } @@ -490,7 +504,7 @@ void FleCrudTest::doSingleInsertWithContention( auto serverPayload = EDCServerCollection::getEncryptedFieldInfo(result); - uassertStatusOK(processInsert(_queryImpl.get(), _edcNs, serverPayload, efc, 0, result)); + uassertStatusOK(processInsert(_queryImpl.get(), _edcNs, serverPayload, efc, 0, result, false)); } void FleCrudTest::doSingleInsertWithContention( @@ -890,7 +904,6 @@ TEST_F(FleCrudTest, UpdateOneSameValue) { << "secret")); } - // Update one document with replacement TEST_F(FleCrudTest, UpdateOneReplace) { @@ -956,7 +969,16 @@ TEST_F(FleCrudTest, SetSafeContent) { builder.append("$set", BSON(kSafeContent << "foo")); auto result = builder.obj(); - ASSERT_THROWS_CODE(doSingleUpdateWithUpdateDoc(1, result), DBException, 6371507); + ASSERT_THROWS_CODE(doSingleUpdateWithUpdateDoc(1, result), DBException, 6666200); +} + +// Test that EDCServerCollection::validateEncryptedFieldInfo checks that the +// safeContent cannot be present in the BSON obj. +TEST_F(FleCrudTest, testValidateEncryptedFieldConfig) { + testValidateEncryptedFieldInfo(BSON(kSafeContent << "secret"), true); + ASSERT_THROWS_CODE(testValidateEncryptedFieldInfo(BSON(kSafeContent << "secret"), false), + DBException, + 6666200); } // Update one document via findAndModify @@ -1038,6 +1060,11 @@ TEST_F(FleCrudTest, FindAndModify_RenameSafeContent) { ASSERT_THROWS_CODE(doFindAndModify(req), DBException, 6371506); } +TEST_F(FleCrudTest, validateTagsTest) { + testValidateTags(BSON(kSafeContent << BSON_ARRAY(123))); + ASSERT_THROWS_CODE(testValidateTags(BSON(kSafeContent << "foo")), DBException, 6371507); +} + // Mess with __safeContent__ and ensure the update errors TEST_F(FleCrudTest, FindAndModify_SetSafeContent) { doSingleInsert(1, @@ -1056,8 +1083,7 @@ TEST_F(FleCrudTest, FindAndModify_SetSafeContent) { req.setUpdate( write_ops::UpdateModification(result, write_ops::UpdateModification::ClassicTag{}, false)); - - ASSERT_THROWS_CODE(doFindAndModify(req), DBException, 6371507); + ASSERT_THROWS_CODE(doFindAndModify(req), DBException, 6666200); } TEST_F(FleTagsTest, InsertOne) { @@ -1199,7 +1225,7 @@ TEST_F(FleTagsTest, MemoryLimit) { doSingleInsert(10, doc); // readTags returns 11 tags which does exceed memory limit. - ASSERT_THROWS_CODE(readTags(doc), DBException, 6401800); + ASSERT_THROWS_CODE(readTags(doc), DBException, ErrorCodes::FLEMaxTagLimitExceeded); doSingleDelete(5); |