jstests/auth/commands_user_defined_roles.js
/**
 * Run the command specified in 't' with the privileges specified in 'privileges'.
 */
Run the command specified in 't' with the privileges specified in 'privileges'.
Run the command specified in ' t ' with the privileges specified in ' privileges ' .
function testProperAuthorization(conn, t, testcase, privileges) {
    const runOnDb = conn.getDB(testcase.runOnDb);
    const state = doTestSetup(conn.sidechannel, t, testcase, privileges);
    authCommandsLib.authenticatedSetup(t, runOnDb);
    let command = t.command;
    if (typeof (command) === "function") {
        command = t.command(state, testcase.commandArgs);
    }
    const res = runOnDb.runCommand(command);
    let out = "";
    if (!testcase.expectFail && (res.ok != 1) && (res.code != commandNotSupportedCode)) {
        out = "command failed with " + tojson(res) + " on db " + testcase.runOnDb +
            " with privileges " + tojson(privileges);
    } else if (testcase.expectFail && res.code == authErrCode) {
        out = "expected authorization success" +
            " but received " + tojson(res) + " on db " + testcase.runOnDb + " with privileges " +
            tojson(privileges);
    }
    doTestTeardown(conn.sidechannel, t, testcase, res);
    return out;
}
function testProperAuthorization ( conn , t , testcase , privileges ) { const runOnDb = conn . getDB ( testcase . runOnDb ) ; const state = doTestSetup ( conn . sidechannel , t , testcase , privileges ) ; authCommandsLib . authenticatedSetup ( t , runOnDb ) ; let command = t . command ; if ( typeof ( command ) === "function" ) { command = t . command ( state , testcase . commandArgs ) ; } const res = runOnDb . runCommand ( command ) ; let out = "" ; if ( ! testcase . expectFail && ( res . ok != 1 ) && ( res . code != commandNotSupportedCode ) ) { out = "command failed with " + tojson ( res ) + " on db " + testcase . runOnDb + " with privileges " + tojson ( privileges ) ; } else if ( testcase . expectFail && res . code == authErrCode ) { out = "expected authorization success" + " but received " + tojson ( res ) + " on db " + testcase . runOnDb + " with privileges " + tojson ( privileges ) ; } doTestTeardown ( conn . sidechannel , t , testcase , res ) ; return out ; }
Run the command specified in 't' with the privileges specified in 'privileges'.
Run the command specified in ' t ' with the privileges specified in ' privileges ' .
// don't error if the test failed with code commandNotSupported since // some storage engines don't support some commands.