summaryrefslogtreecommitdiff
path: root/jstests/multiVersion/dumprestore_24_auth.js
blob: 80dce2736bb308978454e74eee46b79d7c72ba65 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Tests that you can dump user data from 2.4 and restore it to a clean 2.6 system, and that the
// current version of mongodump/mongorestore still support dumping/restoring to and from 2.4.


// The base name to use for various things in the test, including the dbpath and the database name
var testBaseName = "jstests_tool_dumprestore_24_to_26";
var dumpDir = MongoRunner.getAndPrepareDumpDirectory(testBaseName);

function multiVersionDumpRestoreTest(opts) {
    resetDbpath(dumpDir);
    var mongodSource = MongoRunner.runMongod({ binVersion : opts.mongodSourceVersion,
                                               setParameter : "textSearchEnabled=true" });
    var mongodDest = MongoRunner.runMongod({ binVersion : opts.mongodDestVersion,
                                             setParameter : "textSearchEnabled=true" });
    var sourceDB = mongodSource.getDB(testBaseName);
    var sourceAdmin = mongodSource.getDB("admin");
    var destDB = mongodDest.getDB(testBaseName);
    var destAdmin = mongodDest.getDB("admin");

    sourceAdmin.addUser({user: 'adminUser', pwd: 'pwd', roles: ['userAdminAnyDatabase']});
    sourceDB.addUser({user: 'user', pwd: 'pwd', roles: ['readWrite']});

    // Dump using the specified version of mongodump
    MongoRunner.runMongoTool("mongodump", { out : dumpDir, binVersion : opts.mongoDumpVersion,
                                            host : mongodSource.host });

    // Drop the databases
    sourceDB.dropDatabase();
    sourceAdmin.dropDatabase();

    // Restore using the specified version of mongorestore
    MongoRunner.runMongoTool("mongorestore", { dir : dumpDir, binVersion : opts.mongoRestoreVersion,
                                               host : mongodDest.host });

    // Wait until we actually have data or timeout
    assert.soon(function() { return destAdmin.system.users.findOne(); }, "no data after sleep");
    assert.eq(1, destDB.system.users.count());
    assert.eq('user', destDB.system.users.findOne().user);
    assert.eq(1, destAdmin.system.users.count());
    assert.eq('adminUser', destAdmin.system.users.findOne().user);

    if (opts.mongodDestVersion == "latest") {
        var schemaVersion =
            destAdmin.runCommand({getParameter: 1, authSchemaVersion: 1}).authSchemaVersion;
        if (opts.mongodSourceVersion == "2.4") {
            assert.eq(1, schemaVersion);
        } else if (opts.mongodSourceVersion == "latest") {
            assert.eq(3, schemaVersion);
        }
    }

    MongoRunner.stopMongod(mongodSource);
    MongoRunner.stopMongod(mongodDest);
}

multiVersionDumpRestoreTest({mongodSourceVersion: "2.4",
                             mongodDestVersion: "2.4",
                             mongoDumpVersion: "latest",
                             mongoRestoreVersion: "latest"});


print("dumprestore_24_to_26 success!");