2013-01-18 14:23:52 -05:00
|
|
|
// Test forcing certificate validation
|
|
|
|
|
// This tests that forcing certification validation will prohibit clients without certificates
|
|
|
|
|
// from connecting.
|
|
|
|
|
|
2014-09-08 15:18:34 -04:00
|
|
|
// Test that connecting with no client certificate and --sslAllowConnectionsWithoutCertificates
|
|
|
|
|
// (an alias for sslWeakCertificateValidation) connects successfully.
|
2015-03-22 12:08:42 -04:00
|
|
|
var md = MongoRunner.runMongod({sslMode: "requireSSL",
|
|
|
|
|
sslPEMKeyFile: "jstests/libs/server.pem",
|
|
|
|
|
sslCAFile: "jstests/libs/ca.pem",
|
|
|
|
|
sslAllowConnectionsWithoutCertificates: ""});
|
2013-01-18 14:23:52 -05:00
|
|
|
|
2015-03-22 12:08:42 -04:00
|
|
|
var mongo = runMongoProgram("mongo", "--port", md.port, "--ssl", "--sslAllowInvalidCertificates",
|
2013-01-18 14:23:52 -05:00
|
|
|
"--eval", ";");
|
|
|
|
|
|
|
|
|
|
// 0 is the exit code for success
|
|
|
|
|
assert(mongo==0);
|
|
|
|
|
|
|
|
|
|
// Test that connecting with a valid client certificate connects successfully.
|
2015-03-22 12:08:42 -04:00
|
|
|
mongo = runMongoProgram("mongo", "--port", md.port, "--ssl", "--sslAllowInvalidCertificates",
|
2013-01-18 14:23:52 -05:00
|
|
|
"--sslPEMKeyFile", "jstests/libs/client.pem",
|
|
|
|
|
"--eval", ";");
|
|
|
|
|
|
|
|
|
|
// 0 is the exit code for success
|
|
|
|
|
assert(mongo==0);
|
|
|
|
|
|
|
|
|
|
|
2015-03-22 12:08:42 -04:00
|
|
|
// Test that connecting with no client certificate and no --sslAllowConnectionsWithoutCertificates
|
|
|
|
|
// fails to connect.
|
|
|
|
|
var md2 = MongoRunner.runMongod({sslMode: "requireSSL",
|
|
|
|
|
sslPEMKeyFile: "jstests/libs/server.pem",
|
|
|
|
|
sslCAFile: "jstests/libs/ca.pem"});
|
2013-01-18 14:23:52 -05:00
|
|
|
|
2015-03-22 12:08:42 -04:00
|
|
|
mongo = runMongoProgram("mongo", "--port", md2.port, "--ssl", "--sslAllowInvalidCertificates",
|
2013-01-18 14:23:52 -05:00
|
|
|
"--eval", ";");
|
|
|
|
|
|
|
|
|
|
// 1 is the exit code for failure
|
|
|
|
|
assert(mongo==1);
|