2012-05-25 05:55:28 +02:00
|
|
|
// dumpauth.js
|
|
|
|
// test mongodump with authentication
|
|
|
|
|
2015-03-22 17:08:21 +01:00
|
|
|
var m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
|
2016-02-04 18:31:43 +01:00
|
|
|
var dbName = "admin";
|
|
|
|
var colName = "testcol";
|
|
|
|
var profileName = "system.profile";
|
2015-12-14 18:22:16 +01:00
|
|
|
var dumpDir = MongoRunner.dataPath + "jstests_tool_dumprestore_dump_system_profile/";
|
2015-04-28 18:37:45 +02:00
|
|
|
db = m.getDB(dbName);
|
2012-05-25 05:55:28 +02:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
db.createUser({user: "testuser", pwd: "testuser", roles: jsTest.adminUserRoles});
|
|
|
|
assert(db.auth("testuser", "testuser"), "auth failed");
|
2014-04-22 00:43:25 +02:00
|
|
|
|
2015-04-28 18:37:45 +02:00
|
|
|
t = db[colName];
|
2012-05-25 05:55:28 +02:00
|
|
|
t.drop();
|
2015-12-14 18:22:16 +01:00
|
|
|
profile = db[profileName];
|
|
|
|
profile.drop();
|
2012-05-25 05:55:28 +02:00
|
|
|
|
2015-12-14 18:22:16 +01:00
|
|
|
// Activate profiling, to ensure that system.profile can be dumped with the backup role
|
|
|
|
db.setProfilingLevel(2);
|
|
|
|
|
|
|
|
// Populate the database
|
2016-03-09 18:17:50 +01:00
|
|
|
for (var i = 0; i < 100; i++) {
|
|
|
|
t.save({"x": i});
|
2012-05-25 05:55:28 +02:00
|
|
|
}
|
2015-12-14 18:22:16 +01: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
|
2016-03-09 18:17:50 +01:00
|
|
|
db.createUser({user: "backup", pwd: "password", roles: ["backup"]});
|
2012-05-25 05:55:28 +02:00
|
|
|
|
2015-12-14 18:22:16 +01:00
|
|
|
// Backup the database with the backup user
|
2016-06-07 22:01:44 +02:00
|
|
|
var exitCode = MongoRunner.runMongoTool("mongodump", {
|
|
|
|
db: dbName,
|
|
|
|
out: dumpDir,
|
|
|
|
authenticationDatabase: "admin",
|
|
|
|
username: "backup",
|
|
|
|
password: "password",
|
|
|
|
host: "127.0.0.1:" + m.port,
|
|
|
|
});
|
|
|
|
assert.eq(exitCode, 0, "mongodump should succeed with authentication");
|
2015-12-14 18:22:16 +01:00
|
|
|
|
|
|
|
// Assert that a BSON document for admin.system.profile has been produced
|
2016-06-07 22:01:44 +02:00
|
|
|
exitCode =
|
|
|
|
MongoRunner.runMongoTool("bsondump", {}, dumpDir + "/" + dbName + "/" + profileName + ".bson");
|
|
|
|
assert.eq(exitCode, 0, "bsondump should succeed parsing the profile data");
|
2018-02-08 15:46:57 +01:00
|
|
|
MongoRunner.stopMongod(m);
|