mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
/**
|
|
* Validate that the shell can load certificates from the certificate store and connect to the
|
|
* server.
|
|
*/
|
|
|
|
load('jstests/ssl/libs/ssl_helpers.js');
|
|
|
|
requireSSLProvider('windows', function() {
|
|
'use strict';
|
|
|
|
if (_isWindows()) {
|
|
// SChannel backed follows Windows rules and only trusts Root in LocalMachine
|
|
runProgram("certutil.exe", "-addstore", "-f", "Root", "jstests\\libs\\trusted-ca.pem");
|
|
|
|
// Import a pfx file since it contains both a cert and private key and is easy to import
|
|
// via command line.
|
|
runProgram(
|
|
"certutil.exe", "-importpfx", "-f", "-p", "foo", "jstests\\libs\\trusted-client.pfx");
|
|
}
|
|
|
|
const conn = MongoRunner.runMongod(
|
|
{sslMode: 'requireSSL', sslPEMKeyFile: "jstests\\libs\\trusted-server.pem"});
|
|
|
|
const testWithCert = function(certSelector) {
|
|
jsTest.log(`Testing with SSL cert ${certSelector}`);
|
|
const argv = [
|
|
'./mongo',
|
|
'--ssl',
|
|
'--sslCertificateSelector',
|
|
certSelector,
|
|
'--port',
|
|
conn.port,
|
|
'--eval',
|
|
'db.runCommand({buildInfo: 1})'
|
|
];
|
|
|
|
const exitStatus = runMongoProgram.apply(null, argv);
|
|
assert.eq(exitStatus, 0, "successfully connected with SSL");
|
|
};
|
|
|
|
assert.doesNotThrow(function() {
|
|
testWithCert("thumbprint=9ca511552f14d3fc2009d425873599bf77832238");
|
|
});
|
|
|
|
assert.doesNotThrow(function() {
|
|
testWithCert("subject=Trusted Kernel Test Client");
|
|
});
|
|
|
|
MongoRunner.stopMongod(conn);
|
|
});
|