summaryrefslogtreecommitdiff
path: root/jstests/auth/pseudo_commands.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/auth/pseudo_commands.js')
-rw-r--r--jstests/auth/pseudo_commands.js260
1 files changed, 136 insertions, 124 deletions
diff --git a/jstests/auth/pseudo_commands.js b/jstests/auth/pseudo_commands.js
index 629b1fde0d3..510f8c71e53 100644
--- a/jstests/auth/pseudo_commands.js
+++ b/jstests/auth/pseudo_commands.js
@@ -49,144 +49,156 @@ function runTest(conn) {
return (res.ok == 1 && res.isdbgrid == 1);
}
-
(function testInprog() {
- jsTestLog("Testing inprog");
-
- var roles = {read: false,
- readAnyDatabase: false,
- readWrite: false,
- readWriteAnyDatabase: false,
- dbAdmin: false,
- dbAdminAnyDatabase: false,
- dbOwner: false,
- clusterMonitor: true,
- clusterManager: false,
- hostManager: false,
- clusterAdmin: true,
- root: true,
- __system: true
- };
-
- var privilege = { resource: {cluster: true}, actions: ['inprog'] };
-
- var testFunc = function(shouldPass) {
- var passed = true;
- try {
- var res = db.currentOp();
- passed = res.ok && !res.hasOwnProperty("errmsg");
- } catch (e) {
- passed = false;
- }
-
- assert.eq(shouldPass, passed);
- if (shouldPass) {
- assert.gte(res.inprog.length, 0);
- }
- };
-
- testProperAuthorization(testFunc, roles, privilege);
- })();
+ jsTestLog("Testing inprog");
+
+ var roles = {
+ read: false,
+ readAnyDatabase: false,
+ readWrite: false,
+ readWriteAnyDatabase: false,
+ dbAdmin: false,
+ dbAdminAnyDatabase: false,
+ dbOwner: false,
+ clusterMonitor: true,
+ clusterManager: false,
+ hostManager: false,
+ clusterAdmin: true,
+ root: true,
+ __system: true
+ };
+
+ var privilege = {
+ resource: {cluster: true},
+ actions: ['inprog']
+ };
+
+ var testFunc = function(shouldPass) {
+ var passed = true;
+ try {
+ var res = db.currentOp();
+ passed = res.ok && !res.hasOwnProperty("errmsg");
+ } catch (e) {
+ passed = false;
+ }
+
+ assert.eq(shouldPass, passed);
+ if (shouldPass) {
+ assert.gte(res.inprog.length, 0);
+ }
+ };
+
+ testProperAuthorization(testFunc, roles, privilege);
+ })();
(function testKillop() {
- jsTestLog("Testing killOp");
-
- var roles = {read: false,
- readAnyDatabase: false,
- readWrite: false,
- readWriteAnyDatabase: false,
- dbAdmin: false,
- dbAdminAnyDatabase: false,
- dbOwner: false,
- clusterMonitor: false,
- clusterManager: false,
- hostManager: true,
- clusterAdmin: true,
- root: true,
- __system: true
- };
-
- var privilege = { resource: {cluster: true}, actions: ['killop'] };
-
- var testFunc = function(shouldPass) {
- var passed = true;
- try {
- var opid;
- if (isMongos(db)) { // opid format different between mongos and mongod
- opid = "shard0000:1234";
- } else {
- opid = 1234;
- }
- var res = db.killOp(opid);
- printjson(res);
- passed = res.ok && !res.errmsg && !res.err && !res['$err'];
- } catch (e) {
- passed = false;
- }
- assert.eq(shouldPass, passed);
- };
-
- testProperAuthorization(testFunc, roles, privilege);
+ jsTestLog("Testing killOp");
+
+ var roles = {
+ read: false,
+ readAnyDatabase: false,
+ readWrite: false,
+ readWriteAnyDatabase: false,
+ dbAdmin: false,
+ dbAdminAnyDatabase: false,
+ dbOwner: false,
+ clusterMonitor: false,
+ clusterManager: false,
+ hostManager: true,
+ clusterAdmin: true,
+ root: true,
+ __system: true
+ };
+
+ var privilege = {
+ resource: {cluster: true},
+ actions: ['killop']
+ };
+
+ var testFunc = function(shouldPass) {
+ var passed = true;
+ try {
+ var opid;
+ if (isMongos(db)) { // opid format different between mongos and mongod
+ opid = "shard0000:1234";
+ } else {
+ opid = 1234;
+ }
+ var res = db.killOp(opid);
+ printjson(res);
+ passed = res.ok && !res.errmsg && !res.err && !res['$err'];
+ } catch (e) {
+ passed = false;
+ }
+ assert.eq(shouldPass, passed);
+ };
+
+ testProperAuthorization(testFunc, roles, privilege);
})();
(function testUnlock() {
- if (isMongos(db)) {
- return; // unlock doesn't work on mongos
- }
-
- jsTestLog("Testing unlock");
-
- var roles = {read: false,
- readAnyDatabase: false,
- readWrite: false,
- readWriteAnyDatabase: false,
- dbAdmin: false,
- dbAdminAnyDatabase: false,
- dbOwner: false,
- clusterMonitor: false,
- clusterManager: false,
- hostManager: true,
- clusterAdmin: true,
- root: true,
- __system: true
- };
-
- var privilege = { resource: {cluster: true}, actions: ['unlock'] };
-
- var testFunc = function(shouldPass) {
- var passed = true;
- try {
- var ret = admin.fsyncLock(); // must be locked first
- // If the storage engine doesnt support fsync lock, we can't proceed
- if (!ret.ok) {
+ if (isMongos(db)) {
+ return; // unlock doesn't work on mongos
+ }
+
+ jsTestLog("Testing unlock");
+
+ var roles = {
+ read: false,
+ readAnyDatabase: false,
+ readWrite: false,
+ readWriteAnyDatabase: false,
+ dbAdmin: false,
+ dbAdminAnyDatabase: false,
+ dbOwner: false,
+ clusterMonitor: false,
+ clusterManager: false,
+ hostManager: true,
+ clusterAdmin: true,
+ root: true,
+ __system: true
+ };
+
+ var privilege = {
+ resource: {cluster: true},
+ actions: ['unlock']
+ };
+
+ var testFunc = function(shouldPass) {
+ var passed = true;
+ try {
+ var ret = admin.fsyncLock(); // must be locked first
+ // If the storage engine doesnt support fsync lock, we can't proceed
+ if (!ret.ok) {
assert.commandFailedWithCode(ret, ErrorCodes.CommandNotSupported);
- assert(shouldPass); // If we get to the storage engine, we better be authorized.
+ assert(
+ shouldPass); // If we get to the storage engine, we better be authorized.
return;
- }
- var res = db.fsyncUnlock();
- printjson(res);
- passed = res.ok && !res.errmsg && !res.err && !res['$err'];
- passed = passed || false; // convert undefined to false
- } catch (e) {
- passed = false;
- }
- if (!passed) {
- admin.fsyncUnlock();
- }
-
- assert.eq(shouldPass, passed);
- };
-
- testProperAuthorization(testFunc, roles, privilege);
- })();
+ }
+ var res = db.fsyncUnlock();
+ printjson(res);
+ passed = res.ok && !res.errmsg && !res.err && !res['$err'];
+ passed = passed || false; // convert undefined to false
+ } catch (e) {
+ passed = false;
+ }
+ if (!passed) {
+ admin.fsyncUnlock();
+ }
+
+ assert.eq(shouldPass, passed);
+ };
+
+ testProperAuthorization(testFunc, roles, privilege);
+ })();
}
jsTest.log('Test standalone');
-var conn = MongoRunner.runMongod({ auth: '' });
+var conn = MongoRunner.runMongod({auth: ''});
runTest(conn);
MongoRunner.stopMongod(conn.port);
jsTest.log('Test sharding');
-var st = new ShardingTest({ shards: 2, config: 3, keyFile: 'jstests/libs/key1' });
+var st = new ShardingTest({shards: 2, config: 3, keyFile: 'jstests/libs/key1'});
runTest(st.s);
st.stop();