Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SERVER-12384 Add tests for dropUser and dropRole functionality

  • Loading branch information...
commit 60949db97b08252d6c763bd645c70eed5c7b56dc 1 parent e014928
@stbrody stbrody authored
View
39 jstests/auth/role_management_commands.js
@@ -9,7 +9,10 @@ function runTest(conn) {
var userAdminConn = new Mongo(conn.host);
var testUserAdmin = userAdminConn.getDB('test');
var adminUserAdmin = userAdminConn.getDB('admin');
- adminUserAdmin.createUser({user: 'userAdmin', pwd: 'pwd', roles: ['userAdminAnyDatabase']});
+ adminUserAdmin.createRole({role: 'myUserAdminRole',
+ roles: ['userAdminAnyDatabase'],
+ privileges: []});
+ adminUserAdmin.createUser({user: 'userAdmin', pwd: 'pwd', roles: ['myUserAdminRole']});
adminUserAdmin.auth('userAdmin', 'pwd');
testUserAdmin.createUser({user: 'testUser', pwd: 'pwd', roles:[]});
var db = conn.getDB('test');
@@ -215,7 +218,7 @@ function runTest(conn) {
actions: ['insert', 'update', 'find']}]);
assert.doesNotThrow(function() {db.foo.findOne();});
db.foo.insert({a:1});
- assert.gleSuccess(db, authzErrorCode);
+ assert.gleSuccess(db);
assert.eq(7, db.foo.count());
db.foo.update({}, {$inc: {a:1}}, false, true);
assert.gleErrorCode(db, authzErrorCode);
@@ -257,6 +260,38 @@ function runTest(conn) {
res = testUserAdmin.runCommand({rolesInfo: 1, showBuiltinRoles: 1});
assert.eq(9, res.roles.length);
})();
+
+ (function testDropRole() {
+ jsTestLog("Testing dropRole");
+
+ testUserAdmin.grantRolesToUser('testUser', ['testRole4'])
+
+ assert.doesNotThrow(function() {db.foo.findOne();});
+ db.foo.insert({a:1});
+ assert.gleSuccess(db, authzErrorCode);
+ assert.eq(8, db.foo.count());
+
+ assert.commandWorked(testUserAdmin.runCommand({dropRole: 'testRole2'}));
+
+ assert.doesNotThrow(function() {db.foo.findOne();});
+ db.foo.insert({a:1});
+ assert.gleErrorCode(db, authzErrorCode);
+ assert.eq(8, db.foo.count());
+
+ assert.eq(3, testUserAdmin.getRoles().length);
+ })();
+
+ (function testDropAllRolesFromDatabase() {
+ jsTestLog("Testing dropAllRolesFromDatabase");
+
+ assert.doesNotThrow(function() {db.foo.findOne();});
+ assert.eq(3, testUserAdmin.getRoles().length);
+
+ assert.commandWorked(testUserAdmin.runCommand({dropAllRolesFromDatabase: 1}));
+
+ assert.throws(function() {db.foo.findOne();});
+ assert.eq(0, testUserAdmin.getRoles().length);
+ })();
}
jsTest.log('Test standalone');
View
26 jstests/auth/user_management_commands.js
@@ -184,6 +184,32 @@ function runTest(conn) {
}
})();
+
+ (function testDropUser() {
+ jsTestLog("Testing dropUser");
+
+ assert(db.auth('spencer', 'password'));
+ assert(db.auth('andy', 'pwd'));
+
+ assert.commandWorked(testUserAdmin.runCommand({dropUser: 'spencer'}));
+
+ assert(!db.auth('spencer', 'password'));
+ assert(db.auth('andy', 'pwd'));
+
+ assert.eq(1, testUserAdmin.getUsers().length);
+ })();
+
+ (function testDropAllUsersFromDatabase() {
+ jsTestLog("Testing dropAllUsersFromDatabase");
+
+ assert.eq(1, testUserAdmin.getUsers().length);
+ assert(db.auth('andy', 'pwd'));
+
+ assert.commandWorked(testUserAdmin.runCommand({dropAllUsersFromDatabase: 1}));
+
+ assert(!db.auth('andy', 'pwd'));
+ assert.eq(0, testUserAdmin.getUsers().length);
+ })();
}
jsTest.log('Test standalone');
Please sign in to comment.
Something went wrong with that request. Please try again.