summaryrefslogtreecommitdiff
path: root/jstests/sharding/keys_rotation_interval_sec.js
blob: 5924f80386fba0740dfbf3f7fe2ee0801307e875 (plain)
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
/**
 * Test that the keys on config server are rotated according to the KeysRotationIntervalSec value
 */

(function() {
"use strict";
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();
})();