jstests/auth/usersInfo_base.js
// Test behavior and edge cases in usersInfo
Test behavior and edge cases in usersInfo
Test behavior and edge cases in usersInfo
function runTest(conn) {
    let db = conn.getDB("test");
    let emptyDB = conn.getDB("test2");
    let otherDB = conn.getDB("other");
    const userCount = 200;
    for (let i = 0; i < userCount; ++i) {
        assert.commandWorked(db.runCommand({createUser: "user" + i, pwd: "pwd", roles: []}));
    }
    assert.commandWorked(otherDB.runCommand({createUser: "otherUser", pwd: "pwd", roles: []}));
    const allTestInfo = assert.commandWorked(db.runCommand({usersInfo: 1}));
    assert.eq(userCount, allTestInfo.users.length);
    assert.eq(1, assert.commandWorked(db.runCommand({usersInfo: "user12"})).users.length);
    assert.eq(1,
              assert.commandWorked(db.runCommand({usersInfo: {user: "user12", db: "test"}}))
                  .users.length);
    assert.eq(0,
              assert.commandWorked(db.runCommand({usersInfo: {user: "user12", db: "test2"}}))
                  .users.length);
    assert.eq(0, assert.commandWorked(emptyDB.runCommand({usersInfo: "user12"})).users.length);
    assert.eq(0, assert.commandWorked(emptyDB.runCommand({usersInfo: 1})).users.length);
    const allInfo = assert.commandWorked(db.runCommand({usersInfo: {forAllDBs: true}}));
    assert.eq(userCount + 1, allInfo.users.length);
}
function runTest ( conn ) { let db = conn . getDB ( "test" ) ; let emptyDB = conn . getDB ( "test2" ) ; let otherDB = conn . getDB ( "other" ) ; const userCount = 200 ; for ( let i = 0 ; i < userCount ; ++ i ) { assert . commandWorked ( db . runCommand ( { createUser : "user" + i , pwd : "pwd" , roles : [ ] } ) ) ; } assert . commandWorked ( otherDB . runCommand ( { createUser : "otherUser" , pwd : "pwd" , roles : [ ] } ) ) ; const allTestInfo = assert . commandWorked ( db . runCommand ( { usersInfo : 1 } ) ) ; assert . eq ( userCount , allTestInfo . users . length ) ; assert . eq ( 1 , assert . commandWorked ( db . runCommand ( { usersInfo : "user12" } ) ) . users . length ) ; assert . eq ( 1 , assert . commandWorked ( db . runCommand ( { usersInfo : { user : "user12" , db : "test" } } ) ) . users . length ) ; assert . eq ( 0 , assert . commandWorked ( db . runCommand ( { usersInfo : { user : "user12" , db : "test2" } } ) ) . users . length ) ; assert . eq ( 0 , assert . commandWorked ( emptyDB . runCommand ( { usersInfo : "user12" } ) ) . users . length ) ; assert . eq ( 0 , assert . commandWorked ( emptyDB . runCommand ( { usersInfo : 1 } ) ) . users . length ) ; const allInfo = assert . commandWorked ( db . runCommand ( { usersInfo : { forAllDBs : true } } ) ) ; assert . eq ( userCount + 1 , allInfo . users . length ) ; }
Test behavior and edge cases in usersInfo
Test behavior and edge cases in usersInfo
// Check info for all users on the "test" database. // Check we can find a particular user on the "test" database. // No users are found on a database without users. // Check that we can find records for all users on all databases.