2012-05-24 23:55:28 -04:00
|
|
|
// dumpauth.js
|
|
|
|
|
// test mongodump with authentication
|
|
|
|
|
|
2015-03-22 12:08:21 -04:00
|
|
|
var m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
|
2015-04-28 12:37:45 -04:00
|
|
|
var dbName = "admin"
|
|
|
|
|
var colName = "testcol"
|
2015-12-14 12:22:16 -05:00
|
|
|
var profileName = "system.profile"
|
|
|
|
|
var dumpDir = MongoRunner.dataPath + "jstests_tool_dumprestore_dump_system_profile/";
|
2015-04-28 12:37:45 -04:00
|
|
|
db = m.getDB(dbName);
|
2012-05-24 23:55:28 -04:00
|
|
|
|
2014-04-21 18:43:25 -04:00
|
|
|
db.createUser({user: "testuser" , pwd: "testuser", roles: jsTest.adminUserRoles});
|
|
|
|
|
assert( db.auth( "testuser" , "testuser" ) , "auth failed" );
|
|
|
|
|
|
2015-04-28 12:37:45 -04:00
|
|
|
t = db[colName];
|
2012-05-24 23:55:28 -04:00
|
|
|
t.drop();
|
2015-12-14 12:22:16 -05:00
|
|
|
profile = db[profileName];
|
|
|
|
|
profile.drop();
|
2012-05-24 23:55:28 -04:00
|
|
|
|
2015-12-14 12:22:16 -05:00
|
|
|
// Activate profiling, to ensure that system.profile can be dumped with the backup role
|
|
|
|
|
db.setProfilingLevel(2);
|
|
|
|
|
|
|
|
|
|
// Populate the database
|
2012-05-24 23:55:28 -04:00
|
|
|
for(var i = 0; i < 100; i++) {
|
2015-04-28 12:37:45 -04:00
|
|
|
t.save({ "x": i });
|
2012-05-24 23:55:28 -04:00
|
|
|
}
|
2015-12-14 12:22:16 -05:00
|
|
|
assert.gt(profile.count(), 0, "admin.system.profile should have documents");
|
|
|
|
|
assert.eq(t.count(), 100, "testcol should have documents");
|
|
|
|
|
|
|
|
|
|
// Create a user with backup permissions
|
|
|
|
|
db.createUser({user: "backup" , pwd: "password", roles: ["backup"]});
|
2012-05-24 23:55:28 -04:00
|
|
|
|
2015-12-14 12:22:16 -05:00
|
|
|
// Backup the database with the backup user
|
2013-02-13 10:01:34 -05:00
|
|
|
x = runMongoProgram( "mongodump",
|
2015-04-28 12:37:45 -04:00
|
|
|
"--db", dbName,
|
2015-12-14 12:22:16 -05:00
|
|
|
"--out", dumpDir,
|
2013-02-13 10:01:34 -05:00
|
|
|
"--authenticationDatabase=admin",
|
2015-12-14 12:22:16 -05:00
|
|
|
"-u", "backup",
|
|
|
|
|
"-p", "password",
|
|
|
|
|
"-h", "127.0.0.1:"+m.port);
|
2012-05-24 23:55:28 -04:00
|
|
|
assert.eq(x, 0, "mongodump should succeed with authentication");
|
2015-12-14 12:22:16 -05:00
|
|
|
|
|
|
|
|
// Assert that a BSON document for admin.system.profile has been produced
|
|
|
|
|
x = runMongoProgram( "bsondump", dumpDir + "/" + dbName + "/" + profileName + ".bson" );
|
|
|
|
|
assert.eq(x, 0, "bsondump should succeed parsing the profile data");
|