diff options
Diffstat (limited to 'jstests/sharding/auth_copydb.js')
-rw-r--r-- | jstests/sharding/auth_copydb.js | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/jstests/sharding/auth_copydb.js b/jstests/sharding/auth_copydb.js index 6ecb45ac201..8c73214019e 100644 --- a/jstests/sharding/auth_copydb.js +++ b/jstests/sharding/auth_copydb.js @@ -1,44 +1,41 @@ // Tests the copydb command on mongos with auth var runTest = function() { + var st = new ShardingTest({shards: 1, mongos: 1, keyFile: "jstests/libs/key1"}); + var mongos = st.s0; + var destAdminDB = mongos.getDB('admin'); + var destTestDB = mongos.getDB('test'); -var st = new ShardingTest({ shards : 1, - mongos : 1, - keyFile : "jstests/libs/key1"}); -var mongos = st.s0; -var destAdminDB = mongos.getDB('admin'); -var destTestDB = mongos.getDB('test'); + var sourceMongodConn = MongoRunner.runMongod({}); + var sourceTestDB = sourceMongodConn.getDB('test'); -var sourceMongodConn = MongoRunner.runMongod({}); -var sourceTestDB = sourceMongodConn.getDB('test'); + sourceTestDB.foo.insert({a: 1}); -sourceTestDB.foo.insert({a:1}); + destAdminDB.createUser({ + user: 'admin', + pwd: 'password', + roles: jsTest.adminUserRoles + }); // Turns on access control enforcement -destAdminDB.createUser({user: 'admin', pwd: 'password', roles: jsTest.adminUserRoles}); // Turns on access control enforcement + jsTestLog("Running copydb that should fail"); + var res = destAdminDB.runCommand( + {copydb: 1, fromhost: sourceMongodConn.host, fromdb: 'test', todb: 'test'}); + printjson(res); + assert.commandFailed(res); -jsTestLog("Running copydb that should fail"); -var res = destAdminDB.runCommand({copydb:1, - fromhost: sourceMongodConn.host, - fromdb:'test', - todb:'test'}); -printjson(res); -assert.commandFailed(res); + destAdminDB.auth('admin', 'password'); + assert.eq(0, destTestDB.foo.count()); // Be extra sure the copydb didn't secretly succeed. -destAdminDB.auth('admin', 'password'); -assert.eq(0, destTestDB.foo.count()); // Be extra sure the copydb didn't secretly succeed. + jsTestLog("Running copydb that should succeed"); + res = destAdminDB.runCommand( + {copydb: 1, fromhost: sourceMongodConn.host, fromdb: 'test', todb: 'test'}); + printjson(res); + assert.commandWorked(res); -jsTestLog("Running copydb that should succeed"); -res = destAdminDB.runCommand({copydb:1, - fromhost: sourceMongodConn.host, - fromdb:'test', - todb:'test'}); -printjson(res); -assert.commandWorked(res); + assert.eq(1, destTestDB.foo.count()); + assert.eq(1, destTestDB.foo.findOne().a); -assert.eq(1, destTestDB.foo.count()); -assert.eq(1, destTestDB.foo.findOne().a); - -st.stop(); + st.stop(); }; |