summaryrefslogtreecommitdiff
path: root/src/mongo/db/update/set_node_test.cpp
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2020-08-05 15:42:25 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-06 01:41:30 +0000
commite90324a09559eb3398c7c2b3360088e69496c3fd (patch)
tree65f09c99f306e344528a8aca541901dfda510c17 /src/mongo/db/update/set_node_test.cpp
parentf67a91df05719630d7893140dbb3a5edd45a642b (diff)
downloadmongo-e90324a09559eb3398c7c2b3360088e69496c3fd.tar.gz
Revert "SERVER-49117 Remove storage validation of '$' and '.' in field names for insert and update"
This reverts commit f1194464424569250152308e3cae1ecbade7fb71.
Diffstat (limited to 'src/mongo/db/update/set_node_test.cpp')
-rw-r--r--src/mongo/db/update/set_node_test.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/mongo/db/update/set_node_test.cpp b/src/mongo/db/update/set_node_test.cpp
index e31edf0b6a6..8cd2b60243e 100644
--- a/src/mongo/db/update/set_node_test.cpp
+++ b/src/mongo/db/update/set_node_test.cpp
@@ -1018,6 +1018,66 @@ TEST_F(SetNodeTest, ApplySetModToEphemeralDocument) {
ASSERT_FALSE(doc.isInPlaceModeEnabled());
}
+TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldInsideSetElement) {
+ auto update = fromjson("{$set: {a: {$bad: 1}}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ SetNode node;
+ ASSERT_OK(node.init(update["$set"]["a"], expCtx));
+
+ mutablebson::Document doc(fromjson("{a: 5}"));
+ setPathTaken("a");
+ ASSERT_THROWS_CODE_AND_WHAT(
+ node.apply(getApplyParams(doc.root()["a"]), getUpdateNodeApplyParams()),
+ AssertionException,
+ ErrorCodes::DollarPrefixedFieldName,
+ "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage.");
+}
+
+TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldAtStartOfPath) {
+ auto update = fromjson("{$set: {'$bad.a': 1}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ SetNode node;
+ ASSERT_OK(node.init(update["$set"]["$bad.a"], expCtx));
+
+ mutablebson::Document doc(fromjson("{}"));
+ setPathToCreate("$bad.a");
+ ASSERT_THROWS_CODE_AND_WHAT(
+ node.apply(getApplyParams(doc.root()), getUpdateNodeApplyParams()),
+ AssertionException,
+ ErrorCodes::DollarPrefixedFieldName,
+ "The dollar ($) prefixed field '$bad' in '$bad' is not valid for storage.");
+}
+
+TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldInMiddleOfPath) {
+ auto update = fromjson("{$set: {'a.$bad.b': 1}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ SetNode node;
+ ASSERT_OK(node.init(update["$set"]["a.$bad.b"], expCtx));
+
+ mutablebson::Document doc(fromjson("{}"));
+ setPathToCreate("a.$bad.b");
+ ASSERT_THROWS_CODE_AND_WHAT(
+ node.apply(getApplyParams(doc.root()), getUpdateNodeApplyParams()),
+ AssertionException,
+ ErrorCodes::DollarPrefixedFieldName,
+ "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage.");
+}
+
+TEST_F(SetNodeTest, ApplyCannotCreateDollarPrefixedFieldAtEndOfPath) {
+ auto update = fromjson("{$set: {'a.$bad': 1}}");
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());
+ SetNode node;
+ ASSERT_OK(node.init(update["$set"]["a.$bad"], expCtx));
+
+ mutablebson::Document doc(fromjson("{}"));
+ setPathToCreate("a.$bad");
+ ASSERT_THROWS_CODE_AND_WHAT(
+ node.apply(getApplyParams(doc.root()), getUpdateNodeApplyParams()),
+ AssertionException,
+ ErrorCodes::DollarPrefixedFieldName,
+ "The dollar ($) prefixed field '$bad' in 'a.$bad' is not valid for storage.");
+}
+
TEST_F(SetNodeTest, ApplyCanCreateDollarPrefixedFieldNameWhenValidateForStorageIsFalse) {
auto update = fromjson("{$set: {$bad: 1}}");
boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest());