0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-24 00:17:37 +01:00
mongodb/jstests/ssl/ssl_weak.js
W. Brad Moore 3cbd53553c SERVER-84397: Use proper SSL options in tests
GitOrigin-RevId: 2ceb3b5faa6e0038e0f6d2f4326241b735b83535
2024-02-01 15:32:18 +00:00

48 lines
1.7 KiB
JavaScript

// Test forcing certificate validation
// This tests that forcing certification validation will prohibit clients without certificates
// from connecting.
// Test that connecting with no client certificate and --tlsAllowConnectionsWithoutCertificates
// (an alias for sslWeakCertificateValidation) connects successfully.
var md = MongoRunner.runMongod({
tlsMode: "requireTLS",
tlsCertificateKeyFile: "jstests/libs/server.pem",
tlsCAFile: "jstests/libs/ca.pem",
tlsAllowConnectionsWithoutCertificates: ""
});
var mongo = runMongoProgram(
"mongo", "--port", md.port, "--tls", "--tlsAllowInvalidCertificates", "--eval", ";");
// 0 is the exit code for success
assert(mongo == 0);
// Test that connecting with a valid client certificate connects successfully.
mongo = runMongoProgram("mongo",
"--port",
md.port,
"--tls",
"--tlsAllowInvalidCertificates",
"--tlsCertificateKeyFile",
"jstests/libs/client.pem",
"--eval",
";");
// 0 is the exit code for success
assert(mongo == 0);
MongoRunner.stopMongod(md);
// Test that connecting with no client certificate and no --tlsAllowConnectionsWithoutCertificates
// fails to connect.
var md2 = MongoRunner.runMongod({
tlsMode: "requireTLS",
tlsCertificateKeyFile: "jstests/libs/server.pem",
tlsCAFile: "jstests/libs/ca.pem"
});
mongo = runMongoProgram(
"mongo", "--port", md2.port, "--tls", "--tlsAllowInvalidCertificates", "--eval", ";");
// 1 is the exit code for failure
assert(mongo == 1);
MongoRunner.stopMongod(md2);