0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/jstests/ssl/ssl_client_bad_certificate_warning.js
Moustafa Maher be39a8421f SERVER-95628 Make rawMongoProgramOutput more robust (#28204)
GitOrigin-RevId: 6b01ab93e5ba70a22cc816931cd464b6f2ddbd13
2024-10-22 22:40:58 +00:00

58 lines
1.6 KiB
JavaScript

// Test mongo shell output logs correct messages when not including certificates or using bad
// certificates.
const SERVER_CERT = "jstests/libs/server.pem";
const CA_CERT = "jstests/libs/ca.pem";
const BAD_CLIENT_CERT = 'jstests/libs/trusted-client.pem';
function testConnect(outputLog, ...args) {
const command = ['mongo', '--host', 'localhost', '--port', mongod.port, '--tls', ...args];
clearRawMongoProgramOutput();
const clientPID = _startMongoProgram({args: command});
assert.soon(function() {
const output = rawMongoProgramOutput(".*");
if (output.includes(outputLog)) {
stopMongoProgramByPid(clientPID);
return true;
}
return false;
});
}
function runTests() {
// --tlsCertificateKeyFile not specifed when mongod was started with --tlsCAFile or
// --tlsClusterCAFile.
testConnect('No SSL certificate provided by peer', '--tlsCAFile', CA_CERT);
// Certificate not signed by CA_CERT used.
testConnect('SSL peer certificate validation failed',
'--tlsCAFile',
CA_CERT,
'--tlsCertificateKeyFile',
BAD_CLIENT_CERT);
}
// Use tlsClusterCAFile
let mongod = MongoRunner.runMongod({
tlsMode: "requireTLS",
tlsCertificateKeyFile: SERVER_CERT,
tlsClusterCAFile: CA_CERT,
tlsCAFile: CA_CERT,
});
runTests();
MongoRunner.stopMongod(mongod);
// Use tlsCAFile
mongod = MongoRunner.runMongod({
tlsMode: "requireTLS",
tlsCertificateKeyFile: SERVER_CERT,
tlsCAFile: CA_CERT,
});
runTests();
MongoRunner.stopMongod(mongod);