diff options
Diffstat (limited to 'src/mongo/db/matcher/expression_parser_leaf_test.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_parser_leaf_test.cpp | 1134 |
1 files changed, 444 insertions, 690 deletions
diff --git a/src/mongo/db/matcher/expression_parser_leaf_test.cpp b/src/mongo/db/matcher/expression_parser_leaf_test.cpp index 7181c8dea59..17c6efc8b4f 100644 --- a/src/mongo/db/matcher/expression_parser_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_parser_leaf_test.cpp @@ -33,10 +33,11 @@ #include "mongo/db/matcher/expression.h" #include "mongo/db/matcher/expression_leaf.h" #include "mongo/db/matcher/expression_parser.h" -#include "mongo/db/matcher/extensions_callback_disallow_extensions.h" +#include "mongo/db/matcher/extensions_callback_noop.h" #include "mongo/db/pipeline/expression_context_for_test.h" #include "mongo/db/query/collation/collator_interface_mock.h" #include "mongo/platform/decimal128.h" +#include "mongo/unittest/death_test.h" #include "mongo/unittest/unittest.h" namespace mongo { @@ -48,8 +49,7 @@ TEST(MatchExpressionParserLeafTest, NullCollation) { BSONObj query = BSON("x" << "string"); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -61,8 +61,7 @@ TEST(MatchExpressionParserLeafTest, Collation) { BSONObj query = BSON("x" << "string"); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -79,8 +78,11 @@ TEST(MatchExpressionParserLeafTest, ConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); @@ -101,21 +103,30 @@ TEST(MatchExpressionParserLeafTest, ConstantExprFailsWithMissingVariable) { BSONObj query = BSON("x" << BSON("$expr" << "$$userVar")); - ASSERT_THROWS_CODE(auto sw = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx), - AssertionException, - 17276); + ASSERT_THROWS_CODE( + auto sw = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr), + AssertionException, + 17276); } -TEST(MatchExpressionParserLeafTest, ConstantExprFailsWithMissingExpressionContext) { +DEATH_TEST(MatchExpressionParserLeafTest, + ConstantExprFailsWithMissingExpressionContext, + "Invariant failure (allowedFeatures & AllowedFeatures::kExpr) == 0u") { boost::intrusive_ptr<ExpressionContextForTest> nullExpCtx; const CollatorInterface* collator = nullptr; BSONObj query = BSON("x" << BSON("$expr" << "$$userVar")); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, nullExpCtx); + auto result = MatchExpressionParser::parse(query, + collator, + nullExpCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_NOT_OK(result.getStatus()); } @@ -123,8 +134,7 @@ TEST(MatchExpressionParserLeafTest, ConstantExprFailsWithMissingExpressionContex TEST(MatchExpressionParserLeafTest, SimpleEQ2) { BSONObj query = BSON("x" << BSON("$eq" << 2)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); @@ -135,8 +145,7 @@ TEST(MatchExpressionParserLeafTest, SimpleEQ2) { TEST(MatchExpressionParserLeafTest, SimpleEQUndefined) { BSONObj query = BSON("x" << BSON("$eq" << BSONUndefined)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -144,8 +153,7 @@ TEST(MatchExpressionParserLeafTest, EQNullCollation) { BSONObj query = BSON("x" << BSON("$eq" << "string")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -157,8 +165,7 @@ TEST(MatchExpressionParserLeafTest, EQCollation) { BSONObj query = BSON("x" << BSON("$eq" << "string")); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -175,8 +182,11 @@ TEST(MatchExpressionParserLeafTest, EQConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); @@ -193,8 +203,7 @@ TEST(MatchExpressionParserLeafTest, EQConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleGT1) { BSONObj query = BSON("x" << BSON("$gt" << 2)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 2))); @@ -205,8 +214,7 @@ TEST(MatchExpressionParserLeafTest, GTNullCollation) { BSONObj query = BSON("x" << BSON("$gt" << "abc")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::GT, result.getValue()->matchType()); GTMatchExpression* match = static_cast<GTMatchExpression*>(result.getValue().get()); @@ -218,8 +226,7 @@ TEST(MatchExpressionParserLeafTest, GTCollation) { BSONObj query = BSON("x" << BSON("$gt" << "abc")); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::GT, result.getValue()->matchType()); GTMatchExpression* match = static_cast<GTMatchExpression*>(result.getValue().get()); @@ -236,8 +243,11 @@ TEST(MatchExpressionParserLeafTest, GTConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::GT, result.getValue()->matchType()); @@ -254,8 +264,7 @@ TEST(MatchExpressionParserLeafTest, GTConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleLT1) { BSONObj query = BSON("x" << BSON("$lt" << 2)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); @@ -267,8 +276,7 @@ TEST(MatchExpressionParserLeafTest, LTNullCollation) { BSONObj query = BSON("x" << BSON("$lt" << "abc")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::LT, result.getValue()->matchType()); LTMatchExpression* match = static_cast<LTMatchExpression*>(result.getValue().get()); @@ -280,8 +288,7 @@ TEST(MatchExpressionParserLeafTest, LTCollation) { BSONObj query = BSON("x" << BSON("$lt" << "abc")); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::LT, result.getValue()->matchType()); LTMatchExpression* match = static_cast<LTMatchExpression*>(result.getValue().get()); @@ -298,8 +305,11 @@ TEST(MatchExpressionParserLeafTest, LTConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::LT, result.getValue()->matchType()); @@ -316,8 +326,7 @@ TEST(MatchExpressionParserLeafTest, LTConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleGTE1) { BSONObj query = BSON("x" << BSON("$gte" << 2)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); @@ -329,8 +338,7 @@ TEST(MatchExpressionParserLeafTest, GTENullCollation) { BSONObj query = BSON("x" << BSON("$gte" << "abc")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::GTE, result.getValue()->matchType()); GTEMatchExpression* match = static_cast<GTEMatchExpression*>(result.getValue().get()); @@ -342,8 +350,7 @@ TEST(MatchExpressionParserLeafTest, GTECollation) { BSONObj query = BSON("x" << BSON("$gte" << "abc")); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::GTE, result.getValue()->matchType()); GTEMatchExpression* match = static_cast<GTEMatchExpression*>(result.getValue().get()); @@ -360,8 +367,11 @@ TEST(MatchExpressionParserLeafTest, GTEConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::GTE, result.getValue()->matchType()); @@ -380,8 +390,7 @@ TEST(MatchExpressionParserLeafTest, GTEConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleLTE1) { BSONObj query = BSON("x" << BSON("$lte" << 2)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); @@ -393,8 +402,7 @@ TEST(MatchExpressionParserLeafTest, LTENullCollation) { BSONObj query = BSON("x" << BSON("$lte" << "abc")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::LTE, result.getValue()->matchType()); LTEMatchExpression* match = static_cast<LTEMatchExpression*>(result.getValue().get()); @@ -406,8 +414,7 @@ TEST(MatchExpressionParserLeafTest, LTECollation) { BSONObj query = BSON("x" << BSON("$lte" << "abc")); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kReverseString); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::LTE, result.getValue()->matchType()); LTEMatchExpression* match = static_cast<LTEMatchExpression*>(result.getValue().get()); @@ -424,8 +431,11 @@ TEST(MatchExpressionParserLeafTest, LTEConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::LTE, result.getValue()->matchType()); @@ -444,8 +454,7 @@ TEST(MatchExpressionParserLeafTest, LTEConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleNE1) { BSONObj query = BSON("x" << BSON("$ne" << 2)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); @@ -457,8 +466,7 @@ TEST(MatchExpressionParserLeafTest, NENullCollation) { BSONObj query = BSON("x" << BSON("$ne" << "string")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType()); MatchExpression* child = result.getValue()->getChild(0); @@ -472,8 +480,7 @@ TEST(MatchExpressionParserLeafTest, NECollation) { BSONObj query = BSON("x" << BSON("$ne" << "string")); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType()); MatchExpression* child = result.getValue()->getChild(0); @@ -492,8 +499,11 @@ TEST(MatchExpressionParserLeafTest, NEConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType()); @@ -510,36 +520,34 @@ TEST(MatchExpressionParserLeafTest, NEConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleModBad1) { BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); query = BSON("x" << BSON("$mod" << BSON_ARRAY(3))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2 << 4))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$mod" << BSON_ARRAY("q" << 2))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$mod" << 3)); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$mod" << BSON("a" << 1 << "b" << 2))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, SimpleMod1) { BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(3 << 2))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 5))); @@ -550,8 +558,7 @@ TEST(MatchExpressionParserLeafTest, SimpleMod1) { TEST(MatchExpressionParserLeafTest, SimpleModNotNumber) { BSONObj query = BSON("x" << BSON("$mod" << BSON_ARRAY(2 << "r"))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 2))); @@ -571,8 +578,11 @@ TEST(MatchExpressionParserLeafTest, ModConstantExprFails) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(BSON_ARRAY(10 << 2))); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue); } @@ -581,8 +591,7 @@ TEST(MatchExpressionParserLeafTest, IdCollation) { BSONObj query = BSON("$id" << "string"); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -593,8 +602,7 @@ TEST(MatchExpressionParserLeafTest, IdNullCollation) { BSONObj query = BSON("$id" << "string"); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -611,8 +619,11 @@ TEST(MatchExpressionParserLeafTest, IdConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); @@ -622,8 +633,7 @@ TEST(MatchExpressionParserLeafTest, RefCollation) { BSONObj query = BSON("$ref" << "coll"); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -640,8 +650,11 @@ TEST(MatchExpressionParserLeafTest, RefConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(std::string("colName"))); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); @@ -651,8 +664,7 @@ TEST(MatchExpressionParserLeafTest, DbCollation) { BSONObj query = BSON("$db" << "db"); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); EqualityMatchExpression* match = static_cast<EqualityMatchExpression*>(result.getValue().get()); @@ -669,8 +681,11 @@ TEST(MatchExpressionParserLeafTest, DbConstantExpr) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(std::string("dbName"))); - auto result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), collator, expCtx); + auto result = MatchExpressionParser::parse(query, + collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::EQ, result.getValue()->matchType()); @@ -679,8 +694,7 @@ TEST(MatchExpressionParserLeafTest, DbConstantExpr) { TEST(MatchExpressionParserLeafTest, SimpleIN1) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(2 << 3))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 1))); @@ -691,8 +705,7 @@ TEST(MatchExpressionParserLeafTest, SimpleIN1) { TEST(MatchExpressionParserLeafTest, INNullCollation) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY("string"))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::MATCH_IN, result.getValue()->matchType()); InMatchExpression* match = static_cast<InMatchExpression*>(result.getValue().get()); @@ -702,8 +715,7 @@ TEST(MatchExpressionParserLeafTest, INNullCollation) { TEST(MatchExpressionParserLeafTest, INCollation) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY("string"))); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::MATCH_IN, result.getValue()->matchType()); InMatchExpression* match = static_cast<InMatchExpression*>(result.getValue().get()); @@ -720,8 +732,12 @@ TEST(MatchExpressionParserLeafTest, INConstantExprFails) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(BSON_ARRAY(1 << 2))); - StatusWithMatchExpression result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx); + StatusWithMatchExpression result = + MatchExpressionParser::parse(query, + &collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue); @@ -731,8 +747,11 @@ TEST(MatchExpressionParserLeafTest, INConstantExprFails) { varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx); + result = MatchExpressionParser::parse(query, + &collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue); } @@ -746,8 +765,7 @@ TEST(MatchExpressionParserLeafTest, INSingleDBRef) { << "$db" << "db")))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); OID oidx = OID::gen(); @@ -829,8 +847,7 @@ TEST(MatchExpressionParserLeafTest, INMultipleDBRef) { << "$db" << "db")))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); OID oidx = OID::gen(); @@ -971,8 +988,7 @@ TEST(MatchExpressionParserLeafTest, INDBRefWithOptionalField1) { << "foo" << 12345)))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); OID oidx = OID::gen(); @@ -1007,23 +1023,22 @@ TEST(MatchExpressionParserLeafTest, INInvalidDBRefs) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$ref" << "coll")))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); + result = MatchExpressionParser::parse(query, collator); // second field is not $id query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$ref" << "coll" << "$foo" << 1)))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); OID oid = OID::gen(); // missing $ref field query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$id" << oid << "foo" << 3)))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); // missing $id and $ref field @@ -1031,39 +1046,35 @@ TEST(MatchExpressionParserLeafTest, INInvalidDBRefs) { << "test" << "foo" << 3)))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, INExpressionDocument) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$foo" << 1)))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, INNotArray) { BSONObj query = BSON("x" << BSON("$in" << 5)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, INUndefined) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSONUndefined))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, INNotElemMatch) { BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$elemMatch" << 1)))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -1075,8 +1086,7 @@ TEST(MatchExpressionParserLeafTest, INRegexTooLong) { operand.appendArray("$in", inArray.obj()); BSONObj query = BSON("x" << operand.obj()); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -1084,8 +1094,7 @@ TEST(MatchExpressionParserLeafTest, INRegexTooLong2) { string tooLargePattern(50 * 1000, 'z'); BSONObj query = BSON("x" << BSON("$in" << BSON_ARRAY(BSON("$regex" << tooLargePattern)))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -1099,8 +1108,7 @@ TEST(MatchExpressionParserLeafTest, INRegexStuff) { BSONObj query = BSON("a" << operand.obj()); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); BSONObj matchFirst = BSON("a" @@ -1126,8 +1134,7 @@ TEST(MatchExpressionParserLeafTest, INRegexStuff) { TEST(MatchExpressionParserLeafTest, SimpleNIN1) { BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY(2 << 3))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 1))); @@ -1138,16 +1145,14 @@ TEST(MatchExpressionParserLeafTest, SimpleNIN1) { TEST(MatchExpressionParserLeafTest, NINNotArray) { BSONObj query = BSON("x" << BSON("$nin" << 5)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, NINNullCollation) { BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY("string"))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType()); MatchExpression* child = result.getValue()->getChild(0); @@ -1159,8 +1164,7 @@ TEST(MatchExpressionParserLeafTest, NINNullCollation) { TEST(MatchExpressionParserLeafTest, NINCollation) { BSONObj query = BSON("x" << BSON("$nin" << BSON_ARRAY("string"))); CollatorInterfaceMock collator(CollatorInterfaceMock::MockType::kAlwaysEqual); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), &collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, &collator); ASSERT_OK(result.getStatus()); ASSERT_EQUALS(MatchExpression::NOT, result.getValue()->matchType()); MatchExpression* child = result.getValue()->getChild(0); @@ -1179,8 +1183,12 @@ TEST(MatchExpressionParserLeafTest, NINConstantExprFails) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(BSON_ARRAY(1 << 2))); - StatusWithMatchExpression result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx); + StatusWithMatchExpression result = + MatchExpressionParser::parse(query, + &collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue); @@ -1190,8 +1198,11 @@ TEST(MatchExpressionParserLeafTest, NINConstantExprFails) { varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(123)); - result = MatchExpressionParser::parse( - query, ExtensionsCallbackDisallowExtensions(), &collator, expCtx); + result = MatchExpressionParser::parse(query, + &collator, + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr); ASSERT_NOT_OK(result.getStatus()); ASSERT_EQ(result.getStatus().code(), ErrorCodes::BadValue); } @@ -1201,8 +1212,7 @@ TEST(MatchExpressionParserLeafTest, Regex1) { b.appendRegex("x", "abc", "i"); BSONObj query = b.obj(); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" @@ -1219,8 +1229,7 @@ TEST(MatchExpressionParserLeafTest, Regex2) { << "$options" << "i")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" @@ -1237,8 +1246,7 @@ TEST(MatchExpressionParserLeafTest, Regex3) { << "$regex" << "abc")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" @@ -1256,27 +1264,26 @@ TEST(MatchExpressionParserLeafTest, RegexBad) { << "$optionas" << "i")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); // $regex does not with numbers query = BSON("x" << BSON("$regex" << 123)); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$regex" << BSON_ARRAY("abc"))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$optionas" << "i")); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); query = BSON("x" << BSON("$options" << "i")); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -1284,8 +1291,7 @@ TEST(MatchExpressionParserLeafTest, RegexEmbeddedNULByte) { BSONObj query = BSON("x" << BSON("$regex" << "^a\\x00b")); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); const auto value = "a\0b"_sd; @@ -1305,8 +1311,7 @@ TEST(MatchExpressionParserLeafTest, RegexWithConstantExprFails) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(std::string("i"))); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); @@ -1318,7 +1323,7 @@ TEST(MatchExpressionParserLeafTest, RegexWithConstantExprFails) { varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(std::string("abc"))); - result = MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -1327,8 +1332,7 @@ TEST(MatchExpressionParserLeafTest, ExistsYes1) { b.appendBool("$exists", true); BSONObj query = BSON("x" << b.obj()); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" @@ -1342,8 +1346,7 @@ TEST(MatchExpressionParserLeafTest, ExistsNO1) { b.appendBool("$exists", false); BSONObj query = BSON("x" << b.obj()); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSON("x" @@ -1355,8 +1358,7 @@ TEST(MatchExpressionParserLeafTest, ExistsNO1) { TEST(MatchExpressionParserLeafTest, Type1) { BSONObj query = BSON("x" << BSON("$type" << String)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" @@ -1367,8 +1369,7 @@ TEST(MatchExpressionParserLeafTest, Type1) { TEST(MatchExpressionParserLeafTest, Type2) { BSONObj query = BSON("x" << BSON("$type" << (double)NumberDouble)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(result.getValue()->matchesBSON(BSON("x" << 5.3))); @@ -1378,8 +1379,7 @@ TEST(MatchExpressionParserLeafTest, Type2) { TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) { BSONObj query = BSON("x" << BSON("$type" << 1.5)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSON("x" << 5.3))); @@ -1389,8 +1389,7 @@ TEST(MatchExpressionParserLeafTest, TypeDoubleOperator) { TEST(MatchExpressionParserLeafTest, TypeDecimalOperator) { BSONObj query = BSON("x" << BSON("$type" << mongo::NumberDecimal)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT_FALSE(result.getValue()->matchesBSON(BSON("x" << 5.3))); @@ -1400,8 +1399,7 @@ TEST(MatchExpressionParserLeafTest, TypeDecimalOperator) { TEST(MatchExpressionParserLeafTest, TypeNull) { BSONObj query = BSON("x" << BSON("$type" << jstNULL)); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_OK(result.getStatus()); ASSERT(!result.getValue()->matchesBSON(BSONObj())); @@ -1416,48 +1414,35 @@ TEST(MatchExpressionParserLeafTest, TypeBadType) { b.append("$type", (JSTypeMax + 1)); BSONObj query = BSON("x" << b.obj()); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, TypeBad) { BSONObj query = BSON("x" << BSON("$type" << BSON("x" << 1))); const CollatorInterface* collator = nullptr; - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } TEST(MatchExpressionParserLeafTest, TypeBadString) { const CollatorInterface* collator = nullptr; - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: null}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: true}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: {}}}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); ASSERT_NOT_OK( - MatchExpressionParser::parse(fromjson("{a: {$type: ObjectId('000000000000000000000000')}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: []}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + MatchExpressionParser::parse(fromjson("{a: {$type: null}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$type: true}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$type: {}}}}"), collator).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse( + fromjson("{a: {$type: ObjectId('000000000000000000000000')}}"), collator) .getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$type: []}}"), collator).getStatus()); } TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumberDouble = MatchExpressionParser::parse( - fromjson("{a: {$type: 'double'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumberDouble = + MatchExpressionParser::parse(fromjson("{a: {$type: 'double'}}"), collator); ASSERT_OK(typeNumberDouble.getStatus()); TypeMatchExpression* tmeNumberDouble = static_cast<TypeMatchExpression*>(typeNumberDouble.getValue().get()); @@ -1468,8 +1453,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameDouble) { TEST(MatchExpressionParserLeafTest, TypeStringNameNumberDecimal) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumberDecimal = MatchExpressionParser::parse( - fromjson("{a: {$type: 'decimal'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumberDecimal = + MatchExpressionParser::parse(fromjson("{a: {$type: 'decimal'}}"), collator); ASSERT_OK(typeNumberDecimal.getStatus()); TypeMatchExpression* tmeNumberDecimal = static_cast<TypeMatchExpression*>(typeNumberDecimal.getValue().get()); @@ -1480,8 +1465,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringNameNumberDecimal) { TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumberInt = MatchExpressionParser::parse( - fromjson("{a: {$type: 'int'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumberInt = + MatchExpressionParser::parse(fromjson("{a: {$type: 'int'}}"), collator); ASSERT_OK(typeNumberInt.getStatus()); TypeMatchExpression* tmeNumberInt = static_cast<TypeMatchExpression*>(typeNumberInt.getValue().get()); @@ -1492,8 +1477,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumberInt) { TEST(MatchExpressionParserLeafTest, TypeStringnameNumberLong) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumberLong = MatchExpressionParser::parse( - fromjson("{a: {$type: 'long'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumberLong = + MatchExpressionParser::parse(fromjson("{a: {$type: 'long'}}"), collator); ASSERT_OK(typeNumberLong.getStatus()); TypeMatchExpression* tmeNumberLong = static_cast<TypeMatchExpression*>(typeNumberLong.getValue().get()); @@ -1504,8 +1489,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumberLong) { TEST(MatchExpressionParserLeafTest, TypeStringnameString) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeString = MatchExpressionParser::parse( - fromjson("{a: {$type: 'string'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeString = + MatchExpressionParser::parse(fromjson("{a: {$type: 'string'}}"), collator); ASSERT_OK(typeString.getStatus()); TypeMatchExpression* tmeString = static_cast<TypeMatchExpression*>(typeString.getValue().get()); ASSERT_EQ(tmeString->getBSONType(), BSONType::String); @@ -1515,8 +1500,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameString) { TEST(MatchExpressionParserLeafTest, TypeStringnamejstOID) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typejstOID = MatchExpressionParser::parse( - fromjson("{a: {$type: 'objectId'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typejstOID = + MatchExpressionParser::parse(fromjson("{a: {$type: 'objectId'}}"), collator); ASSERT_OK(typejstOID.getStatus()); TypeMatchExpression* tmejstOID = static_cast<TypeMatchExpression*>(typejstOID.getValue().get()); ASSERT_EQ(tmejstOID->getBSONType(), BSONType::jstOID); @@ -1526,8 +1511,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnamejstOID) { TEST(MatchExpressionParserLeafTest, TypeStringnamejstNULL) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typejstNULL = MatchExpressionParser::parse( - fromjson("{a: {$type: 'null'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typejstNULL = + MatchExpressionParser::parse(fromjson("{a: {$type: 'null'}}"), collator); ASSERT_OK(typejstNULL.getStatus()); TypeMatchExpression* tmejstNULL = static_cast<TypeMatchExpression*>(typejstNULL.getValue().get()); @@ -1538,8 +1523,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnamejstNULL) { TEST(MatchExpressionParserLeafTest, TypeStringnameBool) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeBool = MatchExpressionParser::parse( - fromjson("{a: {$type: 'bool'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeBool = + MatchExpressionParser::parse(fromjson("{a: {$type: 'bool'}}"), collator); ASSERT_OK(typeBool.getStatus()); TypeMatchExpression* tmeBool = static_cast<TypeMatchExpression*>(typeBool.getValue().get()); ASSERT_EQ(tmeBool->getBSONType(), BSONType::Bool); @@ -1549,8 +1534,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameBool) { TEST(MatchExpressionParserLeafTest, TypeStringnameObject) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeObject = MatchExpressionParser::parse( - fromjson("{a: {$type: 'object'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeObject = + MatchExpressionParser::parse(fromjson("{a: {$type: 'object'}}"), collator); ASSERT_OK(typeObject.getStatus()); TypeMatchExpression* tmeObject = static_cast<TypeMatchExpression*>(typeObject.getValue().get()); ASSERT_EQ(tmeObject->getBSONType(), BSONType::Object); @@ -1560,8 +1545,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameObject) { TEST(MatchExpressionParserLeafTest, TypeStringnameArray) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeArray = MatchExpressionParser::parse( - fromjson("{a: {$type: 'array'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeArray = + MatchExpressionParser::parse(fromjson("{a: {$type: 'array'}}"), collator); ASSERT_OK(typeArray.getStatus()); TypeMatchExpression* tmeArray = static_cast<TypeMatchExpression*>(typeArray.getValue().get()); ASSERT_EQ(tmeArray->getBSONType(), BSONType::Array); @@ -1571,8 +1556,8 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameArray) { TEST(MatchExpressionParserLeafTest, TypeStringnameNumber) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumber = MatchExpressionParser::parse( - fromjson("{a: {$type: 'number'}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumber = + MatchExpressionParser::parse(fromjson("{a: {$type: 'number'}}"), collator); ASSERT_OK(typeNumber.getStatus()); TypeMatchExpression* tmeNumber = static_cast<TypeMatchExpression*>(typeNumber.getValue().get()); ASSERT_TRUE(tmeNumber->matchesBSON(fromjson("{a: 5.4}"))); @@ -1583,22 +1568,22 @@ TEST(MatchExpressionParserLeafTest, TypeStringnameNumber) { TEST(MatchExpressionParserLeafTest, InvalidTypeCodeLessThanMinKeyFailsToParse) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumber = MatchExpressionParser::parse( - fromjson("{a: {$type: -20}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumber = + MatchExpressionParser::parse(fromjson("{a: {$type: -20}}"), collator); ASSERT_NOT_OK(typeNumber.getStatus()); } TEST(MatchExpressionParserLeafTest, InvalidTypeCodeGreaterThanMaxKeyFailsToParse) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumber = MatchExpressionParser::parse( - fromjson("{a: {$type: 400}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumber = + MatchExpressionParser::parse(fromjson("{a: {$type: 400}}"), collator); ASSERT_NOT_OK(typeNumber.getStatus()); } TEST(MatchExpressionParserLeafTest, InvalidTypeCodeUnusedBetweenMinAndMaxFailsToParse) { const CollatorInterface* collator = nullptr; - StatusWithMatchExpression typeNumber = MatchExpressionParser::parse( - fromjson("{a: {$type: 62}}"), ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression typeNumber = + MatchExpressionParser::parse(fromjson("{a: {$type: 62}}"), collator); ASSERT_NOT_OK(typeNumber.getStatus()); } @@ -1611,8 +1596,7 @@ TEST(MatchExpressionParserLeafTest, ValidTypeCodesParseSuccessfully) { for (auto type : validTypes) { BSONObj predicate = BSON("a" << BSON("$type" << type)); const CollatorInterface* collator = nullptr; - auto expression = MatchExpressionParser::parse( - predicate, ExtensionsCallbackDisallowExtensions(), collator); + auto expression = MatchExpressionParser::parse(predicate, collator); ASSERT_OK(expression.getStatus()); auto typeExpression = static_cast<TypeMatchExpression*>(expression.getValue().get()); ASSERT_EQ(type, typeExpression->getBSONType()); @@ -1628,8 +1612,7 @@ TEST(MatchExpressionParserLeafTest, TypeWithConstantExprFails) { auto varId = expCtx->variablesParseState.defineVariable("userVar"); expCtx->variables.setValue(varId, Value(static_cast<int>(BSONType::NumberDouble))); - StatusWithMatchExpression result = - MatchExpressionParser::parse(query, ExtensionsCallbackDisallowExtensions(), collator); + StatusWithMatchExpression result = MatchExpressionParser::parse(query, collator); ASSERT_NOT_OK(result.getStatus()); } @@ -1637,77 +1620,55 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidMask) { const double k2Power53 = scalbn(1, 32); const CollatorInterface* collator = nullptr; - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << 54)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<long long>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53 - 1)), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << 54)), collator).getStatus()); + ASSERT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<long long>::max())), collator) + .getStatus()); + ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53)), collator) .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << k2Power53 - 1)), collator) + .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << 54)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<long long>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53 - 1)), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << 54)), collator) .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<long long>::max())), collator) + .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53)), collator) + .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << k2Power53 - 1)), collator) + .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << 54)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<long long>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53 - 1)), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << 54)), collator).getStatus()); + ASSERT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<long long>::max())), collator) + .getStatus()); + ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53)), collator) .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << k2Power53 - 1)), collator) + .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << 54)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<long long>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53)), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53 - 1)), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << 54)), collator) .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<long long>::max())), collator) + .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53)), collator) + .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << k2Power53 - 1)), collator) + .getStatus()); } TEST(MatchExpressionParserTest, BitTestMatchExpressionValidArray) { @@ -1718,79 +1679,59 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidArray) { ASSERT_EQ(BSONType::NumberLong, bsonArrayLongLong[3].type()); const CollatorInterface* collator = nullptr; - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0))), collator) + .getStatus()); ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0 << 1 << 2 << 3))), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(0 << 1 << 2 << 3))), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << bsonArrayLongLong)), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse( BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(std::numeric_limits<int>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0))), collator) + .getStatus()); ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0 << 1 << 2 << 3))), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(0 << 1 << 2 << 3))), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << bsonArrayLongLong)), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse( BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(std::numeric_limits<int>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0))), collator) + .getStatus()); ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0 << 1 << 2 << 3))), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(0 << 1 << 2 << 3))), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << bsonArrayLongLong)), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse( BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(std::numeric_limits<int>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_OK( + MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0))), collator) + .getStatus()); ASSERT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0 << 1 << 2 << 3))), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(0 << 1 << 2 << 3))), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << bsonArrayLongLong)), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_OK(MatchExpressionParser::parse( BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(std::numeric_limits<int>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); } @@ -1800,7 +1741,6 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidBinData) { ASSERT_OK( MatchExpressionParser::parse( fromjson("{a: {$bitsAllSet: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); @@ -1808,14 +1748,12 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidBinData) { MatchExpressionParser::parse( fromjson( "{a: {$bitsAllClear: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_OK( MatchExpressionParser::parse( fromjson("{a: {$bitsAnySet: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); @@ -1823,496 +1761,308 @@ TEST(MatchExpressionParserTest, BitTestMatchExpressionValidBinData) { MatchExpressionParser::parse( fromjson( "{a: {$bitsAnyClear: {$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); } TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidMaskType) { const CollatorInterface* collator = nullptr; - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: null}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: true}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: {}}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ''}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: null}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: true}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: {}}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ''}}"), collator).getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: null}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: true}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: {}}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ''}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse( - fromjson("{a: {$bitsAllClear: ObjectId('000000000000000000000000')}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: null}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: true}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: {}}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ''}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse( + fromjson("{a: {$bitsAllClear: ObjectId('000000000000000000000000')}}"), collator) + .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: null}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: true}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: {}}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ''}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse( - fromjson("{a: {$bitsAnySet: ObjectId('000000000000000000000000')}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: null}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: true}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: {}}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ''}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse( + fromjson("{a: {$bitsAnySet: ObjectId('000000000000000000000000')}}"), collator) + .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: null}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: true}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: {}}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ''}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse( - fromjson("{a: {$bitsAnyClear: ObjectId('000000000000000000000000')}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: null}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: true}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: {}}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ''}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse( + fromjson("{a: {$bitsAnyClear: ObjectId('000000000000000000000000')}}"), collator) + .getStatus()); } TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidMaskValue) { const double kLongLongMaxAsDouble = scalbn(1, std::numeric_limits<long long>::digits); const CollatorInterface* collator = nullptr; - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: NaN}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: -54}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<double>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << kLongLongMaxAsDouble)), - ExtensionsCallbackDisallowExtensions(), - collator) + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: NaN}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: -54}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAllSet" << std::numeric_limits<double>::max())), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: 2.5}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAllSet" << kLongLongMaxAsDouble)), collator) .getStatus()); - ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllSet" << Decimal128("2.5"))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: 2.5}}"), collator).getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: NaN}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: -54}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<double>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAllSet" << Decimal128("2.5"))), collator) .getStatus()); + + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: NaN}}"), collator).getStatus()); ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << kLongLongMaxAsDouble)), - ExtensionsCallbackDisallowExtensions(), - collator) + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: -54}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAllClear" << std::numeric_limits<double>::max())), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: 2.5}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAllClear" << kLongLongMaxAsDouble)), collator) .getStatus()); - ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAllClear" << Decimal128("2.5"))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: 2.5}}"), collator).getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: NaN}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: -54}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<double>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAllClear" << Decimal128("2.5"))), collator) .getStatus()); + + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: NaN}}"), collator).getStatus()); ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << kLongLongMaxAsDouble)), - ExtensionsCallbackDisallowExtensions(), - collator) + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: -54}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnySet" << std::numeric_limits<double>::max())), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: 2.5}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnySet" << kLongLongMaxAsDouble)), collator) .getStatus()); - ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnySet" << Decimal128("2.5"))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: 2.5}}"), collator).getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: NaN}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: -54}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse( - BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<double>::max())), - ExtensionsCallbackDisallowExtensions(), - collator) + BSON("a" << BSON("$bitsAnySet" << Decimal128("2.5"))), collator) .getStatus()); + + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: NaN}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: -54}}"), collator).getStatus()); ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << kLongLongMaxAsDouble)), - ExtensionsCallbackDisallowExtensions(), - collator) + MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnyClear" << std::numeric_limits<double>::max())), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: 2.5}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnyClear" << kLongLongMaxAsDouble)), collator) .getStatus()); - ASSERT_NOT_OK( - MatchExpressionParser::parse(BSON("a" << BSON("$bitsAnyClear" << Decimal128("2.5"))), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: 2.5}}"), collator).getStatus()); + + ASSERT_NOT_OK(MatchExpressionParser::parse( + BSON("a" << BSON("$bitsAnyClear" << Decimal128("2.5"))), collator) + .getStatus()); } TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidArray) { const CollatorInterface* collator = nullptr; - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [null]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [true]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ['']}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [{}]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [[]]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [null]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [true]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: ['']}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [{}]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [[]]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"), collator).getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( fromjson( "{a: {$bitsAllSet: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [null]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [true]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ['']}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [{}]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [[]]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [null]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [true]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: ['']}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [{}]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [[]]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1]}}"), collator).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( fromjson( "{a: {$bitsAllClear: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [null]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [true]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ['']}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [{}]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [[]]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [null]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [true]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: ['']}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [{}]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [[]]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"), collator).getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( fromjson( "{a: {$bitsAnySet: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [null]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [true]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [null]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ['']}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [true]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [{}]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [[]]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: ['']}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [{}]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [[]]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1]}}"), collator).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( fromjson( "{a: {$bitsAnyClear: [{$binary: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA', $type: '00'}]}}"), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); } TEST(MatchExpressionParserTest, BitTestMatchExpressionInvalidArrayValue) { const CollatorInterface* collator = nullptr; - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-54]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [NaN]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-54]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [NaN]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [2.5]}}"), collator).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [1e100]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [-1e100]}}"), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(std::numeric_limits<long long>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAllSet" << BSON_ARRAY(std::numeric_limits<long long>::min()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-54]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-54]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [NaN]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [NaN]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [2.5]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [1e100]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: [-1e100]}}"), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(std::numeric_limits<long long>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAllClear" << BSON_ARRAY(std::numeric_limits<long long>::min()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-54]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [NaN]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) - .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-54]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [NaN]}}"), collator).getStatus()); + ASSERT_NOT_OK( + MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [2.5]}}"), collator).getStatus()); + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [1e100]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: [-1e100]}}"), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(std::numeric_limits<long long>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAnySet" << BSON_ARRAY(std::numeric_limits<long long>::min()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-54]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-54]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [NaN]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [NaN]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [2.5]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [1e100]}}"), collator) .getStatus()); - ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1e100]}}"), - ExtensionsCallbackDisallowExtensions(), - collator) + ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: [-1e100]}}"), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(std::numeric_limits<long long>::max()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); ASSERT_NOT_OK( MatchExpressionParser::parse( BSON("a" << BSON("$bitsAnyClear" << BSON_ARRAY(std::numeric_limits<long long>::min()))), - ExtensionsCallbackDisallowExtensions(), collator) .getStatus()); } @@ -2325,27 +2075,31 @@ TEST(MatchExpressionParserLeafTest, BitTestWithConstantExprFails) { expCtx->variables.setValue(varId, Value(BSON_ARRAY(1 << 5))); ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllSet: [{$expr: 'userVar'}]}}"), - ExtensionsCallbackDisallowExtensions(), collator, - expCtx) + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr) .getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnySet: {$expr: 'userVar'}}}"), - ExtensionsCallbackDisallowExtensions(), collator, - expCtx) + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr) .getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAllClear: {$expr: 'userVar'}}}"), - ExtensionsCallbackDisallowExtensions(), collator, - expCtx) + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr) .getStatus()); ASSERT_NOT_OK(MatchExpressionParser::parse(fromjson("{a: {$bitsAnyClear: {$expr: 'userVar'}}}"), - ExtensionsCallbackDisallowExtensions(), collator, - expCtx) + expCtx, + ExtensionsCallbackNoop(), + MatchExpressionParser::AllowedFeatures::kExpr) .getStatus()); } } // namespace mongo |