0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/auth/arbiter.js
2018-02-08 09:46:57 -05:00

43 lines
1.4 KiB
JavaScript

// Certain commands should be run-able from arbiters under localhost, but not from
// any other nodes in the replset.
// @tags: [requires_replication]
// Arbiters don't replicate the admin.system.keys collection, so they can never validate or sign
// clusterTime. Gossiping a clusterTime to an arbiter as a user other than __system will fail, so we
// skip gossiping for this test.
//
// TODO SERVER-32639: remove this flag.
TestData.skipGossipingClusterTime = true;
var name = "arbiter_localhost_test";
var key = "jstests/libs/key1";
var replTest = new ReplSetTest({name: name, nodes: 3, keyFile: key});
var nodes = replTest.nodeList();
replTest.startSet();
replTest.initiate({
_id: name,
members: [
{"_id": 0, "host": nodes[0], priority: 3},
{"_id": 1, "host": nodes[1]},
{"_id": 2, "host": nodes[2], arbiterOnly: true}
],
});
var primaryAdmin = replTest.nodes[0].getDB("admin");
var arbiterAdmin = replTest.nodes[2].getDB("admin");
var cmd0 = {getCmdLineOpts: 1};
var cmd1 = {getParameter: 1, logLevel: 1};
var cmd2 = {serverStatus: 1};
assert.commandFailedWithCode(primaryAdmin.runCommand(cmd0), 13);
assert.commandFailedWithCode(primaryAdmin.runCommand(cmd1), 13);
assert.commandFailedWithCode(primaryAdmin.runCommand(cmd2), 13);
assert.commandWorked(arbiterAdmin.runCommand(cmd0));
assert.commandWorked(arbiterAdmin.runCommand(cmd1));
assert.commandWorked(arbiterAdmin.runCommand(cmd2));
replTest.stopSet();