diff options
Diffstat (limited to 'jstests/noPassthrough/start_session_command.js')
-rw-r--r-- | jstests/noPassthrough/start_session_command.js | 150 |
1 files changed, 74 insertions, 76 deletions
diff --git a/jstests/noPassthrough/start_session_command.js b/jstests/noPassthrough/start_session_command.js index bb542e255fc..5c2bbd4b38b 100644 --- a/jstests/noPassthrough/start_session_command.js +++ b/jstests/noPassthrough/start_session_command.js @@ -1,103 +1,101 @@ (function() { - 'use strict'; +'use strict'; - // This test makes assertions about the number of sessions, which are not compatible with - // implicit sessions. - TestData.disableImplicitSessions = true; +// This test makes assertions about the number of sessions, which are not compatible with +// implicit sessions. +TestData.disableImplicitSessions = true; - var conn; - var admin; - var foo; - var result; - const request = {startSession: 1}; +var conn; +var admin; +var foo; +var result; +const request = { + startSession: 1 +}; - conn = MongoRunner.runMongod({setParameter: {maxSessions: 2}}); - admin = conn.getDB("admin"); +conn = MongoRunner.runMongod({setParameter: {maxSessions: 2}}); +admin = conn.getDB("admin"); - // ensure that the cache is empty - var serverStatus = assert.commandWorked(admin.adminCommand({serverStatus: 1})); - assert.eq(0, serverStatus.logicalSessionRecordCache.activeSessionsCount); +// ensure that the cache is empty +var serverStatus = assert.commandWorked(admin.adminCommand({serverStatus: 1})); +assert.eq(0, serverStatus.logicalSessionRecordCache.activeSessionsCount); - // test that we can run startSession unauthenticated when the server is running without --auth +// test that we can run startSession unauthenticated when the server is running without --auth - result = admin.runCommand(request); - assert.commandWorked( - result, - "failed test that we can run startSession unauthenticated when the server is running without --auth"); - assert(result.id, "failed test that our session response has an id"); - assert.eq( - result.timeoutMinutes, 30, "failed test that our session record has the correct timeout"); +result = admin.runCommand(request); +assert.commandWorked( + result, + "failed test that we can run startSession unauthenticated when the server is running without --auth"); +assert(result.id, "failed test that our session response has an id"); +assert.eq(result.timeoutMinutes, 30, "failed test that our session record has the correct timeout"); - // test that startSession added to the cache - serverStatus = assert.commandWorked(admin.adminCommand({serverStatus: 1})); - assert.eq(1, serverStatus.logicalSessionRecordCache.activeSessionsCount); +// test that startSession added to the cache +serverStatus = assert.commandWorked(admin.adminCommand({serverStatus: 1})); +assert.eq(1, serverStatus.logicalSessionRecordCache.activeSessionsCount); - // test that we can run startSession authenticated when the server is running without --auth +// test that we can run startSession authenticated when the server is running without --auth - admin.createUser({user: 'user0', pwd: 'password', roles: []}); - admin.auth("user0", "password"); +admin.createUser({user: 'user0', pwd: 'password', roles: []}); +admin.auth("user0", "password"); - result = admin.runCommand(request); - assert.commandWorked( - result, - "failed test that we can run startSession authenticated when the server is running without --auth"); - assert(result.id, "failed test that our session response has an id"); - assert.eq( - result.timeoutMinutes, 30, "failed test that our session record has the correct timeout"); +result = admin.runCommand(request); +assert.commandWorked( + result, + "failed test that we can run startSession authenticated when the server is running without --auth"); +assert(result.id, "failed test that our session response has an id"); +assert.eq(result.timeoutMinutes, 30, "failed test that our session record has the correct timeout"); - assert.commandFailed(admin.runCommand(request), - "failed test that we can't run startSession when the cache is full"); - MongoRunner.stopMongod(conn); +assert.commandFailed(admin.runCommand(request), + "failed test that we can't run startSession when the cache is full"); +MongoRunner.stopMongod(conn); - // +// - conn = MongoRunner.runMongod({auth: "", nojournal: ""}); - admin = conn.getDB("admin"); - foo = conn.getDB("foo"); +conn = MongoRunner.runMongod({auth: "", nojournal: ""}); +admin = conn.getDB("admin"); +foo = conn.getDB("foo"); - // test that we can't run startSession unauthenticated when the server is running with --auth +// test that we can't run startSession unauthenticated when the server is running with --auth - assert.commandFailed( - admin.runCommand(request), - "failed test that we can't run startSession unauthenticated when the server is running with --auth"); +assert.commandFailed( + admin.runCommand(request), + "failed test that we can't run startSession unauthenticated when the server is running with --auth"); - // +// - admin.createUser({user: 'admin', pwd: 'admin', roles: jsTest.adminUserRoles}); - admin.auth("admin", "admin"); - admin.createUser({user: 'user0', pwd: 'password', roles: jsTest.basicUserRoles}); - foo.createUser({user: 'user1', pwd: 'password', roles: jsTest.basicUserRoles}); - admin.createUser({user: 'user2', pwd: 'password', roles: []}); - admin.logout(); +admin.createUser({user: 'admin', pwd: 'admin', roles: jsTest.adminUserRoles}); +admin.auth("admin", "admin"); +admin.createUser({user: 'user0', pwd: 'password', roles: jsTest.basicUserRoles}); +foo.createUser({user: 'user1', pwd: 'password', roles: jsTest.basicUserRoles}); +admin.createUser({user: 'user2', pwd: 'password', roles: []}); +admin.logout(); - // test that we can run startSession authenticated as one user with proper permissions +// test that we can run startSession authenticated as one user with proper permissions - admin.auth("user0", "password"); - result = admin.runCommand(request); - assert.commandWorked( - result, - "failed test that we can run startSession authenticated as one user with proper permissions"); - assert(result.id, "failed test that our session response has an id"); - assert.eq( - result.timeoutMinutes, 30, "failed test that our session record has the correct timeout"); +admin.auth("user0", "password"); +result = admin.runCommand(request); +assert.commandWorked( + result, + "failed test that we can run startSession authenticated as one user with proper permissions"); +assert(result.id, "failed test that our session response has an id"); +assert.eq(result.timeoutMinutes, 30, "failed test that our session record has the correct timeout"); - // test that we cant run startSession authenticated as two users with proper permissions +// test that we cant run startSession authenticated as two users with proper permissions - foo.auth("user1", "password"); - assert.commandFailed( - admin.runCommand(request), - "failed test that we cant run startSession authenticated as two users with proper permissions"); +foo.auth("user1", "password"); +assert.commandFailed( + admin.runCommand(request), + "failed test that we cant run startSession authenticated as two users with proper permissions"); - // test that we cant run startSession authenticated as one user without proper permissions +// test that we cant run startSession authenticated as one user without proper permissions - admin.logout(); - admin.auth("user2", "password"); - assert.commandFailed( - admin.runCommand(request), - "failed test that we cant run startSession authenticated as one user without proper permissions"); +admin.logout(); +admin.auth("user2", "password"); +assert.commandFailed( + admin.runCommand(request), + "failed test that we cant run startSession authenticated as one user without proper permissions"); - // - - MongoRunner.stopMongod(conn); +// +MongoRunner.stopMongod(conn); })(); |