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
|
/**
* Validate we can connect over the proxy protocol port with the protocol appended.
* @tags: [requires_fcv_52]
*/
(function() {
if (_isWindows()) {
// The proxy protocol python package currently doesn't support Windows.
return;
}
load("jstests/libs/logv2_helpers.js");
load("jstests/sharding/libs/proxy_protocol.js");
// Test that you can connect to the load balancer port over a proxy.
function testProxyProtocolConnect(ingressPort, egressPort, version) {
'use strict';
let proxy_server = new ProxyProtocolServer(ingressPort, egressPort, version);
proxy_server.start();
let st = new ShardingTest(
{shards: 1, mongos: 1, mongosOptions: {setParameter: {"loadBalancerPort": egressPort}}});
const uri = `mongodb://127.0.0.1:${ingressPort}/?loadBalanced=true`;
const conn = new Mongo(uri);
assert.neq(null, conn, 'Client was unable to connect to the load balancer port');
assert.commandWorked(conn.getDB('admin').runCommand({hello: 1}));
proxy_server.stop();
st.stop();
}
// Test that you can't connect to the load balancer port without being proxied.
function testProxyProtocolConnectFailure(lbPort, sendLoadBalanced) {
'use strict';
let st = new ShardingTest(
{shards: 1, mongos: 1, mongosOptions: {setParameter: {"loadBalancerPort": lbPort}}});
const hostName = st.s.host.substring(0, st.s.host.indexOf(":"));
const uri = `mongodb://${hostName}:${lbPort}/?loadBalanced=${sendLoadBalanced}`;
try {
var conn = new Mongo(uri);
assert(false, 'Client was unable to connect to the load balancer port');
} catch (err) {
assert(checkLog.checkContainsOnceJsonStringMatch(
st.s, 6067900, "msg", "Error while parsing proxy protocol header"),
"Connection failed for some reason other than lacking a proxy protocol header");
}
st.stop();
}
const ingressPort = 21234;
const egressPort = 21235;
testProxyProtocolConnect(ingressPort, egressPort, 1);
testProxyProtocolConnect(ingressPort, egressPort, 2);
testProxyProtocolConnectFailure(egressPort, "true");
testProxyProtocolConnectFailure(egressPort, "false");
})();
|