Skip to content

CSHARP-734: SOCKS5 Proxy Support #1731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 79 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
21e84d0
CSHARP-734: SOCKS5 Proxy Support
papafe Jun 24, 2025
358987d
Small fix
papafe Jun 24, 2025
bb21a5c
Added options to MongoClient settings
papafe Jun 24, 2025
a8f749f
Added uri options test for proxy options
papafe Jun 24, 2025
6be0f42
Added additional checks on parsing.
papafe Jun 24, 2025
5785036
Small fix
papafe Jul 16, 2025
5aa3e8c
Added base implementation
papafe Jul 17, 2025
985c879
Improvements plus initial tests
papafe Jul 17, 2025
7ada60f
Various corrections
papafe Jul 18, 2025
65a6240
Improvements
papafe Jul 18, 2025
79c9b5e
Various fixes
papafe Jul 18, 2025
c7ebfa5
Simplification
papafe Jul 18, 2025
1fce641
Added comments
papafe Jul 21, 2025
3b4640f
First version of setting class
papafe Jul 22, 2025
99a9a5e
Various fixes
papafe Jul 23, 2025
63412e2
Small improvements
papafe Jul 23, 2025
ac2213e
Added async version
papafe Jul 23, 2025
a73dfb5
Simplifications
papafe Jul 23, 2025
09c771f
Removed unused
papafe Jul 23, 2025
011b3b7
Removed flush and simplified
papafe Jul 23, 2025
593c428
Simplification
papafe Jul 23, 2025
4ae6c98
Fixed auth
papafe Jul 23, 2025
472e560
Removed unused parameters
papafe Jul 23, 2025
b01546d
Fixed whitespace
papafe Jul 23, 2025
9d6b0e5
Added use of async
papafe Jul 23, 2025
bd9b705
Added comments and removed unused methods
papafe Jul 24, 2025
6627173
File scoped namespaces
papafe Jul 24, 2025
d055b5a
Added connection string tests
papafe Jul 24, 2025
5c35e4f
Added MongoClientSettings test
papafe Jul 24, 2025
96d5280
Removed unused using.
papafe Jul 24, 2025
7662a7b
Removed the builder
papafe Jul 29, 2025
b9ea9ef
Added unit tests
papafe Jul 29, 2025
7e3be20
Fixed tests and renaming
papafe Jul 29, 2025
696774b
Removed comment
papafe Jul 29, 2025
6aef0bc
Small correction
papafe Jul 29, 2025
38e1bee
Fixed test
papafe Jul 29, 2025
663e853
Fixed test
papafe Jul 29, 2025
70b9df1
Improved tests
papafe Jul 30, 2025
2274bb6
Improved test.
papafe Jul 30, 2025
45ac5c0
Removed unused parameter.
papafe Jul 31, 2025
5bbc67b
Evergreen test
papafe Aug 4, 2025
15f14f6
Correction
papafe Aug 4, 2025
18e545b
Small fixes
papafe Aug 4, 2025
0f35499
Evergreen improvements
papafe Aug 5, 2025
fe6f629
Test improvements
papafe Aug 5, 2025
5a51b3c
Small improvements and fix
papafe Aug 6, 2025
e11abae
Small fixes
papafe Aug 6, 2025
74c20a9
Small fix
papafe Aug 6, 2025
092f841
Small fix
papafe Aug 6, 2025
7243ab8
Added missing trait.
papafe Aug 6, 2025
a4d943a
Trying to add command check
papafe Aug 11, 2025
3e93864
Corrected the command calculation
papafe Aug 11, 2025
b103679
Corrected API
papafe Aug 11, 2025
167fe10
Small corrections
papafe Aug 11, 2025
1cbe075
Smal fix
papafe Aug 11, 2025
f41e06f
Various small corrections.
papafe Aug 12, 2025
1448c00
Small corrections according to PR.
papafe Aug 13, 2025
e84074b
Small fixes following PR.
papafe Aug 13, 2025
a630377
Other small fixes.
papafe Aug 13, 2025
a0f0d5d
Added disposal of stream and socket
papafe Aug 13, 2025
e5287aa
Fix
papafe Aug 13, 2025
f88c8f8
Removed unnecessary test.
papafe Aug 13, 2025
8b5a974
Added cleanup stage
papafe Aug 13, 2025
15949d5
Testing proxyStreamFactory as a wrapper
papafe Aug 13, 2025
95c891f
Various small fixes
papafe Aug 14, 2025
bd4acfd
Use of LINQ
papafe Aug 14, 2025
1ceafe1
Various fixes
papafe Aug 14, 2025
c513ab9
Added missing docs and fixed error message.
papafe Aug 19, 2025
c8be82c
added comment
papafe Aug 19, 2025
e19b895
Small naming corrections
papafe Aug 19, 2025
433eeda
Remove unused
papafe Aug 19, 2025
5bad18e
Fixed cleanup
papafe Aug 19, 2025
68389be
Removed unused
papafe Aug 19, 2025
eaba61c
Small corrections.
papafe Aug 20, 2025
d860832
Fixed error message.
papafe Aug 21, 2025
f0be68a
Moved tests to their own file.
papafe Aug 21, 2025
fc7c610
CSHARP-5581: Test MONGODB-X509 on cloud-dev (#1757)
papafe Aug 21, 2025
2aa4e43
Removed double definition.
papafe Aug 21, 2025
10f8f07
Correction.
papafe Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ Task("TestLoadBalanced")
Task("TestLoadBalancedNetStandard21").IsDependentOn("TestLoadBalanced");
Task("TestLoadBalancedNet60").IsDependentOn("TestLoadBalanced");

Task("TestSocks5ProxyNet472").IsDependentOn("TestSocks5Proxy");
Task("TestSocks5ProxyNetStandard21").IsDependentOn("TestSocks5Proxy");
Task("TestSocks5ProxyNet60").IsDependentOn("TestSocks5Proxy");

Task("TestCsfleWithMockedKms")
.IsDependentOn("TestLibMongoCrypt")
.DoesForEach(
Expand Down Expand Up @@ -263,6 +267,13 @@ Task("TestX509")

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

Task("TestSocks5Proxy")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/*.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"Socks5Proxy\""));

Task("Package")
.IsDependentOn("PackageNugetPackages");

Expand Down
26 changes: 25 additions & 1 deletion evergreen/cleanup-test-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,29 @@ else
ps -ax | grep mongocryptd
pkill -f 'mongocryptd' || echo 'mongocryptd was already killed or not launched'
# check that it's actually killed
ps -ax | grep mongocryptd
ps -ax | grep mongocryptd
fi

# The proxy server processes have almost certainly already been killed by the evergreen process cleaning though.
# This is just to be sure it already happened and delete the file containing the saved PIDs.

echo "Attempting to kill proxy servers if present and deleting PID file."
PID_FILE="socks5_pids.txt"

if [[ ! -f "$PID_FILE" ]]; then
echo "No PID file found ($PID_FILE)"
exit 0
fi

cat "$PID_FILE" | while read -r pid; do
if [[ -n "$pid" ]]; then
if [[ "$OS" =~ Windows|windows ]]; then
powershell -NoProfile -Command "Stop-Process -Id $pid -Force" 2>$null || \
echo "PID $pid already gone"
else
kill "$pid" 2>/dev/null || echo "PID $pid already gone"
fi
fi
done

rm -f "$PID_FILE"
85 changes: 85 additions & 0 deletions evergreen/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,44 @@ functions:
TARGET="TestX509" \
evergreen/run-tests.sh

setup-socks5-proxy:
- command: shell.exec
params:
background: true
script: |
${PREPARE_SHELL}
MONGODB_URI="${MONGODB_URI}"
# Read the MongoDB URI connection string and extract an arbitrary member's host:port
HOST_PORT=$(echo "$MONGODB_URI" | sed 's|mongodb://||' | cut -d',' -f1)

MAP_ARG="localhost:12345 to $HOST_PORT"
python3 $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "$MAP_ARG" --port 1080 --auth username:p4ssw0rd & PROXY_PID1=$!
python3 $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "$MAP_ARG" --port 1081 & PROXY_PID2=$!

echo "$PROXY_PID1" > socks5_pids.txt
echo "$PROXY_PID2" >> socks5_pids.txt

echo "Started proxies with PIDs: $PROXY_PID1, $PROXY_PID2"

run-socks5-proxy-tests:
- command: shell.exec
type: test
params:
working_dir: "mongo-csharp-driver"
shell: "bash"
script: |
export SOCKS5_PROXY_SERVERS_ENABLED=true
${PREPARE_SHELL}
OS=${OS} \
evergreen/add-ca-certs.sh
SSL=${SSL} \
MONGODB_URI="${MONGODB_URI}" \
TOPOLOGY=${TOPOLOGY} \
OS=${OS} \
FRAMEWORK=${FRAMEWORK} \
TARGET="TestSocks5Proxy" \
evergreen/run-tests.sh

pre:
- func: fetch-source
- func: prepare-resources
Expand Down Expand Up @@ -1237,6 +1275,30 @@ tasks:
vars:
FRAMEWORK: net60

- name: test-socks5-proxy-net472
commands:
- func: bootstrap-mongo-orchestration
- func: setup-socks5-proxy
- func: run-socks5-proxy-tests
vars:
FRAMEWORK: net472

- name: test-socks5-proxy-netstandard21
commands:
- func: bootstrap-mongo-orchestration
- func: setup-socks5-proxy
- func: run-socks5-proxy-tests
vars:
FRAMEWORK: netstandard21

- name: test-socks5-proxy-net60
commands:
- func: bootstrap-mongo-orchestration
- func: setup-socks5-proxy
- func: run-socks5-proxy-tests
vars:
FRAMEWORK: net60

- name: plain-auth-tests
commands:
- func: run-plain-auth-tests
Expand Down Expand Up @@ -2531,6 +2593,29 @@ buildvariants:
tasks:
- name: atlas-search-index-helpers-task-group

# Socks5 Proxy tests
- matrix_name: "socks5-proxy-tests-linux"
matrix_spec: { os: "ubuntu-2004", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
tasks:
- name: test-socks5-proxy-netstandard21
- name: test-socks5-proxy-net60

- matrix_name: "socks5-proxy-tests-windows"
matrix_spec: { os: "windows-64", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
tasks:
- name: test-socks5-proxy-net472
- name: test-socks5-proxy-netstandard21
- name: test-socks5-proxy-net60

- matrix_name: "socks5-proxy-tests-macos"
matrix_spec: { os: "macos-14", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
tasks:
- name: test-socks5-proxy-netstandard21
- name: test-socks5-proxy-net60

# CSFLE tests
- matrix_name: "csfle-with-mocked-kms-tests-windows"
matrix_spec: { os: "windows-64", ssl: "nossl", version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"], topology: ["replicaset"] }
Expand Down
139 changes: 139 additions & 0 deletions specifications/uri-options/tests/proxy-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"tests": [
{
"description": "proxyPort without proxyHost",
"uri": "mongodb://localhost/?proxyPort=1080",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "proxyUsername without proxyHost",
"uri": "mongodb://localhost/?proxyUsername=abc",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "proxyPassword without proxyHost",
"uri": "mongodb://localhost/?proxyPassword=def",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "all other proxy options without proxyHost",
"uri": "mongodb://localhost/?proxyPort=1080&proxyUsername=abc&proxyPassword=def",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "proxyUsername without proxyPassword",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "proxyPassword without proxyUsername",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPassword=def",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "multiple proxyHost parameters",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyHost=localhost2",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "multiple proxyPort parameters",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPort=1234&proxyPort=12345",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "multiple proxyUsername parameters",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc&proxyUsername=def&proxyPassword=123",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "multiple proxyPassword parameters",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc&proxyPassword=123&proxyPassword=456",
"valid": false,
"warning": false,
"hosts": null,
"auth": null,
"options": null
},
{
"description": "only host present",
"uri": "mongodb://localhost/?proxyHost=localhost",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "host and default port present",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPort=1080",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "host and non-default port present",
"uri": "mongodb://localhost/?proxyHost=localhost&proxyPort=12345",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "replicaset, host and non-default port present",
"uri": "mongodb://rs1,rs2,rs3/?proxyHost=localhost&proxyPort=12345",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {}
},
{
"description": "all options present",
"uri": "mongodb://rs1,rs2,rs3/?proxyHost=localhost&proxyPort=12345&proxyUsername=asdf&proxyPassword=qwerty",
"valid": true,
"warning": false,
"hosts": null,
"auth": null,
"options": {}
}
]
}
Loading