summaryrefslogtreecommitdiff
path: root/jstests/auth/deleted_recreated_user.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/auth/deleted_recreated_user.js
parentc9599d8610c3da0b7c3da65667aff821063cf5b9 (diff)
downloadmongo-c1a45ebbb0530e3d0201321d725527f1eb83ffce.tar.gz
Apply formatting per `clang-format-7.0.1`
Diffstat (limited to 'jstests/auth/deleted_recreated_user.js')
-rw-r--r--jstests/auth/deleted_recreated_user.js116
1 files changed, 58 insertions, 58 deletions
diff --git a/jstests/auth/deleted_recreated_user.js b/jstests/auth/deleted_recreated_user.js
index 87517f48297..704710107c0 100644
--- a/jstests/auth/deleted_recreated_user.js
+++ b/jstests/auth/deleted_recreated_user.js
@@ -1,74 +1,74 @@
// Test that sessions can not be resumed by deleted and recreated user.
(function() {
- 'use strict';
+'use strict';
- const kInvalidationIntervalSecs = 5;
+const kInvalidationIntervalSecs = 5;
- function runTest(s0, s1) {
- assert(s0);
- assert(s1);
- const admin = s0.getDB('admin');
+function runTest(s0, s1) {
+ assert(s0);
+ assert(s1);
+ const admin = s0.getDB('admin');
- function checkIdType(username) {
- const user = admin.system.users.find({user: username, db: 'admin'}).toArray()[0];
- const id = user._id;
- const userId = user.userId;
- assert.eq(typeof(id), 'string');
- assert.eq(id, 'admin.' + username);
- assert.eq(typeof(userId), 'object');
- assert.eq(tojson(userId).substring(0, 5), 'UUID(');
- }
-
- admin.createUser({user: 'admin', pwd: 'pass', roles: jsTest.adminUserRoles});
- assert(admin.auth('admin', 'pass'));
- checkIdType('admin');
+ function checkIdType(username) {
+ const user = admin.system.users.find({user: username, db: 'admin'}).toArray()[0];
+ const id = user._id;
+ const userId = user.userId;
+ assert.eq(typeof (id), 'string');
+ assert.eq(id, 'admin.' + username);
+ assert.eq(typeof (userId), 'object');
+ assert.eq(tojson(userId).substring(0, 5), 'UUID(');
+ }
- admin.createUser({user: 'user', pwd: 'pass', roles: jsTest.basicUserRoles});
- checkIdType('user');
- admin.logout();
+ admin.createUser({user: 'admin', pwd: 'pass', roles: jsTest.adminUserRoles});
+ assert(admin.auth('admin', 'pass'));
+ checkIdType('admin');
- // Connect as basic user and create a session.
- assert(admin.auth('user', 'pass'));
- assert.writeOK(admin.mycoll.insert({_id: "foo", data: "bar"}));
+ admin.createUser({user: 'user', pwd: 'pass', roles: jsTest.basicUserRoles});
+ checkIdType('user');
+ admin.logout();
- // Perform administrative commands via separate shell.
- function evalCmd(cmd) {
- const uri = 'mongodb://admin:pass@localhost:' + s1.port + '/admin';
- const result = runMongoProgram('./mongo', uri, '--eval', cmd);
- assert.eq(result, 0, "Command failed");
- }
- evalCmd('db.dropUser("user"); ');
- evalCmd('db.createUser({user: "user", pwd: "secret", roles: ["root"]});');
+ // Connect as basic user and create a session.
+ assert(admin.auth('user', 'pass'));
+ assert.writeOK(admin.mycoll.insert({_id: "foo", data: "bar"}));
- if (s0 !== s1) {
- // Wait for twice the invalidation interval when sharding.
- sleep(2 * kInvalidationIntervalSecs * 1000);
- }
+ // Perform administrative commands via separate shell.
+ function evalCmd(cmd) {
+ const uri = 'mongodb://admin:pass@localhost:' + s1.port + '/admin';
+ const result = runMongoProgram('./mongo', uri, '--eval', cmd);
+ assert.eq(result, 0, "Command failed");
+ }
+ evalCmd('db.dropUser("user"); ');
+ evalCmd('db.createUser({user: "user", pwd: "secret", roles: ["root"]});');
- // This should fail due to invalid user session.
- const thrown =
- assert.throws(() => admin.mycoll.find({}).toArray(), [], "Able to find after recreate");
- assert.eq(thrown.code, ErrorCodes.Unauthorized, "Threw something other than unauthorized");
+ if (s0 !== s1) {
+ // Wait for twice the invalidation interval when sharding.
+ sleep(2 * kInvalidationIntervalSecs * 1000);
}
- const mongod = MongoRunner.runMongod({auth: ''});
- runTest(mongod, mongod);
- MongoRunner.stopMongod(mongod);
+ // This should fail due to invalid user session.
+ const thrown =
+ assert.throws(() => admin.mycoll.find({}).toArray(), [], "Able to find after recreate");
+ assert.eq(thrown.code, ErrorCodes.Unauthorized, "Threw something other than unauthorized");
+}
+
+const mongod = MongoRunner.runMongod({auth: ''});
+runTest(mongod, mongod);
+MongoRunner.stopMongod(mongod);
- // TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
- const st = new ShardingTest({
- shards: 1,
- mongos: 2,
- config: 1,
- other: {
- keyFile: 'jstests/libs/key1',
- shardAsReplicaSet: false,
- mongosOptions: {
- setParameter: 'userCacheInvalidationIntervalSecs=' + kInvalidationIntervalSecs,
- },
+// TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
+const st = new ShardingTest({
+ shards: 1,
+ mongos: 2,
+ config: 1,
+ other: {
+ keyFile: 'jstests/libs/key1',
+ shardAsReplicaSet: false,
+ mongosOptions: {
+ setParameter: 'userCacheInvalidationIntervalSecs=' + kInvalidationIntervalSecs,
},
- });
- runTest(st.s0, st.s1);
- st.stop();
+ },
+});
+runTest(st.s0, st.s1);
+st.stop();
})();