summaryrefslogtreecommitdiff
path: root/jstests/tool
diff options
context:
space:
mode:
authorSiddharth Singh <singhsiddharth@gmail.com>2012-05-30 18:10:53 -0400
committerSiddharth Singh <singhsiddharth@gmail.com>2012-06-04 10:06:31 -0400
commit05e09a4763902a17c76b091b2e3f292948199fcd (patch)
tree0e1f230945ade377af4da351086e6b636c0c2448 /jstests/tool
parentf771b167bf6edc931a37436e7b3463759ed7e915 (diff)
downloadmongo-05e09a4763902a17c76b091b2e3f292948199fcd.tar.gz
SERVER-4972 mongorestore restores without no auth
Test for mongorestore on server with --auth allows restore without credentials of colls with no index
Diffstat (limited to 'jstests/tool')
-rw-r--r--jstests/tool/restorewithauth.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/jstests/tool/restorewithauth.js b/jstests/tool/restorewithauth.js
new file mode 100644
index 00000000000..685301bdd94
--- /dev/null
+++ b/jstests/tool/restorewithauth.js
@@ -0,0 +1,76 @@
+/* SERVER-4972
+ * Test for mongorestore on server with --auth allows restore without credentials of colls
+ * with no index
+ */
+/*
+ * 1) Start mongo without auth.
+ * 2) Write to collection
+ * 3) Take dump of the collection using mongodump.
+ * 4) Drop the collection.
+ * 5) Stop mongod from step 1.
+ * 6) Restart mongod with auth.
+ * 7) Add admin user to kick authentication
+ * 8) Try restore without auth credentials. The restore should fail
+ * 9) Try restore with correct auth credentials. The restore should succeed this time.
+ */
+
+var port = allocatePorts(1)[0];
+baseName = "jstests_restorewithauth";
+var conn = startMongod( "--port", port, "--dbpath", "/data/db/" + baseName, "--nohttpinterface",
+ "--nojournal", "--bind_ip", "127.0.0.1" );
+
+// write to ns foo.bar
+var foo = conn.getDB( "foo" );
+for( var i = 0; i < 4; i++ ) {
+ foo["bar"].save( { "x": i } );
+}
+
+// make sure the collection exists
+assert.eq( foo.system.namespaces.count({name: "foo.bar"}), 1 )
+
+//make sure it has no index except _id
+assert.eq( foo.system.indexes.count(), 1 )
+
+// get data dump
+var dumpdir = "/data/db/restorewithauth-dump1/";
+resetDbpath( dumpdir );
+x = runMongoProgram( "mongodump", "--db", "foo", "-h", "127.0.0.1:"+port, "--collection", "bar",
+ "--out", dumpdir );
+
+// now drop the collection
+foo.bar.drop();
+
+// stop mongod
+stopMongod( port );
+
+// start mongod with --auth
+conn = startMongod( "--auth", "--port", port, "--dbpath", "/data/db/" + baseName, "--nohttpinterface",
+ "--nojournal", "--bind_ip", "127.0.0.1" );
+
+// admin user
+var admin = conn.getDB( "admin" )
+admin.addUser( "admin" , "admin" );
+admin.auth( "admin" , "admin" );
+
+var foo = conn.getDB( "foo" )
+
+// make sure no collection with the same name exists
+assert.eq( foo.system.namespaces.count( {name: "foo.bar"}), 0 )
+
+// now try to restore dump
+x = runMongoProgram( "mongorestore", "-h", "127.0.0.1:" + port, "--dir" , dumpdir, "-vvvvv" );
+
+// make sure that the collection isn't restored
+assert.eq( foo.system.namespaces.count({name: "foo.bar"}), 0 )
+
+// now try to restore dump with correct credentials
+x = runMongoProgram( "mongorestore", "-h", "127.0.0.1:" + port, "-d", "foo", "-u", "admin", "-p",
+ "admin", "--dir", dumpdir + "foo/", "-vvvvv");
+
+// make sure that the collection was restored
+assert.eq( foo.system.namespaces.count({name: "foo.bar"}), 1 )
+
+// make sure the collection has 4 documents
+assert.eq( foo.bar.count(), 4 )
+
+stopMongod( port );