summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2016-02-26 16:36:34 -0500
committerRandolph Tan <randolph@10gen.com>2016-03-14 15:10:02 -0400
commit1a6f2e7bfdd593d4c43612a192a3b7dd4fc7e537 (patch)
tree5346b9d7b01349cf7c856a298032c53d8e969d43 /jstests
parent3071389ed3476eeb1e6730bbc1f841addf54b383 (diff)
downloadmongo-1a6f2e7bfdd593d4c43612a192a3b7dd4fc7e537.tar.gz
SERVER-22651 Port sync_cluster_config/auth_config_down.js to CSRS
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/auth_no_config_primary.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/jstests/sharding/auth_no_config_primary.js b/jstests/sharding/auth_no_config_primary.js
new file mode 100644
index 00000000000..4c6d04d8b1e
--- /dev/null
+++ b/jstests/sharding/auth_no_config_primary.js
@@ -0,0 +1,50 @@
+/**
+ * Tests authorization when a config server has no primary.
+ *
+ * This test cannot be run on ephemeral storage engines because it requires the users to persist
+ * across a restart.
+ * @tags: [requires_persistence]
+ */
+(function() {
+"use strict";
+
+var st = new ShardingTest({ shards: 1, keyFile: 'jstests/libs/key1' });
+
+st.s.getDB('admin').createUser({ user: 'root', pwd: 'pass', roles: ['root']});
+st.s.getDB('admin').auth('root', 'pass');
+var testDB = st.s.getDB('test');
+testDB.user.insert({ hello: 'world' });
+
+// Kill all secondaries, forcing the current primary to step down.
+st.configRS.getSecondaries().forEach(function(secondaryConn) {
+ MongoRunner.stopMongod(secondaryConn.port);
+});
+
+// Test authenticate through a fresh connection.
+var newConn = new Mongo(st.s.host);
+
+assert.commandFailedWithCode(newConn.getDB('test').runCommand({ find: 'user' }),
+ ErrorCodes.Unauthorized);
+
+newConn.getDB('admin').auth('root', 'pass');
+
+var res = newConn.getDB('test').user.findOne();
+assert.neq(null, res);
+assert.eq('world', res.hello);
+
+// Test authenticate through new mongos.
+var otherMongos = MongoRunner.runMongos({ keyFile : "jstests/libs/key1",
+ configdb : st.s.savedOptions.configdb });
+
+assert.commandFailedWithCode(otherMongos.getDB('test').runCommand({ find: 'user' }),
+ ErrorCodes.Unauthorized);
+
+otherMongos.getDB('admin').auth('root', 'pass');
+
+var res = otherMongos.getDB('test').user.findOne();
+assert.neq(null, res);
+assert.eq('world', res.hello);
+
+st.stop();
+})();
+