SERVER-126213: Ensure we wait upon HMAC keys (#53405)

GitOrigin-RevId: 93a557037e4702b03b8ba7749de0f6a84570c605
This commit is contained in:
nandinibhartiyaMDB 2026-05-07 17:59:17 -05:00 committed by MongoDB Bot
parent 4ec900b6ed
commit 1bff6b8f2e

View File

@ -7,8 +7,9 @@
import {ReplSetTest} from "jstests/libs/replsettest.js";
import {ShardingTest} from "jstests/libs/shardingtest.js";
import {QuerySamplingUtil} from "jstests/sharding/analyze_shard_key/libs/query_sampling_util.js";
function runTest(primary) {
function runTest(primary, hmacKeyConn = primary) {
const dbName = "testDb";
const collName0 = "testColl0";
const collName1 = "testColl1";
@ -18,6 +19,15 @@ function runTest(primary) {
const adminDb = primary.getDB("admin");
assert.commandWorked(adminDb.runCommand({createUser: "super", pwd: "super", roles: ["__system"]}));
assert(adminDb.auth("super", "super"));
// In a sharded cluster, HMAC keys are stored on the config server, not on the shards, so
// awaitHMACKeys must be called on the config server primary. Authenticate there first so the
// find on admin.system.keys is authorized.
if (hmacKeyConn !== primary) {
const hmacAdminDb = hmacKeyConn.getDB("admin");
assert.commandWorked(hmacAdminDb.runCommand({createUser: "super", pwd: "super", roles: ["__system"]}));
assert(hmacAdminDb.auth("super", "super"));
}
QuerySamplingUtil.awaitHMACKeys(hmacKeyConn);
const testDb = adminDb.getSiblingDB(dbName);
const docs = [];
const numDocs = 1000;
@ -117,7 +127,7 @@ function runTest(primary) {
{
const st = new ShardingTest({shards: 1, keyFile: "jstests/libs/key1"});
runTest(st.rs0.getPrimary());
runTest(st.rs0.getPrimary(), st.configRS.getPrimary());
st.stop();
}