1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/**
* Verify that adding 'comment' field to any command shouldn't cause unexpected failures.
* @tags: [
* requires_capped,
* requires_persistence,
* requires_replication,
* requires_sharding,
* ]
*/
import {authCommandsLib} from "jstests/auth/lib/commands_lib.js";
load("jstests/libs/fail_point_util.js"); // Helper to enable/disable failpoints easily.
const tests = authCommandsLib.tests;
// The following commands require additional start up configuration and hence need to be skipped.
const denylistedTests = [
"startRecordingTraffic",
"stopRecordingTraffic",
"addShardToZone",
"removeShardFromZone",
"oidcListKeys",
"oidcRefreshKeys"
];
function runTests(tests, conn, impls, options) {
for (const test of tests) {
if (!denylistedTests.includes(test.testname)) {
authCommandsLib.runOneTest(conn, test, impls, options);
}
}
}
const impls = {
runOneTest: function(conn, testObj) {
// Some tests requires mongot, however, setting this failpoint will make search queries to
// return EOF, that way all the hassle of setting it up can be avoided.
let disableSearchFailpoint;
if (testObj.disableSearch) {
disableSearchFailpoint = configureFailPoint(conn.rs0 ? conn.rs0.getPrimary() : conn,
'searchReturnEofImmediately');
}
const testCase = testObj.testcases[0];
const runOnDb = conn.getDB(testCase.runOnDb);
const state = testObj.setup && testObj.setup(runOnDb);
const command = (typeof (testObj.command) === "function")
? testObj.command(state, testCase.commandArgs)
: testObj.command;
command['comment'] = {comment: true};
const res = runOnDb.runCommand(command);
assert(res.ok == 1 || testCase.expectFail || res.code == ErrorCodes.CommandNotSupported,
tojson(res));
if (testObj.teardown) {
testObj.teardown(runOnDb, res);
}
if (disableSearchFailpoint) {
disableSearchFailpoint.off();
}
}
};
let conn = MongoRunner.runMongod();
// Test with standalone mongod.
runTests(tests, conn, impls);
MongoRunner.stopMongod(conn);
// Test with a sharded cluster. Some tests require the first shard's name acquired from the
// auth commands library to be up-to-date in order to set up correctly.
conn = new ShardingTest({shards: 1, mongos: 2});
runTests(tests, conn, impls, {shard0name: conn.shard0.shardName});
conn.stop();
|