summaryrefslogtreecommitdiff
path: root/jstests/tool/dumpauth.js
blob: 5edfe1e9f52171c22dae48a396a49be6ae336351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// dumpauth.js
// test mongodump with authentication

var m = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"});
var dbName = "admin"
var colName = "testcol"
db = m.getDB(dbName);

db.createUser({user:  "testuser" , pwd: "testuser", roles: jsTest.adminUserRoles});
assert( db.auth( "testuser" , "testuser" ) , "auth failed" );

t = db[colName];
t.drop();

for(var i = 0; i < 100; i++) {
  t.save({ "x": i });
}

x = runMongoProgram( "mongodump",
                     "--db", dbName,
                     "--authenticationDatabase=admin",
                     "-u", "testuser",
                     "-p", "testuser",
                     "-h", "127.0.0.1:"+m.port,
                     "--collection", colName);
assert.eq(x, 0, "mongodump should succeed with authentication");

// SERVER-5233: mongodump with authentication breaks when using "--out -"
x = runMongoProgram( "mongodump",
                     "--db", dbName,
                     "--authenticationDatabase=admin",
                     "-u", "testuser",
                     "-p", "testuser",
                     "-h", "127.0.0.1:"+m.port,
                     "--collection", colName,
                     "--out", "-" );
assert.eq(x, 0, "mongodump should succeed with authentication while using '--out'");