summaryrefslogtreecommitdiff
path: root/jstests/ssl/ssl_fragment.js
blob: bdb16559a0b43647dc36870e7029600010552c8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * Test that a large request and response works correctly.
 */
(function() {
    'use strict';

    function runTest(conn) {
        // SSL packets have a max size of ~16 kb so to test packet fragmentation support, create a
        // string larger then 16kb.
        const chunk = 'E$%G^56w4v5v54Vv$V@#t2#%t56u7B$ub%6 NU@ Y3qv4Yq%yq4C%yx$%zh';  // random data
        let s = '';
        while (s.length < (8 * 1024 * 1024)) {
            s += chunk;
        }

        const ssl_frag = conn.getCollection('test.ssl_frag');
        assert.writeOK(ssl_frag.insert({_id: "large_str", foo: s}));

        const read = ssl_frag.find({_id: "large_str"}).toArray()[0].foo;
        assert.eq(s, read, "Did not receive value written");
    }

    let options = {
        sslMode: "requireSSL",
        sslPEMKeyFile: "jstests/libs/server.pem",
        networkMessageCompressors: 'disabled',
    };

    let mongosOptions = {
        sslMode: "requireSSL",
        sslPEMKeyFile: "jstests/libs/server.pem",
        networkMessageCompressors: 'disabled',
    };

    if (_isWindows()) {
        // Force the ASIO stack to do small reads which will excerise the schannel buffering code
        // and significantly slow down the test
        options = Object.extend(options,
                                {setParameter: {"failpoint.smallTLSReads": "{'mode':'alwaysOn'}"}});
        mongosOptions = Object.extend(
            mongosOptions, {setParameter: {"failpoint.smallTLSReads": "{'mode':'alwaysOn'}"}});
    }

    const mongod = MongoRunner.runMongod(options);
    runTest(mongod);
    MongoRunner.stopMongod(mongod);

    // TODO: Remove 'shardAsReplicaSet: false' when SERVER-32672 is fixed.
    const st = new ShardingTest({
        shards: 3,
        mongos: 1,
        config: 1,
        other: {
            configOptions: options,
            mongosOptions: mongosOptions,
            shardOptions: options,
            shardAsReplicaSet: false,
        }
    });

    runTest(st.s0);
    st.stop();

})();