summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBrigitte Lamarche <thesisiwbl@gmail.com>2018-12-20 14:24:02 -0500
committerBrigitte Lamarche <thesisiwbl@gmail.com>2019-01-03 15:13:57 -0500
commitbb9114dc71bfcf42422471f7789eca00881b8864 (patch)
tree4809839aab0c3f97bf56a66df15cd8eae8b03ca2 /src/mongo
parent68832e1f70fa4571673ab337ae2e529b04b67e6b (diff)
downloadmongo-bb9114dc71bfcf42422471f7789eca00881b8864.tar.gz
SERVER-38362 Prevent $out stage within $lookup
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/pipeline/document_source_lookup.cpp8
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_test.cpp17
2 files changed, 13 insertions, 12 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp
index 84ff4c5496e..0d8ea164537 100644
--- a/src/mongo/db/pipeline/document_source_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup.cpp
@@ -656,8 +656,14 @@ void DocumentSourceLookUp::initializeIntrospectionPipeline() {
// Ensure that the pipeline does not contain a $changeStream stage. This check will be
// performed recursively on all sub-pipelines.
uassert(ErrorCodes::IllegalOperation,
- "$changeStream is not allowed within a $lookup foreign pipeline",
+ "$changeStream is not allowed within a $lookup's pipeline",
sources.empty() || !sources.front()->constraints().isChangeStreamStage());
+
+ // Ensure that the pipeline does not contain a $out stage. Since $out must be the last stage
+ // of a pipeline, we only need to check the last DocumentSource.
+ uassert(51047,
+ "$out is not allowed within a $lookup's pipeline",
+ sources.empty() || !sources.back()->constraints().writesPersistentData());
}
void DocumentSourceLookUp::serializeToArray(
diff --git a/src/mongo/db/pipeline/document_source_lookup_test.cpp b/src/mongo/db/pipeline/document_source_lookup_test.cpp
index 027a06c5e15..64e12231227 100644
--- a/src/mongo/db/pipeline/document_source_lookup_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_test.cpp
@@ -215,12 +215,12 @@ TEST_F(DocumentSourceLookUpTest, LookupEmptyPipelineDoesntUseDiskAndIsOKInATrans
DocumentSource::TransactionRequirement::kAllowed);
}
-TEST_F(DocumentSourceLookUpTest, LookupWithChildStagesInheritsDiskUseRequirement) {
+TEST_F(DocumentSourceLookUpTest, LookupWithOutInPipelineNotAllowed) {
+ auto ERROR_CODE_OUT_BANNED_IN_LOOKUP = 51047;
auto expCtx = getExpCtx();
NamespaceString fromNs("test", "coll");
expCtx->setResolvedNamespace_forTest(fromNs, {fromNs, std::vector<BSONObj>{}});
-
- auto docSource =
+ ASSERT_THROWS_CODE(
DocumentSourceLookUp::createFromBson(BSON("$lookup" << BSON("from"
<< "coll"
<< "pipeline"
@@ -229,14 +229,9 @@ TEST_F(DocumentSourceLookUpTest, LookupWithChildStagesInheritsDiskUseRequirement
<< "as"
<< "as"))
.firstElement(),
- expCtx);
- auto lookup = static_cast<DocumentSourceLookUp*>(docSource.get());
-
- ASSERT_TRUE(lookup->wasConstructedWithPipelineSyntax());
- ASSERT(lookup->constraints(Pipeline::SplitState::kUnsplit).diskRequirement ==
- DocumentSource::DiskUseRequirement::kWritesPersistentData);
- ASSERT(lookup->constraints(Pipeline::SplitState::kUnsplit).transactionRequirement ==
- DocumentSource::TransactionRequirement::kNotAllowed);
+ expCtx),
+ AssertionException,
+ ERROR_CODE_OUT_BANNED_IN_LOOKUP);
}
TEST_F(DocumentSourceLookUpTest, LiteParsedDocumentSourceLookupContainsExpectedNamespaces) {