diff options
Diffstat (limited to 'jstests/ssl_x509')
| -rw-r--r-- | jstests/ssl_x509/sharding_with_x509.js | 123 | ||||
| -rw-r--r-- | jstests/ssl_x509/x509_basic.js | 47 |
2 files changed, 52 insertions, 118 deletions
diff --git a/jstests/ssl_x509/sharding_with_x509.js b/jstests/ssl_x509/sharding_with_x509.js index 32aa5d7db73..1bf668dcbab 100644 --- a/jstests/ssl_x509/sharding_with_x509.js +++ b/jstests/ssl_x509/sharding_with_x509.js @@ -3,9 +3,7 @@ (function() { 'use strict'; -load("jstests/libs/log.js"); // For findMatchingLogLine. - -const x509_options = { +var x509_options = { sslMode: "requireSSL", sslPEMKeyFile: "jstests/libs/server.pem", sslCAFile: "jstests/libs/ca.pem", @@ -14,85 +12,68 @@ const x509_options = { clusterAuthMode: "x509" }; -function runTest() { - // Start ShardingTest with enableBalancer because ShardingTest attempts to turn off the balancer - // otherwise, which it will not be authorized to do. Once SERVER-14017 is fixed the - // "enableBalancer" line could be removed. - const st = new ShardingTest({ - shards: 2, - mongos: 1, - other: { - enableBalancer: true, - configOptions: x509_options, - mongosOptions: x509_options, - rsOptions: x509_options, - shardOptions: x509_options - } - }); - - st.s.getDB('admin').createUser({user: 'admin', pwd: 'pwd', roles: ['root']}); - st.s.getDB('admin').auth('admin', 'pwd'); +// Start ShardingTest with enableBalancer because ShardingTest attempts to turn off the balancer +// otherwise, which it will not be authorized to do. Once SERVER-14017 is fixed the +// "enableBalancer" line could be removed. +var st = new ShardingTest({ + shards: 2, + mongos: 1, + other: { + enableBalancer: true, + configOptions: x509_options, + mongosOptions: x509_options, + rsOptions: x509_options, + shardOptions: x509_options + } +}); - const coll = st.s.getCollection("test.foo"); +st.s.getDB('admin').createUser({user: 'admin', pwd: 'pwd', roles: ['root']}); +st.s.getDB('admin').auth('admin', 'pwd'); - st.shardColl(coll, {insert: 1}, false); +var coll = st.s.getCollection("test.foo"); - // Authenticate the config server and verify that a log line concerning a username change does - // not appear on the config server since we are doing intracluster auth using X509. - st.c0.getDB('admin').auth('admin', 'pwd'); - const globalLog = assert.commandWorked(st.c0.adminCommand({getLog: "global"})); - const fieldMatcher = {msg: "Different user name was supplied to saslSupportedMechs"}; - assert.eq( - null, - findMatchingLogLine(globalLog.log, fieldMatcher), - "Found log line concerning \"Different user name was supplied to saslSupportedMechs\" when we did not expect to."); +st.shardColl(coll, {insert: 1}, false); - print("starting insertion phase"); +print("starting insertion phase"); - // Insert a bunch of data - const toInsert = 2000; - let bulk = coll.initializeUnorderedBulkOp(); - for (let i = 0; i < toInsert; i++) { - bulk.insert({my: "test", data: "to", insert: i}); - } - assert.commandWorked(bulk.execute()); +// Insert a bunch of data +var toInsert = 2000; +var bulk = coll.initializeUnorderedBulkOp(); +for (var i = 0; i < toInsert; i++) { + bulk.insert({my: "test", data: "to", insert: i}); +} +assert.commandWorked(bulk.execute()); - print("starting updating phase"); +print("starting updating phase"); - // Update a bunch of data - const toUpdate = toInsert; - bulk = coll.initializeUnorderedBulkOp(); - for (let i = 0; i < toUpdate; i++) { - const id = coll.findOne({insert: i})._id; - bulk.find({insert: i, _id: id}).update({$inc: {counter: 1}}); - } - assert.commandWorked(bulk.execute()); - - print("starting deletion"); +// Update a bunch of data +var toUpdate = toInsert; +bulk = coll.initializeUnorderedBulkOp(); +for (var i = 0; i < toUpdate; i++) { + var id = coll.findOne({insert: i})._id; + bulk.find({insert: i, _id: id}).update({$inc: {counter: 1}}); +} +assert.commandWorked(bulk.execute()); - // Remove a bunch of data - const toDelete = toInsert / 2; - bulk = coll.initializeUnorderedBulkOp(); - for (let i = 0; i < toDelete; i++) { - bulk.find({insert: i}).removeOne(); - } - assert.commandWorked(bulk.execute()); +print("starting deletion"); - // Make sure the right amount of data is there - assert.eq(coll.find().itcount({my: 'test'}), toInsert / 2); +// Remove a bunch of data +var toDelete = toInsert / 2; +bulk = coll.initializeUnorderedBulkOp(); +for (var i = 0; i < toDelete; i++) { + bulk.find({insert: i}).removeOne(); +} +assert.commandWorked(bulk.execute()); - // Authenticate csrs so ReplSetTest.stopSet() can do db hash check. - if (st.configRS) { - st.configRS.nodes.forEach((node) => { - node.getDB('admin').auth('admin', 'pwd'); - }); - } +// Make sure the right amount of data is there +assert.eq(coll.find().itcount({my: 'test'}), toInsert / 2); - st.stop(); +// Authenticate csrs so ReplSetTest.stopSet() can do db hash check. +if (st.configRS) { + st.configRS.nodes.forEach((node) => { + node.getDB('admin').auth('admin', 'pwd'); + }); } -TestData.enableTestCommands = true; -runTest(); -TestData.enableTestCommands = false; -runTest(); +st.stop(); })(); diff --git a/jstests/ssl_x509/x509_basic.js b/jstests/ssl_x509/x509_basic.js deleted file mode 100644 index 7dad98e824f..00000000000 --- a/jstests/ssl_x509/x509_basic.js +++ /dev/null @@ -1,47 +0,0 @@ -// Check that if a hello command for intracluster auth contains both the saslSupportedMechs field -// for the __system user and a speculativeAuthenticate field for X509, we do not see a log marking -// the changing of the username from __system to that specified in the x509 certificate. -(function() { -'use strict'; - -load("jstests/libs/log.js"); // For findMatchingLogLine. - -const x509_options = { - sslMode: "requireSSL", - sslPEMKeyFile: "jstests/libs/server.pem", - sslCAFile: "jstests/libs/ca.pem", - sslClusterFile: "jstests/libs/cluster_cert.pem", - sslAllowInvalidHostnames: "", - clusterAuthMode: "x509" -}; -const CLIENT_USER = "CN=client,OU=KernelUser,O=MongoDB,L=New York City,ST=New York,C=US"; - -function runTest() { - const mongo = MongoRunner.runMongod(Object.merge(x509_options, {auth: ""})); - - const ext = mongo.getDB("$external"); - ext.createUser({user: CLIENT_USER, roles: []}); - - assert.commandWorked(ext.runCommand({ - hello: 1, - saslSupportedMechs: "local.__system", - speculativeAuthenticate: {authenticate: "1", mechanism: "MONGODB-X509", db: "$external"} - })); - - const profileLevelDB = mongo.getDB("x509_basic"); - const globalLog = assert.commandWorked(profileLevelDB.adminCommand({getLog: 'global'})); - const fieldMatcher = {msg: "Different user name was supplied to saslSupportedMechs"}; - assert.eq( - null, - findMatchingLogLine(globalLog.log, fieldMatcher), - "Found log line concerning \"Different user name was supplied to saslSupportedMechs\" when we did not expect to."); - MongoRunner.stopMongod(mongo); -} - -// Since the logic around this log has special-casing around enableTestCommands, assert that the log -// is absent both when in test-mode and normal mode. -TestData.enableTestCommands = true; -runTest(); -TestData.enableTestCommands = false; -runTest(); -})(); |
