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
|
// Check that rotation works for the server certificate
(function() {
"use strict";
load('jstests/ssl/libs/ssl_helpers.js');
const dbPath = MongoRunner.toRealDir("$dataDir/cluster_x509_rotate_test/");
mkdir(dbPath);
copyCertificateFile("jstests/libs/ca.pem", dbPath + "/ca-test.pem");
copyCertificateFile("jstests/libs/server.pem", dbPath + "/server-test.pem");
const mongod = MongoRunner.runMongod({
sslMode: "requireSSL",
sslPEMKeyFile: dbPath + "/server-test.pem",
sslCAFile: dbPath + "/ca-test.pem"
});
// Rotate in new certificates
copyCertificateFile("jstests/libs/trusted-ca.pem", dbPath + "/ca-test.pem");
copyCertificateFile("jstests/libs/trusted-server.pem", dbPath + "/server-test.pem");
assert.commandWorked(mongod.getDB("test").rotateCertificates("Rotated!"));
// make sure that mongo is still connected after rotation
assert.commandWorked(mongod.adminCommand({connectionStatus: 1}));
const host = "localhost:" + mongod.port;
// Start shell with old certificates and make sure it can't connect
let out = runMongoProgram("mongo",
"--host",
host,
"--ssl",
"--sslPEMKeyFile",
"jstests/libs/client.pem",
"--sslCAFile",
"jstests/libs/ca.pem",
"--eval",
";");
assert.neq(out, 0, "Mongo invocation did not fail");
// Start shell with new certificates and make sure it can connect
out = runMongoProgram("mongo",
"--host",
host,
"--ssl",
"--sslPEMKeyFile",
"jstests/libs/trusted-client.pem",
"--sslCAFile",
"jstests/libs/trusted-ca.pem",
"--eval",
";");
assert.eq(out, 0, "Mongo invocation failed");
MongoRunner.stopMongod(mongod);
}());
|