summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/set_user_write_block_mode.js
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2022-04-08 11:21:10 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-08 12:11:25 +0000
commit526193103b6064df5894b3d0c19c6cbdd15fbd3b (patch)
treec853acb91c7d821cc12b31266c421947ac94c5d8 /jstests/noPassthrough/set_user_write_block_mode.js
parent2348955db895146aa9a0d58246e3fc995049acd2 (diff)
downloadmongo-526193103b6064df5894b3d0c19c6cbdd15fbd3b.tar.gz
SERVER-65038 Ensure profiling works when write blocking is enabled
Diffstat (limited to 'jstests/noPassthrough/set_user_write_block_mode.js')
-rw-r--r--jstests/noPassthrough/set_user_write_block_mode.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/noPassthrough/set_user_write_block_mode.js b/jstests/noPassthrough/set_user_write_block_mode.js
index e2e83bdd095..bc8ebead019 100644
--- a/jstests/noPassthrough/set_user_write_block_mode.js
+++ b/jstests/noPassthrough/set_user_write_block_mode.js
@@ -134,6 +134,31 @@ function testCheckedOps(conn, shouldSucceed, expectedFailure) {
assertState();
}
+// Checks that an unprivileged user's operations can be logged on the profiling collection.
+function testProfiling(fixture) {
+ const collName = 'foo';
+ fixture.asAdmin(({db}) => {
+ assert.commandWorked(db[collName].insert({x: 1}));
+ });
+
+ // Enable profiling.
+ const prevProfilingLevel = fixture.setProfilingLevel(2).was;
+
+ // Perform a find() as an unprivileged user.
+ const comment = UUID();
+ fixture.asUser(({db}) => {
+ db[collName].find().comment(comment).itcount();
+ });
+
+ // Check that the find() was logged on the profiling collection.
+ fixture.asAdmin(({db}) => {
+ assert.eq(1, db.system.profile.find({'command.comment': comment}).itcount());
+ });
+
+ // Restore the original profiling level.
+ fixture.setProfilingLevel(prevProfilingLevel);
+}
+
function runTest(fixture) {
fixture.asAdmin(({conn}) => setupForTesting(conn));
@@ -159,6 +184,9 @@ function runTest(fixture) {
fixture.asAdmin(({conn}) => testCheckedOps(conn, true));
fixture.asUser(({conn}) => testCheckedOps(conn, false, ErrorCodes.UserWritesBlocked));
+ // Ensure that profiling works while user writes are blocked.
+ testProfiling(fixture);
+
// Restarting the cluster has no impact, as write block state is durable
fixture.restart();