diff options
author | Gregory Noma <gregory.noma@gmail.com> | 2020-07-09 10:46:37 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-20 13:35:53 +0000 |
commit | 2cf8cd352731e3996342ce92b900514f4899db52 (patch) | |
tree | 03e929143a3476c2d7c422f8c3b4eddd3a485a46 /jstests/core/views | |
parent | ab1a892520e9a9b84ae90d52f84a0f107efbdecd (diff) | |
download | mongo-2cf8cd352731e3996342ce92b900514f4899db52.tar.gz |
SERVER-43633 Prohibit user writes to system.views in FCV 4.6
Diffstat (limited to 'jstests/core/views')
-rw-r--r-- | jstests/core/views/duplicate_ns.js | 33 | ||||
-rw-r--r-- | jstests/core/views/invalid_system_views.js | 12 | ||||
-rw-r--r-- | jstests/core/views/view_with_invalid_dbname.js | 32 | ||||
-rw-r--r-- | jstests/core/views/views_creation.js | 35 |
4 files changed, 74 insertions, 38 deletions
diff --git a/jstests/core/views/duplicate_ns.js b/jstests/core/views/duplicate_ns.js index 8b22e6769a4..1d528e30ec1 100644 --- a/jstests/core/views/duplicate_ns.js +++ b/jstests/core/views/duplicate_ns.js @@ -1,10 +1,13 @@ -// @tags: [ -// assumes_superuser_permissions, -// requires_non_retryable_writes, -// ] - -// Test the creation of view with a duplicate name to a collection. - +/** + * Tests the creation of view with a duplicate name to a collection. + * + * @tags: [ + * assumes_against_mongod_not_mongos, + * assumes_superuser_permissions, + * # applyOps is not retryable. + * requires_non_retryable_writes, + * ] + */ (function() { "use strict"; @@ -14,12 +17,18 @@ const collName = "myns"; const viewId = dbName + "." + collName; assert.commandWorked(viewsDb.dropDatabase()); -assert.commandWorked(viewsDb.system.views.remove({_id: viewId})); assert.commandWorked(viewsDb.runCommand({create: collName})); -assert.commandWorked(viewsDb.system.views.insert({ - _id: viewId, - viewOn: "coll", - pipeline: [], +assert.commandWorked(viewsDb.createCollection("system.views")); +assert.commandWorked(viewsDb.adminCommand({ + applyOps: [{ + op: "i", + ns: dbName + ".system.views", + o: { + _id: viewId, + viewOn: "coll", + pipeline: [], + } + }] })); assert.eq(2, viewsDb.getCollectionInfos() diff --git a/jstests/core/views/invalid_system_views.js b/jstests/core/views/invalid_system_views.js index 726715c5533..8e0939d313e 100644 --- a/jstests/core/views/invalid_system_views.js +++ b/jstests/core/views/invalid_system_views.js @@ -3,6 +3,8 @@ * collections. * * @tags: [ + * # applyOps is not available on mongos. + * assumes_against_mongod_not_mongos, * assumes_superuser_permissions, * requires_non_retryable_commands, * requires_non_retryable_writes, @@ -25,8 +27,11 @@ function runTest(badViewDefinition) { assert.commandWorked(viewsDB.runCommand({create: "collection2"})); assert.commandWorked(viewsDB.runCommand({create: "collection3"})); assert.commandWorked(viewsDB.collection.createIndex({x: 1})); - assert.commandWorked(viewsDB.system.views.insert(badViewDefinition), - "failed to insert " + tojson(badViewDefinition)); + assert.commandWorked(viewsDB.createCollection("system.views")); + assert.commandWorked( + viewsDB.adminCommand( + {applyOps: [{op: "i", ns: viewsDB.getName() + ".system.views", o: badViewDefinition}]}), + "failed to insert " + tojson(badViewDefinition)); // Test that a command involving views properly fails with a views-specific error code. assert.commandFailedWithCode( @@ -118,7 +123,8 @@ function runTest(badViewDefinition) { assert.commandWorked(viewsDB.runCommand({drop: "collection2"}), makeErrorMessage("drop")); // Drop the offending view so that the validate hook succeeds. - assert.commandWorked(viewsDB.system.views.remove(badViewDefinition)); + assert.commandWorked(viewsDB.adminCommand( + {applyOps: [{op: "d", ns: viewsDB.getName() + ".system.views", o: badViewDefinition}]})); } runTest({_id: "invalid_system_views.badViewStringPipeline", viewOn: "collection", pipeline: "bad"}); diff --git a/jstests/core/views/view_with_invalid_dbname.js b/jstests/core/views/view_with_invalid_dbname.js index 180461d41b7..a4e0c126193 100644 --- a/jstests/core/views/view_with_invalid_dbname.js +++ b/jstests/core/views/view_with_invalid_dbname.js @@ -1,6 +1,16 @@ -// When loading the view catalog, the server should not crash because it encountered a view with an -// invalid name. This test is specifically for the case of a view with a dbname that contains an -// embedded null character (SERVER-36859). + +/** + * When loading the view catalog, the server should not crash because it encountered a view with an + * invalid name. This test is specifically for the case of a view with a dbname that contains an + * embedded null character (SERVER-36859). + * + * @tags: [ + * # applyOps is not available on mongos. + * assumes_against_mongod_not_mongos, + * # applyOps is not retryable. + * requires_non_retryable_commands, + * ] + */ (function() { "use strict"; @@ -15,13 +25,11 @@ const viewDef = { pipeline: [] }; -try { - assert.commandWorked(db.system.views.insert(viewDef)); -} finally { - // Don't let the bogus view stick around, or else it will cause an error in validation. - var result = db.system.views.deleteOne({_id: viewName}); -} -// If this test otherwise succeeded, assert cleaning up succeeded. -// Skip this assertion if the test otherwise failed, to avoid masking the original error. -assert.eq(1, result.deletedCount); +db.system.views.drop(); +assert.commandWorked(db.createCollection("system.views")); +assert.commandWorked(db.adminCommand({applyOps: [{op: "i", ns: "test.system.views", o: viewDef}]})); + +// Don't let the bogus view stick around, or else it will cause an error in validation. +assert.commandWorked( + db.adminCommand({applyOps: [{op: "d", ns: "test.system.views", o: {_id: viewName}}]})); }()); diff --git a/jstests/core/views/views_creation.js b/jstests/core/views/views_creation.js index 1765b9c4182..7c211b801d4 100644 --- a/jstests/core/views/views_creation.js +++ b/jstests/core/views/views_creation.js @@ -1,8 +1,14 @@ -// Test the creation of views with various options. -// @tags: [ -// assumes_superuser_permissions, -// ] - +/** + * Test the creation of views with various options. + * + * @tags: [ + * # applyOps is not available on mongos. + * assumes_against_mongod_not_mongos, + * assumes_superuser_permissions, + * # applyOps is not retryable. + * requires_non_retryable_commands, + * ] + */ (function() { "use strict"; @@ -100,14 +106,21 @@ assert.commandFailedWithCode(viewsDB.runCommand({ // These test that, when an existing view in system.views is invalid because of a $out in the // pipeline, the database errors on creation of a new view. -assert.commandWorked(viewsDB.system.views.insert({ - _id: `${viewsDBName}.invalidView`, - viewOn: "collection", - pipeline: [{$project: {_id: false}}, {$out: "notExistingCollection"}] +assert.commandWorked(viewsDB.adminCommand({ + applyOps: [{ + op: "i", + ns: viewsDBName + ".system.views", + o: { + _id: viewsDBName + ".invalidView", + viewOn: "collection", + pipeline: [{$project: {_id: false}}, {$out: "notExistingCollection"}] + } + }] })); assert.commandFailedWithCode( viewsDB.runCommand({create: "viewWithBadViewCatalog", viewOn: "collection", pipeline: []}), ErrorCodes.OptionNotSupportedOnView); -assert.commandWorked( - viewsDB.system.views.remove({_id: `${viewsDBName}.invalidView`}, {justOne: true})); +assert.commandWorked(viewsDB.adminCommand({ + applyOps: [{op: "d", ns: viewsDBName + ".system.views", o: {_id: viewsDBName + ".invalidView"}}] +})); }()); |