Skip to content

Commit ad09ee9

Browse files
chiihuangMongoDB Bot
authored andcommitted
SERVER-92411 Add missing authz tests on aggregation stages in jstests/auth/commands_lib.js (#35133)
GitOrigin-RevId: e9c33a4ff41b1a03d23d3cd5abc15999bbe989c8
1 parent 95a2872 commit ad09ee9

8 files changed

+1050
-103
lines changed

etc/backports_required_for_multiversion_tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ last-continuous:
505505
ticket: SERVER-89618
506506
- test_file: jstests/core/timeseries/timeseries_computed_field.js
507507
ticket: SERVER-88072
508+
- test_file: jstests/auth/commands_builtin_roles_replset.js
509+
ticket: SERVER-92411
508510
- test_file: jstests/core/timeseries/timeseries_geonear_lookup.js
509511
ticket: SERVER-81454
510512
- test_file: jstests/sharding/move_chunk_deferred_lookup.js
@@ -1170,6 +1172,8 @@ last-lts:
11701172
ticket: SERVER-89618
11711173
- test_file: jstests/core/timeseries/timeseries_computed_field.js
11721174
ticket: SERVER-88072
1175+
- test_file: jstests/auth/commands_builtin_roles_replset.js
1176+
ticket: SERVER-92411
11731177
- test_file: jstests/core/timeseries/timeseries_geonear_lookup.js
11741178
ticket: SERVER-81454
11751179
- test_file: jstests/sharding/move_chunk_deferred_lookup.js
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {createUsers, roles, runOneTest} from "jstests/auth/lib/commands_builtin_roles.js";
2+
import {authCommandsLib} from "jstests/auth/lib/commands_lib.js";
3+
4+
function isPrimaryNode(conn) {
5+
return (conn.adminCommand({hello: 1}).isWritablePrimary);
6+
}
7+
8+
function updateRolesWithPrimaryDB(primaryConn) {
9+
roles.forEach(role => {
10+
role.db = primaryConn.getDB(role.dbname);
11+
});
12+
}
13+
14+
function runAllCommandsBuiltinRoles(rst) {
15+
// Tracks the connection 'conn' and ensures it is connecting to writable primary.
16+
let conn = rst.getPrimary();
17+
18+
const runOneTestOnPrimary = (_, t) => {
19+
// Some test commands may make 'conn' step down as a secondary. If that happens, update
20+
// 'conn' with a primary one.
21+
if (!isPrimaryNode(conn)) {
22+
conn = rst.getPrimary();
23+
// The DBs in 'roles' may still connect to a secondary. Update them with the DBs from
24+
// 'conn'.
25+
updateRolesWithPrimaryDB(conn);
26+
}
27+
return runOneTest(conn, t);
28+
};
29+
30+
const testFunctionImpls = {createUsers: createUsers, runOneTest: runOneTestOnPrimary};
31+
authCommandsLib.runTests(conn, testFunctionImpls);
32+
}
33+
34+
const dbPath = MongoRunner.toRealDir("$dataDir/commands_built_in_roles_replset/");
35+
mkdir(dbPath);
36+
const opts = {
37+
auth: "",
38+
setParameter: {
39+
trafficRecordingDirectory: dbPath,
40+
syncdelay: 0 // Disable checkpoints as this can cause some commands to fail transiently.
41+
}
42+
};
43+
44+
// run all tests replset
45+
const rst = new ReplSetTest({
46+
nodes: 3,
47+
nodeOptions: opts,
48+
waitForKeys: false,
49+
keyFile: "jstests/libs/key1",
50+
});
51+
rst.startSet();
52+
rst.initiate();
53+
rst.awaitSecondaryNodes();
54+
55+
runAllCommandsBuiltinRoles(rst);
56+
rst.stopSet();

jstests/auth/lib/commands_builtin_roles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function testProperAuthorization(conn, t, testcase, r) {
9898
* First of two entry points for this test library.
9999
* To be invoked as an test argument to authCommandsLib.runTests().
100100
*/
101-
function runOneTest(conn, t) {
101+
export function runOneTest(conn, t) {
102102
var failures = [];
103103

104104
// Some tests requires mongot, however, setting this failpoint will make search queries to
@@ -133,7 +133,7 @@ function runOneTest(conn, t) {
133133
* Second entry point for this test library.
134134
* To be invoked as an test argument to authCommandsLib.runTests().
135135
*/
136-
function createUsers(conn) {
136+
export function createUsers(conn) {
137137
var adminDb = conn.getDB(adminDbName);
138138
adminDb.createUser({user: "admin", pwd: "password", roles: ["__system"]});
139139

0 commit comments

Comments
 (0)