src/mongo/shell/replsettest.js
/**
     * For all unauthenticated connections passed in, authenticates them with the '__system' user.
     * If a connection is already authenticated, we will skip authentication for that connection and
     * assume that it already has the correct privileges. It is up to the caller of this function to
     * ensure that the connection is appropriately authenticated.
     */
For all unauthenticated connections passed in, authenticates them with the '__system' user.
If a connection is already authenticated, we will skip authentication for that connection and
assume that it already has the correct privileges. It is up to the caller of this function to
ensure that the connection is appropriately authenticated.
For all unauthenticated connections passed in authenticates them with the ' __system ' user . If a connection is already authenticated we will skip authentication for that connection and assume that it already has the correct privileges . It is up to the caller of this function to ensure that the connection is appropriately authenticated .
function asCluster(conn, fn, keyFileParam = undefined) {
        let connArray = conn;
        if (conn.length == null)
            connArray = [conn];
        const unauthenticatedConns = connArray.filter(connection => {
            const connStatus = connection.adminCommand({connectionStatus: 1, showPrivileges: true});
            const connIsAuthenticated = connStatus.authInfo.authenticatedUsers.length > 0;
            return !connIsAuthenticated;
        });
        const connOptions = connArray[0].fullOptions || {};
        const authMode = connOptions.clusterAuthMode || connArray[0].clusterAuthMode ||
            jsTest.options().clusterAuthMode;
        keyFileParam = keyFileParam || connOptions.keyFile || self.keyFile;
        let needsAuth = (keyFileParam || authMode === "x509" || authMode === "sendX509" ||
                         authMode === "sendKeyFile") &&
            unauthenticatedConns.length > 0;
        if (needsAuth &&
            (connOptions.transitionToAuth !== undefined ||
             (authMode === "x509" && !connArray[0].isTLS()))) {
            needsAuth = false;
        }
        if (needsAuth) {
            return authutil.asCluster(unauthenticatedConns, keyFileParam, fn);
        } else {
            return fn();
        }
    }
function asCluster ( conn , fn , keyFileParam = undefined ) { let connArray = conn ; if ( conn . length == null ) connArray = [ conn ] ; const unauthenticatedConns = connArray . filter ( connection => { const connStatus = connection . adminCommand ( { connectionStatus : 1 , showPrivileges : true } ) ; const connIsAuthenticated = connStatus . authInfo . authenticatedUsers . length > 0 ; return ! connIsAuthenticated ; } ) ; const connOptions = connArray [ 0 ] . fullOptions || { } ; const authMode = connOptions . clusterAuthMode || connArray [ 0 ] . clusterAuthMode || jsTest . options ( ) . clusterAuthMode ; keyFileParam = keyFileParam || connOptions . keyFile || self . keyFile ; let needsAuth = ( keyFileParam || authMode === "x509" || authMode === "sendX509" || authMode === "sendKeyFile" ) && unauthenticatedConns . length > 0 ; if ( needsAuth && ( connOptions . transitionToAuth !== undefined || ( authMode === "x509" && ! connArray [ 0 ] . isTLS ( ) ) ) ) { needsAuth = false ; } if ( needsAuth ) { return authutil . asCluster ( unauthenticatedConns , keyFileParam , fn ) ; } else { return fn ( ) ; } }
For all unauthenticated connections passed in, authenticates them with the '__system' user.
For all unauthenticated connections passed in authenticates them with the ' __system ' user .
// There are few cases where we do not auth // 1. When transitioning to auth // 2. When cluster is running in x509 but shell was not started with TLS (i.e. sslSpecial // suite)