From adbc29e06ebf142a3c14091db20b5e8a23bb8980 Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Tue, 1 Apr 2014 14:07:20 -0400 Subject: SERVER-13441 getUser and getRole shell helpers shouldn't throw when user/role not found (cherry picked from commit abf252cfe8833ab15dc8d62e8e05a30108484508) --- jstests/auth/user_defined_roles_on_secondaries.js | 2 +- jstests/core/role_management_helpers.js | 8 ++++---- jstests/core/user_management_helpers.js | 2 +- src/mongo/shell/db.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/jstests/auth/user_defined_roles_on_secondaries.js b/jstests/auth/user_defined_roles_on_secondaries.js index eb51445616a..1ef357fb2d8 100644 --- a/jstests/auth/user_defined_roles_on_secondaries.js +++ b/jstests/auth/user_defined_roles_on_secondaries.js @@ -129,7 +129,7 @@ rstest.nodes.forEach(function (node) { // Verify that dropping roles propagates. rstest.getMaster().getDB("db1").dropRole("r2", { w: 2}); rstest.nodes.forEach(function (node) { - assert.throws(function() { node.getDB("db1").getRole("r2") }, [], node); + assert.eq(null, node.getDB("db1").getRole("r2")); var role = node.getDB("db1").getRole("r3"); assert.eq(1, role.roles.length, node); assertListContainsRole(role.roles, {role: "r1", db: "db1"}, node); diff --git a/jstests/core/role_management_helpers.js b/jstests/core/role_management_helpers.js index 1cb821975ef..761bd61e77b 100644 --- a/jstests/core/role_management_helpers.js +++ b/jstests/core/role_management_helpers.js @@ -123,15 +123,15 @@ function assertHasPrivilege(privilegeArray, privilege) { // Test dropRole db.dropRole('roleC'); - assert.throws(function() {db.getRole('roleC')}); + assert.eq(null, db.getRole('roleC')); roleObj = db.getRole("roleB", {showPrivileges: true}); assert.eq(0, roleObj.privileges.length); assert.eq(0, roleObj.roles.length); // Test dropAllRoles db.dropAllRoles(); - assert.throws(function() {db.getRole('roleA')}); - assert.throws(function() {db.getRole('roleB')}); - assert.throws(function() {db.getRole('roleC')}); + assert.eq(null, db.getRole('roleA')); + assert.eq(null, db.getRole('roleB')); + assert.eq(null, db.getRole('roleC')); }(db)); \ No newline at end of file diff --git a/jstests/core/user_management_helpers.js b/jstests/core/user_management_helpers.js index 50707f584ab..b79f15e1816 100644 --- a/jstests/core/user_management_helpers.js +++ b/jstests/core/user_management_helpers.js @@ -65,7 +65,7 @@ function assertHasRole(rolesArray, roleName, roleDB) { // Test dropUser db.dropUser('andy'); - assert.throws(function() {printjson(db.getUser('andy'));}); + assert.eq(null, db.getUser('andy')); // Test dropAllUsers db.dropAllUsers() diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index d656a7703f8..e9572e7d8cb 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -1261,7 +1261,7 @@ DB.prototype.getUser = function(username, args) { } if (res.users.length == 0) { - throw Error("User " + username + "@" + db.getName() + " not found"); + return null; } return res.users[0]; } @@ -1388,7 +1388,7 @@ DB.prototype.getRole = function(rolename, args) { } if (res.roles.length == 0) { - throw Error("Role " + rolename + "@" + db.getName() + " not found"); + return null; } return res.roles[0]; } -- cgit v1.2.1