Permalink
Browse files

SERVER-12111 Make sure usersInfo can always find users when midway th…

…rough the auth schema upgrade
  • Loading branch information...
stbrody committed Jan 16, 2014
1 parent 5df691c commit 6d52377da1545aef697889a7e83800e80cf93084
@@ -0,0 +1,44 @@
+// Tests that the usersInfo command reports the correct users when authSchemaVersion = 2
+
+// bring up 2.4 mongod
+var mongod = MongoRunner.runMongod({
+ binVersion: '2.4',
+ auth: ''
+});
+
+mongod.getDB('test').addUser({user: 'testUser', pwd: '12345', roles: ['readWrite']});
+mongod.getDB('admin').addUser({user: 'adminUser',
+ pwd: '12345',
+ roles: ['userAdminAnyDatabase', 'clusterAdmin']});
+
+// restart as 2.6
+MongoRunner.stopMongod(mongod);
+mongod = MongoRunner.runMongod({
+ restart: mongod,
+ binVersion: '2.6'
+});
+
+var admin = mongod.getDB('admin');
+assert.eq(1, admin.auth('adminUser', '12345'));
+
+// run the upgrade step once, to put us at auth schema version 2
+var res = admin.runCommand({authSchemaUpgrade: 1, maxSteps: 1});
+printjson(res);
+assert.commandFailedWithCode(res, 77) // OperationIncomplete
+assert(!res.done);
+
+// confirm where we are in the upgrade process
+res = admin.runCommand({getParameter: 1, authSchemaVersion: 1});
+printjson(res);
+assert.eq(1, res.ok);
+assert.eq(2, res.authSchemaVersion);
+
+// now, run usersInfo on the admin database
+var usersInfo = admin.runCommand({usersInfo:1});
+printjson(usersInfo);
+
+// there should be a user reported in the output of usersInfo
+assert.eq(1, usersInfo.users.length, 'usersInfo should find 1 user in the admin db');
+assert.eq("adminUser", usersInfo.users[0].user, 'usersInfo did not find the adminUser@admin user');
+
+MongoRunner.stopMongod(mongod);
@@ -1114,6 +1114,11 @@ namespace mongo {
}
AuthorizationManager* authzManager = getGlobalAuthorizationManager();
+ int authzVersion = authzManager->getAuthorizationVersion();
+ NamespaceString usersNamespace =
+ authzVersion== AuthorizationManager::schemaVersion26Final ?
+ AuthorizationManager::usersCollectionNamespace :
+ AuthorizationManager::usersAltCollectionNamespace;
BSONObjBuilder projection;
if (!args.showCredentials) {
projection.append("credentials", 0);
@@ -1122,7 +1127,7 @@ namespace mongo {
&BSONArrayBuilder::append<BSONObj>;
const boost::function<void(const BSONObj&)> function =
boost::bind(appendBSONObj, &usersArrayBuilder, _1);
- authzManager->queryAuthzDocument(AuthorizationManager::usersCollectionNamespace,
+ authzManager->queryAuthzDocument(usersNamespace,
queryBuilder.done(),
projection.done(),
function);

0 comments on commit 6d52377

Please sign in to comment.