diff options
author | Pawel Terlecki <pawel.terlecki@mongodb.com> | 2019-03-28 17:05:59 -0400 |
---|---|---|
committer | Pawel Terlecki <pawel.terlecki@mongodb.com> | 2019-04-12 20:12:32 -0400 |
commit | 008e0e0abcdcdae60a3fee23fb0a17a7c3b0be0d (patch) | |
tree | 0ab29c6db414803c23222396ea96b827b9df9d54 /src/mongo/db/matcher/expression_parser_test.cpp | |
parent | a6e3a3b544b874455ad8a98dbc12bfee5098ea25 (diff) | |
download | mongo-008e0e0abcdcdae60a3fee23fb0a17a7c3b0be0d.tar.gz |
SERVER-39492 Allow array of BSON types in encrypt.bsonType specification
Changed the IDL definition of EncryptionInfo.bsonType to use a custom type based on
MatcherTypeSet. Since it is a pretty generic type we could move it to
basic_types.idl.
Changed InternalSchemaBinDataEncryptedTypeExpression to use
MatcherTypeSet as well, rather than a single type. Parsing logic of
MatcherTypeSet allowed for a concise code.
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_parser_test.cpp | 90 |
1 files changed, 72 insertions, 18 deletions
diff --git a/src/mongo/db/matcher/expression_parser_test.cpp b/src/mongo/db/matcher/expression_parser_test.cpp index 0b9de433bc6..983ea94d755 100644 --- a/src/mongo/db/matcher/expression_parser_test.cpp +++ b/src/mongo/db/matcher/expression_parser_test.cpp @@ -583,7 +583,24 @@ TEST(InternalBinDataSubTypeMatchExpressionTest, InvalidNumericalSubTypeDoesNotPa ASSERT_NOT_OK(statusWith2.getStatus()); } -TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeMatches) { +TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeMatchesSingleTypeAlias) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + auto query = BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" + << "string")); + auto expr = uassertStatusOK(MatchExpressionParser::parse(query, expCtx)); + + FleBlobHeader blob; + blob.fleBlobSubtype = FleBlobSubtype::Deterministic; + memset(blob.keyUUID, 0, sizeof(blob.keyUUID)); + blob.originalBsonType = BSONType::String; + + BSONObj matchingDoc = BSON("a" << BSONBinData(reinterpret_cast<const void*>(&blob), + sizeof(FleBlobHeader), + BinDataType::Encrypt)); + ASSERT_TRUE(expr->matchesBSON(matchingDoc)); +} + +TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeMatchesSingleType) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto query = BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << BSONType::String)); auto expr = uassertStatusOK(MatchExpressionParser::parse(query, expCtx)); @@ -599,7 +616,24 @@ TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeMatches) { ASSERT_TRUE(expr->matchesBSON(matchingDoc)); } -TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeDoesNotMatch) { +TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeMatchesOneOfTypesInArray) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + auto query = BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" + << BSON_ARRAY(BSONType::Date << BSONType::String))); + auto expr = uassertStatusOK(MatchExpressionParser::parse(query, expCtx)); + + FleBlobHeader blob; + blob.fleBlobSubtype = FleBlobSubtype::Deterministic; + memset(blob.keyUUID, 0, sizeof(blob.keyUUID)); + blob.originalBsonType = BSONType::String; + + BSONObj matchingDoc = BSON("a" << BSONBinData(reinterpret_cast<const void*>(&blob), + sizeof(FleBlobHeader), + BinDataType::Encrypt)); + ASSERT_TRUE(expr->matchesBSON(matchingDoc)); +} + +TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeDoesNotMatchSingleType) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); auto query = BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << BSONType::String)); auto expr = uassertStatusOK(MatchExpressionParser::parse(query, expCtx)); @@ -615,39 +649,59 @@ TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeDoesNotMatch) { ASSERT_FALSE(expr->matchesBSON(notMatchingDoc)); } -TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, NonNumericalArgumentDoesNotParse) { +TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, BsonTypeDoesNotMatchTypeArray) { + boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); + auto query = BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" + << BSON_ARRAY(BSONType::Date << BSONType::Bool))); + auto expr = uassertStatusOK(MatchExpressionParser::parse(query, expCtx)); + + FleBlobHeader blob; + blob.fleBlobSubtype = FleBlobSubtype::Deterministic; + memset(blob.keyUUID, 0, sizeof(blob.keyUUID)); + blob.originalBsonType = BSONType::NumberInt; + + BSONObj notMatchingDoc = BSON("a" << BSONBinData(reinterpret_cast<const void*>(&blob), + sizeof(FleBlobHeader), + BinDataType::Encrypt)); + ASSERT_FALSE(expr->matchesBSON(notMatchingDoc)); +} + +TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, InvalidArgumentDoesNotParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); ASSERT_EQ(MatchExpressionParser::parse(BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << "bar")), expCtx) .getStatus(), - ErrorCodes::FailedToParse); + ErrorCodes::BadValue); ASSERT_EQ(MatchExpressionParser::parse(BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << "0")), expCtx) .getStatus(), - ErrorCodes::FailedToParse); + ErrorCodes::BadValue); } TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, InvalidNumericalArgumentDoesNotParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - ASSERT_EQ(MatchExpressionParser::parse( - BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << 0.21)), expCtx) - .getStatus(), - ErrorCodes::FailedToParse); - ASSERT_EQ(MatchExpressionParser::parse( - BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << 13.3)), expCtx) - .getStatus(), - ErrorCodes::FailedToParse); + ASSERT_EQ( + MatchExpressionParser::parse( + BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << BSON_ARRAY(0.21))), expCtx) + .getStatus(), + ErrorCodes::BadValue); + ASSERT_EQ( + MatchExpressionParser::parse( + BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" << BSON_ARRAY(13.3))), expCtx) + .getStatus(), + ErrorCodes::BadValue); } TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, NonBsonTypeArgumentDoesNotParse) { boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest()); - ASSERT_EQ(MatchExpressionParser::parse(BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" - << (BSONType::JSTypeMax + 1))), - expCtx) - .getStatus(), - ErrorCodes::FailedToParse); + ASSERT_EQ( + MatchExpressionParser::parse(BSON("a" << BSON("$_internalSchemaBinDataEncryptedType" + << BSON_ARRAY(BSONType::JSTypeMax + 1))), + expCtx) + .getStatus(), + ErrorCodes::BadValue); } TEST(InternalSchemaBinDataEncryptedTypeExpressionTest, IntentToEncryptFleBlobDoesNotMatch) { |