jstests/ssl/libs/ssl_helpers.js
/**
 * Takes in two mongod/mongos configuration options and runs a basic
 * sharding test to see if they can work together...
 */
Takes in two mongod/mongos configuration options and runs a basic
sharding test to see if they can work together
Takes in two mongod / mongos configuration options and runs a basic sharding test to see if they can work together
function mixedShardTest(options1, options2, shouldSucceed) {
    let authSucceeded = false;
    try {
         Also, the autosplitter will be turned on automatically with 'enableBalancer: true'. We
         then want to disable the autosplitter, but cannot do so here with 'enableAutoSplit:
         false' because ShardingTest will attempt to call disableAutoSplit(), which it will not be
         authorized to do if auth is enabled.
         Once SERVER-14017 is fixed the "enableBalancer" line can be removed.
         The mongo shell cannot authenticate as the internal __system user in tests that use x509
         for cluster authentication. Choosing the default value for wcMajorityJournalDefault in
         ReplSetTest cannot be done automatically without the shell performing such
         authentication, so in this test we must make the choice explicitly, based on the global
         test options.
        let wcMajorityJournalDefault;
        if (jsTestOptions().noJournal || jsTestOptions().storageEngine == "inMemory") {
            wcMajorityJournalDefault = false;
        } else {
            wcMajorityJournalDefault = true;
        }
        var st = new ShardingTest({
            mongos: [options1],
            config: 1,
            shards: [options1, options2],
            other: {
                enableBalancer: true,
                configOptions: options1,
                writeConcernMajorityJournalDefault: wcMajorityJournalDefault
            },
        });
         Create admin user in case the options include auth
        st.admin.createUser({user: 'admin', pwd: 'pwd', roles: ['root']});
        st.admin.auth('admin', 'pwd');
        authSucceeded = true;
        st.stopBalancer();
        st.disableAutoSplit();
         Test that $lookup works because it causes outgoing connections to be opened
        testShardedLookup(st);
         Test mongos talking to config servers
        var r = st.adminCommand({enableSharding: "test"});
        assert.eq(r, true, "error enabling sharding for this configuration");
        st.ensurePrimaryShard("test", st.shard0.shardName);
        r = st.adminCommand({movePrimary: 'test', to: st.shard1.shardName});
        assert.eq(r, true, "error movePrimary failed for this configuration");
        var db1 = st.getDB("test");
        r = st.adminCommand({shardCollection: "test.col", key: {_id: 1}});
        assert.eq(r, true, "error sharding collection for this configuration");
         Test mongos talking to shards
        var bigstr = Array(1024 * 1024).join("#");
        var bulk = db1.col.initializeUnorderedBulkOp();
        for (var i = 0; i < 128; i++) {
            bulk.insert({_id: i, string: bigstr});
        }
        assert.commandWorked(bulk.execute());
        assert.eq(128, db1.col.count(), "error retrieving documents from cluster");
         Split chunk to make it small enough to move
        assert.commandWorked(st.splitFind("test.col", {_id: 0}));
         Test shards talking to each other
        r = st.getDB('test').adminCommand(
            {moveChunk: 'test.col', find: {_id: 0}, to: st.shard0.shardName});
        assert(r.ok, "error moving chunks: " + tojson(r));
        db1.col.remove({});
    } catch (e) {
        if (shouldSucceed)
            throw e;
         silence error if we should fail...
        print("IMPORTANT! => Test failed when it should have failed...continuing...");
    } finally {
         Authenticate csrs so ReplSetTest.stopSet() can do db hash check.
        if (authSucceeded && st.configRS) {
            st.configRS.nodes.forEach((node) => {
                node.getDB('admin').auth('admin', 'pwd');
            });
        }
         This has to be done in order for failure
         to not prevent future tests from running...
        if (st) {
            if (st.s.fullOptions.clusterAuthMode === 'x509') {
                 Index consistency check during shutdown needs a privileged user to auth as.
                const x509User =
                    'CN=client,OU=KernelUser,O=MongoDB,L=New York City,ST=New York,C=US';
                st.s.getDB('$external')
                    .createUser({user: x509User, roles: [{role: '__system', db: 'admin'}]});
            }
            st.stop();
        }
    }
}
function mixedShardTest ( options1 , options2 , shouldSucceed ) { let authSucceeded = false ; try { let wcMajorityJournalDefault ; if ( jsTestOptions ( ) . noJournal || jsTestOptions ( ) . storageEngine == "inMemory" ) { wcMajorityJournalDefault = false ; } else { wcMajorityJournalDefault = true ; } var st = new ShardingTest ( { mongos : [ options1 ] , config : 1 , shards : [ options1 , options2 ] , other : { enableBalancer : true , configOptions : options1 , writeConcernMajorityJournalDefault : wcMajorityJournalDefault } , } ) ; st . admin . createUser ( { user : 'admin' , pwd : 'pwd' , roles : [ 'root' ] } ) ; st . admin . auth ( 'admin' , 'pwd' ) ; authSucceeded = true ; st . stopBalancer ( ) ; st . disableAutoSplit ( ) ; testShardedLookup ( st ) ; var r = st . adminCommand ( { enableSharding : "test" } ) ; assert . eq ( r , true , "error enabling sharding for this configuration" ) ; st . ensurePrimaryShard ( "test" , st . shard0 . shardName ) ; r = st . adminCommand ( { movePrimary : 'test' , to : st . shard1 . shardName } ) ; assert . eq ( r , true , "error movePrimary failed for this configuration" ) ; var db1 = st . getDB ( "test" ) ; r = st . adminCommand ( { shardCollection : "test.col" , key : { _id : 1 } } ) ; assert . eq ( r , true , "error sharding collection for this configuration" ) ; var bigstr = Array ( 1024 * 1024 ) . join ( "#" ) ; var bulk = db1 . col . initializeUnorderedBulkOp ( ) ; for ( var i = 0 ; i < 128 ; i ++ ) { bulk . insert ( { _id : i , string : bigstr } ) ; } assert . commandWorked ( bulk . execute ( ) ) ; assert . eq ( 128 , db1 . col . count ( ) , "error retrieving documents from cluster" ) ; assert . commandWorked ( st . splitFind ( "test.col" , { _id : 0 } ) ) ; r = st . getDB ( 'test' ) . adminCommand ( { moveChunk : 'test.col' , find : { _id : 0 } , to : st . shard0 . shardName } ) ; assert ( r . ok , "error moving chunks: " + tojson ( r ) ) ; db1 . col . remove ( { } ) ; } catch ( e ) { if ( shouldSucceed ) throw e ; print ( "IMPORTANT! => Test failed when it should have failed...continuing..." ) ; } finally { if ( authSucceeded && st . configRS ) { st . configRS . nodes . forEach ( ( node ) => { node . getDB ( 'admin' ) . auth ( 'admin' , 'pwd' ) ; } ) ; } if ( st ) { if ( st . s . fullOptions . clusterAuthMode === 'x509' ) { const x509User = 'CN=client,OU=KernelUser,O=MongoDB,L=New York City,ST=New York,C=US' ; st . s . getDB ( '$external' ) . createUser ( { user : x509User , roles : [ { role : '__system' , db : 'admin' } ] } ) ; } st . stop ( ) ; } } }
Takes in two mongod/mongos configuration options and runs a basic
 sharding test to see if they can work together...
