summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/auth_reject_mismatching_logical_times.js
diff options
context:
space:
mode:
authorclang-format-7.0.1 <adam.martin@10gen.com>2019-07-26 18:42:24 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2019-07-26 18:42:24 -0400
commitc1a45ebbb0530e3d0201321d725527f1eb83ffce (patch)
treef523079dc5ded3052eefbdcaae424b7502df5b25 /jstests/noPassthrough/auth_reject_mismatching_logical_times.js
parentc9599d8610c3da0b7c3da65667aff821063cf5b9 (diff)
downloadmongo-c1a45ebbb0530e3d0201321d725527f1eb83ffce.tar.gz
Apply formatting per `clang-format-7.0.1`
Diffstat (limited to 'jstests/noPassthrough/auth_reject_mismatching_logical_times.js')
-rw-r--r--jstests/noPassthrough/auth_reject_mismatching_logical_times.js109
1 files changed, 54 insertions, 55 deletions
diff --git a/jstests/noPassthrough/auth_reject_mismatching_logical_times.js b/jstests/noPassthrough/auth_reject_mismatching_logical_times.js
index c67482ae5b9..ca4e3da965c 100644
--- a/jstests/noPassthrough/auth_reject_mismatching_logical_times.js
+++ b/jstests/noPassthrough/auth_reject_mismatching_logical_times.js
@@ -4,73 +4,72 @@
* @tags: [requires_replication, requires_sharding]
*/
(function() {
- "use strict";
+"use strict";
- // Given a valid cluster time object, returns one with the same signature, but a mismatching
- // cluster time.
- function mismatchingLogicalTime(lt) {
- return Object.merge(lt, {clusterTime: Timestamp(lt.clusterTime.getTime() + 100, 0)});
- }
+// Given a valid cluster time object, returns one with the same signature, but a mismatching
+// cluster time.
+function mismatchingLogicalTime(lt) {
+ return Object.merge(lt, {clusterTime: Timestamp(lt.clusterTime.getTime() + 100, 0)});
+}
- function assertRejectsMismatchingLogicalTime(db) {
- let validTime = db.runCommand({isMaster: 1}).$clusterTime;
- let mismatchingTime = mismatchingLogicalTime(validTime);
+function assertRejectsMismatchingLogicalTime(db) {
+ let validTime = db.runCommand({isMaster: 1}).$clusterTime;
+ let mismatchingTime = mismatchingLogicalTime(validTime);
- assert.commandFailedWithCode(
- db.runCommand({isMaster: 1, $clusterTime: mismatchingTime}),
- ErrorCodes.TimeProofMismatch,
- "expected command with mismatching cluster time and signature to be rejected");
- }
+ assert.commandFailedWithCode(
+ db.runCommand({isMaster: 1, $clusterTime: mismatchingTime}),
+ ErrorCodes.TimeProofMismatch,
+ "expected command with mismatching cluster time and signature to be rejected");
+}
- function assertAcceptsValidLogicalTime(db) {
- let validTime = db.runCommand({isMaster: 1}).$clusterTime;
- assert.commandWorked(
- testDB.runCommand({isMaster: 1, $clusterTime: validTime}),
- "expected command with valid cluster time and signature to be accepted");
- }
+function assertAcceptsValidLogicalTime(db) {
+ let validTime = db.runCommand({isMaster: 1}).$clusterTime;
+ assert.commandWorked(testDB.runCommand({isMaster: 1, $clusterTime: validTime}),
+ "expected command with valid cluster time and signature to be accepted");
+}
- // Start the sharding test with auth on.
- // TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
- const st = new ShardingTest({
- mongos: 1,
- manualAddShard: true,
- other: {keyFile: "jstests/libs/key1", shardAsReplicaSet: false}
- });
+// Start the sharding test with auth on.
+// TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
+const st = new ShardingTest({
+ mongos: 1,
+ manualAddShard: true,
+ other: {keyFile: "jstests/libs/key1", shardAsReplicaSet: false}
+});
- // Create admin user and authenticate as them.
- st.s.getDB("admin").createUser({user: "foo", pwd: "bar", roles: jsTest.adminUserRoles});
- st.s.getDB("admin").auth("foo", "bar");
+// Create admin user and authenticate as them.
+st.s.getDB("admin").createUser({user: "foo", pwd: "bar", roles: jsTest.adminUserRoles});
+st.s.getDB("admin").auth("foo", "bar");
- // Add shard with auth enabled.
- const rst = new ReplSetTest({nodes: 2});
- rst.startSet({keyFile: "jstests/libs/key1", shardsvr: ""});
+// Add shard with auth enabled.
+const rst = new ReplSetTest({nodes: 2});
+rst.startSet({keyFile: "jstests/libs/key1", shardsvr: ""});
- // TODO: Wait for stable recovery timestamp when SERVER-32672 is fixed.
- rst.initiateWithAnyNodeAsPrimary(
- null, "replSetInitiate", {doNotWaitForStableRecoveryTimestamp: true});
- assert.commandWorked(st.s.adminCommand({addShard: rst.getURL()}));
+// TODO: Wait for stable recovery timestamp when SERVER-32672 is fixed.
+rst.initiateWithAnyNodeAsPrimary(
+ null, "replSetInitiate", {doNotWaitForStableRecoveryTimestamp: true});
+assert.commandWorked(st.s.adminCommand({addShard: rst.getURL()}));
- const testDB = st.s.getDB("test");
+const testDB = st.s.getDB("test");
- // Unsharded collections reject mismatching cluster times and accept valid ones.
- assertRejectsMismatchingLogicalTime(testDB);
- assertAcceptsValidLogicalTime(testDB);
+// Unsharded collections reject mismatching cluster times and accept valid ones.
+assertRejectsMismatchingLogicalTime(testDB);
+assertAcceptsValidLogicalTime(testDB);
- // Initialize sharding.
- assert.commandWorked(testDB.adminCommand({enableSharding: "test"}));
- assert.commandWorked(
- testDB.adminCommand({shardCollection: testDB.foo.getFullName(), key: {_id: 1}}));
+// Initialize sharding.
+assert.commandWorked(testDB.adminCommand({enableSharding: "test"}));
+assert.commandWorked(
+ testDB.adminCommand({shardCollection: testDB.foo.getFullName(), key: {_id: 1}}));
- // Sharded collections reject mismatching cluster times and accept valid ones.
- assertRejectsMismatchingLogicalTime(testDB);
- assertAcceptsValidLogicalTime(testDB);
+// Sharded collections reject mismatching cluster times and accept valid ones.
+assertRejectsMismatchingLogicalTime(testDB);
+assertAcceptsValidLogicalTime(testDB);
- // Shards and config servers also reject mismatching times and accept valid ones.
- assertRejectsMismatchingLogicalTime(rst.getPrimary().getDB("test"));
- assertAcceptsValidLogicalTime(rst.getPrimary().getDB("test"));
- assertRejectsMismatchingLogicalTime(st.configRS.getPrimary().getDB("admin"));
- assertAcceptsValidLogicalTime(st.configRS.getPrimary().getDB("admin"));
+// Shards and config servers also reject mismatching times and accept valid ones.
+assertRejectsMismatchingLogicalTime(rst.getPrimary().getDB("test"));
+assertAcceptsValidLogicalTime(rst.getPrimary().getDB("test"));
+assertRejectsMismatchingLogicalTime(st.configRS.getPrimary().getDB("admin"));
+assertAcceptsValidLogicalTime(st.configRS.getPrimary().getDB("admin"));
- st.stop();
- rst.stopSet();
+st.stop();
+rst.stopSet();
})();