From c4a92236f342852a2f633c8ae0fc8011ca85b543 Mon Sep 17 00:00:00 2001 From: Kristina Date: Thu, 23 Jun 2011 13:32:05 -0400 Subject: [PATCH] fix auth test and missing hook call --- jstests/sharding/auth.js | 45 +++++++++++++++++++++++++++++++++------- s/d_migrate.cpp | 1 + shell/servers.js | 4 +++- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/jstests/sharding/auth.js b/jstests/sharding/auth.js index 71c4388d1e3..559ec2c1fac 100644 --- a/jstests/sharding/auth.js +++ b/jstests/sharding/auth.js @@ -28,7 +28,7 @@ function getShardName(rsTest) { return config._id+"/"+members.join(","); } -var s = new ShardingTest( "auth1", 0 , 0 , 1 , {rs: true, chunksize : 2, extraOptions : {"keyFile" : "jstests/libs/key1"}}); +var s = new ShardingTest( "auth1", 0 , 0 , 1 , {rs: true, extraOptions : {"keyFile" : "jstests/libs/key1"}, noChunkSize : true}); print("logging in first, if there was an unclean shutdown the user might already exist"); login(adminUser); @@ -43,6 +43,19 @@ else { s.getDB(adminUser.db).addUser(adminUser.username, adminUser.password); } +login(adminUser); +s.getDB( "config" ).settings.update( { _id : "chunksize" }, {$set : {value : 1 }}, true ); +printjson(s.getDB("config").runCommand({getlasterror:1})); +printjson(s.getDB("config").settings.find().toArray()); + +print("restart mongos"); +stopMongoProgram(31000); +var opts = { port : 31000, v : 0, configdb : s._configDB, keyFile : "jstests/libs/key1", chunkSize : 1 }; +var conn = startMongos( opts ); +s.s = s._mongos[0] = s["s0"] = conn; + +login(adminUser); + d1 = new ReplSetTest({name : "d1", nodes : 3, startPort : 34000}); d1.startSet({keyFile : "jstests/libs/key2"}); d1.initiate(); @@ -92,7 +105,7 @@ logout(adminUser); print("insert try 1"); s.getDB("test").foo.insert({x:1}); result = s.getDB("test").runCommand({getLastError : 1}); -printjson(result); +assert.eq(result.err, "unauthorized"); logout(adminUser); @@ -101,9 +114,9 @@ login(testUser); print("insert try 2"); s.getDB("test").foo.insert({x:1}); result = s.getDB("test").runCommand({getLastError : 1}); -printjson(result); +assert.eq(result.err, null); -login(adminUser); +logout(testUser); d2 = new ReplSetTest({name : "d2", nodes : 3, startPort : 36000}); d2.startSet({keyFile : "jstests/libs/key1"}); @@ -111,9 +124,13 @@ d2.initiate(); shardName = getShardName(d2); -result = s.adminCommand({addShard : shardName}) +print("adding shard "+shardName); +login(adminUser); +print("logged in"); +result = s.getDB("admin").runCommand({addShard : shardName}) -for (i=0; i<100000; i++) { +var num = 100000; +for (i=0; i 0 && d2Chunks > 0 && d1Chunks+d2Chunks == totalChunks); -assert.eq(s.getDB("test").foo.count(), 100001); +assert.eq(s.getDB("test").foo.count(), num+1); + +s.s.setSlaveOk(); + +var cursor = s.getDB("test").foo.find({x:{$lt : 500}}); + +var count = 0; +while (cursor.hasNext()) { + cursor.next(); + count++; +} + +assert.eq(count, 501); s.stop(); diff --git a/s/d_migrate.cpp b/s/d_migrate.cpp index 94d3b20398a..9e87326f480 100644 --- a/s/d_migrate.cpp +++ b/s/d_migrate.cpp @@ -1529,6 +1529,7 @@ namespace mongo { void migrateThread() { Client::initThread( "migrateThread" ); if (!noauth) { + ShardedConnectionInfo::addHook(); cc().getAuthenticationInfo()->authorize("local", internalSecurity.user); } migrateStatus.go(); diff --git a/shell/servers.js b/shell/servers.js index e138de609f4..4388b5cf4bc 100755 --- a/shell/servers.js +++ b/shell/servers.js @@ -210,7 +210,9 @@ ShardingTest = function( testName , numShards , verboseLevel , numMongos , other this._configDB = localhost + ":30000," + localhost + ":30001," + localhost + ":30002"; this._configConnection = new Mongo( this._configDB ); - this._configConnection.getDB( "config" ).settings.insert( { _id : "chunksize" , value : otherParams.chunksize || 50 } ); + if (!otherParams.noChunkSize) { + this._configConnection.getDB( "config" ).settings.insert( { _id : "chunksize" , value : otherParams.chunksize || 50 } ); + } } else { for ( var i=0; i