File: auth_copydb.js

package info (click to toggle)
mongodb 1%3A3.2.11-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 196,404 kB
  • sloc: cpp: 1,412,793; ansic: 504,961; python: 78,522; perl: 5,837; sh: 5,661; java: 4,202; makefile: 1,784; pascal: 617; xml: 176; asm: 128
file content (42 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download
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
38
39
40
41
42
// Tests the copydb command on mongos with auth
var runTest = function() {

    var st = new ShardingTest({shards: 1, mongos: 1, keyFile: "jstests/libs/key1"});
    var mongos = st.s0;
    var destAdminDB = mongos.getDB('admin');
    var destTestDB = mongos.getDB('test');

    var sourceMongodConn = MongoRunner.runMongod({});
    var sourceTestDB = sourceMongodConn.getDB('test');

    sourceTestDB.foo.insert({a: 1});

    destAdminDB.createUser({
        user: 'admin',
        pwd: 'password',
        roles: jsTest.adminUserRoles
    });  // Turns on access control enforcement

    jsTestLog("Running copydb that should fail");
    var res = destAdminDB.runCommand(
        {copydb: 1, fromhost: sourceMongodConn.host, fromdb: 'test', todb: 'test'});
    printjson(res);
    assert.commandFailed(res);

    destAdminDB.auth('admin', 'password');
    assert.eq(0, destTestDB.foo.count());  // Be extra sure the copydb didn't secretly succeed.

    jsTestLog("Running copydb that should succeed");
    res = destAdminDB.runCommand(
        {copydb: 1, fromhost: sourceMongodConn.host, fromdb: 'test', todb: 'test'});
    printjson(res);
    assert.commandWorked(res);

    assert.eq(1, destTestDB.foo.count());
    assert.eq(1, destTestDB.foo.findOne().a);

    st.stop();

};

runTest();