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
|
/**
* This verifies that an invalid authSchema document causes MongoDB to fail to start, except in the
* presence of startupAuthSchemaValidation=false.
*
* @tags: [requires_persistence]
*/
(function() {
const dbpath = MongoRunner.dataPath + "validateAuthSchemaOnStartup/";
resetDbpath(dbpath);
const dbName = "validateAuthSchemaOnStartup";
const authSchemaColl = "system.version";
let mongod = MongoRunner.runMongod({dbpath: dbpath, auth: ""});
let adminDB = mongod.getDB('admin');
// Create a user.
adminDB.createUser(
{user: "root", pwd: "root", roles: [{role: 'userAdminAnyDatabase', db: 'admin'}]});
assert(adminDB.auth("root", "root"));
MongoRunner.stopMongod(mongod);
// Start without auth to corrupt the authSchema document.
mongod = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
adminDB = mongod.getDB('admin');
let currentVersion = adminDB[authSchemaColl].findOne({_id: 'authSchema'}).currentVersion;
// Invalidate the authSchema document.
assert.commandWorked(adminDB[authSchemaColl].update({_id: 'authSchema'}, {currentVersion: 'asdf'}));
MongoRunner.stopMongod(mongod);
// Confirm start up fails, even without --auth.
assert.eq(null, MongoRunner.runMongod({dbpath: dbpath, noCleanData: true}));
// Confirm startup works with the flag to disable validation so the document can be repaired.
mongod = MongoRunner.runMongod(
{dbpath: dbpath, noCleanData: true, setParameter: "startupAuthSchemaValidation=false"});
adminDB = mongod.getDB('admin');
assert.commandWorked(
adminDB[authSchemaColl].update({_id: 'authSchema'}, {currentVersion: currentVersion}));
MongoRunner.stopMongod(mongod);
// Confirm everything is normal again.
mongod = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true, auth: ""});
adminDB = mongod.getDB('admin');
assert(adminDB.auth("root", "root"));
MongoRunner.stopMongod(mongod);
})();
|