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

49 lines
1.6 KiB
JavaScript

/**
* Tests various failure cases when using certificate selectors on Windows.
*/
import {
requireSSLProvider,
TRUSTED_SERVER_CERT,
} from "jstests/ssl/libs/ssl_helpers.js";
const notFoundError = "failed to find cert";
const badValueError = "Invalid certificate selector value";
const startupFailureTestCases = [
{selector: `thumbprint=DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF`, error: notFoundError},
{selector: `subject=Unknown Test Client`, error: notFoundError},
{selector: `thumbprint=LOL`, error: badValueError},
{
keyFile: TRUSTED_SERVER_CERT,
clusterSelector: `thumbprint=DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF`,
error: notFoundError
},
{
keyFile: TRUSTED_SERVER_CERT,
clusterSelector: `subject=Unknown Test Client`,
error: notFoundError
},
{keyFile: TRUSTED_SERVER_CERT, clusterSelector: `thumbprint=LOL`, error: badValueError},
];
function testStartupFails(testCase) {
jsTestLog(`Running testStartupFails with test case: ${tojson(testCase)}`);
const opts = {
tlsMode: 'requireTLS',
tlsCertificateKeyFile: testCase.keyFile,
tlsCertificateSelector: testCase.selector,
tlsClusterCertificateSelector: testCase.clusterSelector,
tlsAllowInvalidHostnames: "",
setParameter: {tlsUseSystemCA: true},
waitForConnect: true,
};
clearRawMongoProgramOutput();
assert.throws(() => {
MongoRunner.runMongod(opts);
});
assert(rawMongoProgramOutput(".*").includes(testCase.error));
}
requireSSLProvider('windows', function() {
startupFailureTestCases.forEach(test => testStartupFails(test));
});