Skip to content

Commit 96652ed

Browse files
authored
CSHARP-734: SOCKS5 Proxy Support (#1731)
1 parent d03569a commit 96652ed

30 files changed

+1960
-84
lines changed

build.cake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ Task("TestLoadBalanced")
218218
Task("TestLoadBalancedNetStandard21").IsDependentOn("TestLoadBalanced");
219219
Task("TestLoadBalancedNet60").IsDependentOn("TestLoadBalanced");
220220

221+
Task("TestSocks5ProxyNet472").IsDependentOn("TestSocks5Proxy");
222+
Task("TestSocks5ProxyNetStandard21").IsDependentOn("TestSocks5Proxy");
223+
Task("TestSocks5ProxyNet60").IsDependentOn("TestSocks5Proxy");
224+
221225
Task("TestCsfleWithMockedKms")
222226
.IsDependentOn("TestLibMongoCrypt")
223227
.DoesForEach(
@@ -263,6 +267,13 @@ Task("TestX509")
263267

264268
Task("TestX509Net60").IsDependentOn("TestX509");
265269

270+
Task("TestSocks5Proxy")
271+
.IsDependentOn("Build")
272+
.DoesForEach(
273+
items: GetFiles("./**/*.Tests.csproj"),
274+
action: (BuildConfig buildConfig, Path testProject) =>
275+
RunTests(buildConfig, testProject, filter: "Category=\"Socks5Proxy\""));
276+
266277
Task("Package")
267278
.IsDependentOn("PackageNugetPackages");
268279

evergreen/cleanup-test-resources.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,29 @@ else
1313
ps -ax | grep mongocryptd
1414
pkill -f 'mongocryptd' || echo 'mongocryptd was already killed or not launched'
1515
# check that it's actually killed
16-
ps -ax | grep mongocryptd
16+
ps -ax | grep mongocryptd
1717
fi
18+
19+
# The proxy server processes have almost certainly already been killed by the evergreen process cleaning though.
20+
# This is just to be sure it already happened and delete the file containing the saved PIDs.
21+
22+
echo "Attempting to kill proxy servers if present and deleting PID file."
23+
PID_FILE="socks5_pids.txt"
24+
25+
if [[ ! -f "$PID_FILE" ]]; then
26+
echo "No PID file found ($PID_FILE)"
27+
exit 0
28+
fi
29+
30+
cat "$PID_FILE" | while read -r pid; do
31+
if [[ -n "$pid" ]]; then
32+
if [[ "$OS" =~ Windows|windows ]]; then
33+
powershell -NoProfile -Command "Stop-Process -Id $pid -Force" 2>$null || \
34+
echo "PID $pid already gone"
35+
else
36+
kill "$pid" 2>/dev/null || echo "PID $pid already gone"
37+
fi
38+
fi
39+
done
40+
41+
rm -f "$PID_FILE"

evergreen/evergreen.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,44 @@ functions:
10691069
TARGET="TestX509" \
10701070
evergreen/run-tests.sh
10711071
1072+
setup-socks5-proxy:
1073+
- command: shell.exec
1074+
params:
1075+
background: true
1076+
script: |
1077+
${PREPARE_SHELL}
1078+
MONGODB_URI="${MONGODB_URI}"
1079+
# Read the MongoDB URI connection string and extract an arbitrary member's host:port
1080+
HOST_PORT=$(echo "$MONGODB_URI" | sed 's|mongodb://||' | cut -d',' -f1)
1081+
1082+
MAP_ARG="localhost:12345 to $HOST_PORT"
1083+
python3 $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "$MAP_ARG" --port 1080 --auth username:p4ssw0rd & PROXY_PID1=$!
1084+
python3 $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "$MAP_ARG" --port 1081 & PROXY_PID2=$!
1085+
1086+
echo "$PROXY_PID1" > socks5_pids.txt
1087+
echo "$PROXY_PID2" >> socks5_pids.txt
1088+
1089+
echo "Started proxies with PIDs: $PROXY_PID1, $PROXY_PID2"
1090+
1091+
run-socks5-proxy-tests:
1092+
- command: shell.exec
1093+
type: test
1094+
params:
1095+
working_dir: "mongo-csharp-driver"
1096+
shell: "bash"
1097+
script: |
1098+
export SOCKS5_PROXY_SERVERS_ENABLED=true
1099+
${PREPARE_SHELL}
1100+
OS=${OS} \
1101+
evergreen/add-ca-certs.sh
1102+
SSL=${SSL} \
1103+
MONGODB_URI="${MONGODB_URI}" \
1104+
TOPOLOGY=${TOPOLOGY} \
1105+
OS=${OS} \
1106+
FRAMEWORK=${FRAMEWORK} \
1107+
TARGET="TestSocks5Proxy" \
1108+
evergreen/run-tests.sh
1109+
10721110
pre:
10731111
- func: fetch-source
10741112
- func: prepare-resources
@@ -1237,6 +1275,30 @@ tasks:
12371275
vars:
12381276
FRAMEWORK: net60
12391277

1278+
- name: test-socks5-proxy-net472
1279+
commands:
1280+
- func: bootstrap-mongo-orchestration
1281+
- func: setup-socks5-proxy
1282+
- func: run-socks5-proxy-tests
1283+
vars:
1284+
FRAMEWORK: net472
1285+
1286+
- name: test-socks5-proxy-netstandard21
1287+
commands:
1288+
- func: bootstrap-mongo-orchestration
1289+
- func: setup-socks5-proxy
1290+
- func: run-socks5-proxy-tests
1291+
vars:
1292+
FRAMEWORK: netstandard21
1293+
1294+
- name: test-socks5-proxy-net60
1295+
commands:
1296+
- func: bootstrap-mongo-orchestration
1297+
- func: setup-socks5-proxy
1298+
- func: run-socks5-proxy-tests
1299+
vars:
1300+
FRAMEWORK: net60
1301+
12401302
- name: plain-auth-tests
12411303
commands:
12421304
- func: run-plain-auth-tests
@@ -2531,6 +2593,29 @@ buildvariants:
25312593
tasks:
25322594
- name: atlas-search-index-helpers-task-group
25332595

2596+
# Socks5 Proxy tests
2597+
- matrix_name: "socks5-proxy-tests-linux"
2598+
matrix_spec: { os: "ubuntu-2004", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
2599+
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
2600+
tasks:
2601+
- name: test-socks5-proxy-netstandard21
2602+
- name: test-socks5-proxy-net60
2603+
2604+
- matrix_name: "socks5-proxy-tests-windows"
2605+
matrix_spec: { os: "windows-64", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
2606+
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
2607+
tasks:
2608+
- name: test-socks5-proxy-net472
2609+
- name: test-socks5-proxy-netstandard21
2610+
- name: test-socks5-proxy-net60
2611+
2612+
- matrix_name: "socks5-proxy-tests-macos"
2613+
matrix_spec: { os: "macos-14", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
2614+
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
2615+
tasks:
2616+
- name: test-socks5-proxy-netstandard21
2617+
- name: test-socks5-proxy-net60
2618+
25342619
# CSFLE tests
25352620
- matrix_name: "csfle-with-mocked-kms-tests-windows"
25362621
matrix_spec: { os: "windows-64", ssl: "nossl", version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"], topology: ["replicaset"] }
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"tests": [
3+
{
4+
"description": "proxyPort without proxyHost",
5+
"uri": "mongodb://localhost/?proxyPort=1080",
6+
"valid": false,
7+
"warning": false,
8+
"hosts": null,
9+
"auth": null,
10+
"options": null
11+
},
12+
{
13+
"description": "proxyUsername without proxyHost",
14+
"uri": "mongodb://localhost/?proxyUsername=abc",
15+
"valid": false,
16+
"warning": false,
17+
"hosts": null,
18+
"auth": null,
19+
"options": null
20+
},
21+
{
22+
"description": "proxyPassword without proxyHost",
23+
"uri": "mongodb://localhost/?proxyPassword=def",
24+
"valid": false,
25+
"warning": false,
26+
"hosts": null,
27+
"auth": null,
28+
"options": null
29+
},
30+
{
31+
"description": "all other proxy options without proxyHost",
32+
"uri": "mongodb://localhost/?proxyPort=1080&proxyUsername=abc&proxyPassword=def",
33+
"valid": false,
34+
"warning": false,
35+
"hosts": null,
36+
"auth": null,
37+
"options": null
38+
},
39+
{
40+
"description": "proxyUsername without proxyPassword",
41+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc",
42+
"valid": false,
43+
"warning": false,
44+
"hosts": null,
45+
"auth": null,
46+
"options": null
47+
},
48+
{
49+
"description": "proxyPassword without proxyUsername",
50+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPassword=def",
51+
"valid": false,
52+
"warning": false,
53+
"hosts": null,
54+
"auth": null,
55+
"options": null
56+
},
57+
{
58+
"description": "multiple proxyHost parameters",
59+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyHost=localhost2",
60+
"valid": false,
61+
"warning": false,
62+
"hosts": null,
63+
"auth": null,
64+
"options": null
65+
},
66+
{
67+
"description": "multiple proxyPort parameters",
68+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPort=1234&proxyPort=12345",
69+
"valid": false,
70+
"warning": false,
71+
"hosts": null,
72+
"auth": null,
73+
"options": null
74+
},
75+
{
76+
"description": "multiple proxyUsername parameters",
77+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc&proxyUsername=def&proxyPassword=123",
78+
"valid": false,
79+
"warning": false,
80+
"hosts": null,
81+
"auth": null,
82+
"options": null
83+
},
84+
{
85+
"description": "multiple proxyPassword parameters",
86+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc&proxyPassword=123&proxyPassword=456",
87+
"valid": false,
88+
"warning": false,
89+
"hosts": null,
90+
"auth": null,
91+
"options": null
92+
},
93+
{
94+
"description": "only host present",
95+
"uri": "mongodb://localhost/?proxyHost=localhost",
96+
"valid": true,
97+
"warning": false,
98+
"hosts": null,
99+
"auth": null,
100+
"options": {}
101+
},
102+
{
103+
"description": "host and default port present",
104+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPort=1080",
105+
"valid": true,
106+
"warning": false,
107+
"hosts": null,
108+
"auth": null,
109+
"options": {}
110+
},
111+
{
112+
"description": "host and non-default port present",
113+
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPort=12345",
114+
"valid": true,
115+
"warning": false,
116+
"hosts": null,
117+
"auth": null,
118+
"options": {}
119+
},
120+
{
121+
"description": "replicaset, host and non-default port present",
122+
"uri": "mongodb://rs1,rs2,rs3/?proxyHost=localhost&proxyPort=12345",
123+
"valid": true,
124+
"warning": false,
125+
"hosts": null,
126+
"auth": null,
127+
"options": {}
128+
},
129+
{
130+
"description": "all options present",
131+
"uri": "mongodb://rs1,rs2,rs3/?proxyHost=localhost&proxyPort=12345&proxyUsername=asdf&proxyPassword=qwerty",
132+
"valid": true,
133+
"warning": false,
134+
"hosts": null,
135+
"auth": null,
136+
"options": {}
137+
}
138+
]
139+
}

0 commit comments

Comments
 (0)