Takes in two mongod / mongos configuration options and runs a basic sharding test to see if they can work together ...
// Start ShardingTest with enableBalancer because ShardingTest attempts to turn // off the balancer otherwise, which it will not be authorized to do if auth is enabled. // // Also, the autosplitter will be turned on automatically with 'enableBalancer: true'. We // then want to disable the autosplitter, but cannot do so here with 'enableAutoSplit: // false' because ShardingTest will attempt to call disableAutoSplit(), which it will not be // authorized to do if auth is enabled. // // Once SERVER-14017 is fixed the "enableBalancer" line can be removed. // The mongo shell cannot authenticate as the internal __system user in tests that use x509 // for cluster authentication. Choosing the default value for wcMajorityJournalDefault in // ReplSetTest cannot be done automatically without the shell performing such // authentication, so in this test we must make the choice explicitly, based on the global // test options. // Create admin user in case the options include auth // Test that $lookup works because it causes outgoing connections to be opened // Test mongos talking to config servers // Test mongos talking to shards // Split chunk to make it small enough to move // Test shards talking to each other // silence error if we should fail... // Authenticate csrs so ReplSetTest.stopSet() can do db hash check. // This has to be done in order for failure // to not prevent future tests from running... // Index consistency check during shutdown needs a privileged user to auth as.