mongo/jstests/sharding/keys_rotation_interval_sec.js
Zac 591928c619 SERVER-108478 JS formatted by prettier and remove clang-format (#39656)
GitOrigin-RevId: 6c8f6aded47f260aa4f7c231b17dae3302cb1e04
2025-08-21 17:27:09 +00:00

32 lines
1.0 KiB
JavaScript

/**
* Test that the keys on config server are rotated according to the KeysRotationIntervalSec value
*/
import {ShardingTest} from "jstests/libs/shardingtest.js";
const kRotationInterval = 30;
let st = new ShardingTest({
mongos: 1,
shards: {rs0: {nodes: 2}},
other: {configOptions: {setParameter: {"KeysRotationIntervalSec": 30}}},
});
let keys = st.s.getDB("admin").system.keys.find();
// add a few seconds to the expire timestamp to account for rounding that may happen.
let maxExpireTime = Timestamp(Date.now() / 1000 + kRotationInterval * 2 + 5, 0);
assert(keys.count() >= 2);
keys.toArray().forEach(function (key, i) {
assert.hasFields(
key,
["purpose", "key", "expiresAt"],
"key document " + i + ": " + tojson(key) + ", did not have all of the expected fields",
);
assert.lte(
bsonWoCompare(key.expiresAt, maxExpireTime),
0,
"key document " + i + ": " + tojson(key) + "expiresAt value is greater than: " + tojson(maxExpireTime),
);
});
st.stop();