diff options
author | James Wahlin <james.wahlin@10gen.com> | 2017-04-11 10:12:56 -0400 |
---|---|---|
committer | James Wahlin <james.wahlin@10gen.com> | 2017-04-12 17:00:45 -0400 |
commit | b5e2615f9cf29942783ed554afeb364052dd83a4 (patch) | |
tree | 1deb75898a9f170ddc3ea482d829dbbfa0064287 /src/mongo/db/views | |
parent | 2788b12816f9124cae6b35a0554361b232c27419 (diff) | |
download | mongo-b5e2615f9cf29942783ed554afeb364052dd83a4.tar.gz |
SERVER-28271 Improve handling of invalid view pipeline defs
Diffstat (limited to 'src/mongo/db/views')
-rw-r--r-- | src/mongo/db/views/view_catalog.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/views/view_catalog_test.cpp | 10 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp index e9771f79ba6..7f810dcaf25 100644 --- a/src/mongo/db/views/view_catalog.cpp +++ b/src/mongo/db/views/view_catalog.cpp @@ -89,10 +89,22 @@ Status ViewCatalog::_reloadIfNeeded_inlock(OperationContext* opCtx) { } NamespaceString viewName(view["_id"].str()); + + auto pipeline = view["pipeline"].Obj(); + for (auto&& stage : pipeline) { + if (BSONType::Object != stage.type()) { + return Status(ErrorCodes::InvalidViewDefinition, + str::stream() << "View 'pipeline' entries must be objects, but " + << viewName.toString() + << " has a pipeline element of type " + << stage.type()); + } + } + _viewMap[viewName.ns()] = std::make_shared<ViewDefinition>(viewName.db(), viewName.coll(), view["viewOn"].str(), - view["pipeline"].Obj(), + pipeline, std::move(collator.getValue())); return Status::OK(); }); diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp index d6303eb8070..694f35ac1e1 100644 --- a/src/mongo/db/views/view_catalog_test.cpp +++ b/src/mongo/db/views/view_catalog_test.cpp @@ -128,6 +128,16 @@ TEST_F(ViewCatalogFixture, CreateViewOnDifferentDatabase) { viewCatalog.createView(opCtx.get(), viewName, viewOn, emptyPipeline, emptyCollation)); } +TEST_F(ViewCatalogFixture, CreateViewWithPipelineFailsOnInvalidStageName) { + const NamespaceString viewName("db.view"); + const NamespaceString viewOn("db.coll"); + + auto invalidPipeline = BSON_ARRAY(BSON("INVALID_STAGE_NAME" << 1)); + ASSERT_THROWS( + viewCatalog.createView(opCtx.get(), viewName, viewOn, invalidPipeline, emptyCollation), + UserException); +} + TEST_F(ViewCatalogFixture, CreateViewOnInvalidCollectionName) { const NamespaceString viewName("db.view"); const NamespaceString viewOn("db.$coll"); |