Permalink
Browse files

SERVER-7160 Full mongorestore with auth should auth only against the …

…admin db
  • Loading branch information...
1 parent 6bebf26 commit 5eb79913ff0ceb6fbf782d8a1ec965ae95880fb4 @stbrody stbrody committed with milkie Sep 26, 2012
Showing with 45 additions and 5 deletions.
  1. +28 −0 jstests/tool/dumprestore_auth.js
  2. +13 −3 src/mongo/shell/servers_misc.js
  3. +4 −2 src/mongo/tools/tool.cpp
View
28 jstests/tool/dumprestore_auth.js
@@ -0,0 +1,28 @@
+// dumprestore_auth.js
+
+t = new ToolTest("dumprestore_auth", { auth : "" });
+
+c = t.startDB("foo");
+
+adminDB = c.getDB().getSiblingDB('admin');
+adminDB.addUser('admin', 'password');
+adminDB.auth('admin','password');
+
+assert.eq(0 , c.count() , "setup1");
+c.save({ a : 22 });
+assert.eq(1 , c.count() , "setup2");
+
+t.runTool("dump" , "--out" , t.ext, "--username", "admin", "--password", "password");
+
+c.drop();
+assert.eq(0 , c.count() , "after drop");
+
+t.runTool("restore" , "--dir" , t.ext); // Should fail
+assert.eq(0 , c.count() , "after restore without auth");
+
+t.runTool("restore" , "--dir" , t.ext, "--username", "admin", "--password", "password");
+assert.soon("c.findOne()" , "no data after sleep");
+assert.eq(1 , c.count() , "after restore 2");
+assert.eq(22 , c.findOne().a , "after restore 2");
+
+t.stop();
View
16 src/mongo/shell/servers_misc.js
@@ -55,8 +55,9 @@ MongodRunner.prototype.port = function() { return this.port_; }
MongodRunner.prototype.toString = function() { return [ this.port_, this.dbpath_, this.peer_, this.arbiter_ ].toString(); }
-ToolTest = function( name ){
+ToolTest = function( name, extraOptions ){
this.name = name;
+ this.options = extraOptions;
this.port = allocatePorts(1)[0];
this.baseName = "jstests_tool_" + name;
this.root = "/data/db/" + this.baseName;
@@ -69,8 +70,17 @@ ToolTest = function( name ){
ToolTest.prototype.startDB = function( coll ){
assert( ! this.m , "db already running" );
-
- this.m = startMongoProgram( "mongod" , "--port", this.port , "--dbpath" , this.dbpath , "--nohttpinterface", "--noprealloc" , "--smallfiles" , "--bind_ip", "127.0.0.1" );
+
+ var options = {port : this.port,
+ dbpath : this.dbpath,
+ nohttpinterface : "",
+ noprealloc : "",
+ smallfiles : "",
+ bind_ip : "127.0.0.1"};
+
+ Object.extend(options, this.options);
+
+ this.m = startMongoProgram.apply(null, MongoRunner.arrOptions("mongod", options));
this.db = this.m.getDB( this.baseName );
if ( coll )
return this.db.getCollection( coll );
View
6 src/mongo/tools/tool.cpp
@@ -423,8 +423,10 @@ namespace mongo {
}
string errmsg;
- if ( _conn->auth( dbname , _username , _password , errmsg, true, level ) ) {
- return;
+ if (dbname.size()) {
+ if ( _conn->auth( dbname , _username , _password , errmsg, true, level ) ) {
+ return;
+ }
}
// try against the admin db

0 comments on commit 5eb7991

Please sign in to comment.