Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
161bcb0
CSHARP-734: SOCKS5 Proxy Support
papafe Jun 24, 2025
0467f72
Small fix
papafe Jun 24, 2025
38ca1ab
Added options to MongoClient settings
papafe Jun 24, 2025
558656e
Added uri options test for proxy options
papafe Jun 24, 2025
372262d
Added additional checks on parsing.
papafe Jun 24, 2025
be65cf4
Small fix
papafe Jul 16, 2025
74fd94d
Added base implementation
papafe Jul 17, 2025
9afcac1
Improvements plus initial tests
papafe Jul 17, 2025
1453c60
Various corrections
papafe Jul 18, 2025
0eb374c
Improvements
papafe Jul 18, 2025
35f6c17
Various fixes
papafe Jul 18, 2025
91f60cd
Simplification
papafe Jul 18, 2025
843d6f3
Added comments
papafe Jul 21, 2025
d651145
First version of setting class
papafe Jul 22, 2025
079d9c2
Various fixes
papafe Jul 23, 2025
6aaa7d8
Small improvements
papafe Jul 23, 2025
430ad84
Added async version
papafe Jul 23, 2025
94c42cd
Simplifications
papafe Jul 23, 2025
a329f37
Removed unused
papafe Jul 23, 2025
35a0e48
Removed flush and simplified
papafe Jul 23, 2025
34c8145
Simplification
papafe Jul 23, 2025
4bfd007
Fixed auth
papafe Jul 23, 2025
5a733d6
Removed unused parameters
papafe Jul 23, 2025
e34be95
Fixed whitespace
papafe Jul 23, 2025
c104292
Added use of async
papafe Jul 23, 2025
e49b60f
Added comments and removed unused methods
papafe Jul 24, 2025
eac292d
File scoped namespaces
papafe Jul 24, 2025
d19dd1c
Added connection string tests
papafe Jul 24, 2025
b913f07
Added MongoClientSettings test
papafe Jul 24, 2025
7f3a0c4
Removed unused using.
papafe Jul 24, 2025
ed02b51
Removed the builder
papafe Jul 29, 2025
d2839f1
Added unit tests
papafe Jul 29, 2025
23b30cd
Fixed tests and renaming
papafe Jul 29, 2025
f35e0a4
Removed comment
papafe Jul 29, 2025
e5636aa
Small correction
papafe Jul 29, 2025
532738d
Fixed test
papafe Jul 29, 2025
9cee149
Fixed test
papafe Jul 29, 2025
91887c5
Improved tests
papafe Jul 30, 2025
e46575f
Improved test.
papafe Jul 30, 2025
ccd6e83
Removed unused parameter.
papafe Jul 31, 2025
d537f3d
Evergreen test
papafe Aug 4, 2025
ae5f096
Correction
papafe Aug 4, 2025
95068bc
Small fixes
papafe Aug 4, 2025
678956d
Evergreen improvements
papafe Aug 5, 2025
449bcf5
Test improvements
papafe Aug 5, 2025
cbea7d9
Small improvements and fix
papafe Aug 6, 2025
c35e098
Small fixes
papafe Aug 6, 2025
bec16a5
Small fix
papafe Aug 6, 2025
3ccfc6c
Small fix
papafe Aug 6, 2025
52419d7
Added missing trait.
papafe Aug 6, 2025
48e8d91
Trying to add command check
papafe Aug 11, 2025
ba322d4
Corrected the command calculation
papafe Aug 11, 2025
4ac9e00
Corrected API
papafe Aug 11, 2025
c39f80a
Small corrections
papafe Aug 11, 2025
6f6ac2d
Smal fix
papafe Aug 11, 2025
392fab3
Various small corrections.
papafe Aug 12, 2025
8aa643f
Small corrections according to PR.
papafe Aug 13, 2025
e3d023a
Small fixes following PR.
papafe Aug 13, 2025
fc845c1
Other small fixes.
papafe Aug 13, 2025
11c71a6
Added disposal of stream and socket
papafe Aug 13, 2025
c78fc55
Fix
papafe Aug 13, 2025
065e487
Removed unnecessary test.
papafe Aug 13, 2025
07694b4
Added cleanup stage
papafe Aug 13, 2025
c68e416
Testing proxyStreamFactory as a wrapper
papafe Aug 13, 2025
1f1b051
Various small fixes
papafe Aug 14, 2025
b50a252
Use of LINQ
papafe Aug 14, 2025
cf3d5a5
Various fixes
papafe Aug 14, 2025
67bcc6f
Added missing docs and fixed error message.
papafe Aug 19, 2025
2b68319
added comment
papafe Aug 19, 2025
7d4e234
Small naming corrections
papafe Aug 19, 2025
ae3174e
Remove unused
papafe Aug 19, 2025
cceeff1
Fixed cleanup
papafe Aug 19, 2025
8c4a8e9
Removed unused
papafe Aug 19, 2025
7cadcac
Small corrections.
papafe Aug 20, 2025
1cd9e8d
Fixed error message.
papafe Aug 21, 2025
d316dc2
Moved tests to their own file.
papafe Aug 21, 2025
0f2ab46
CSHARP-5581: Test MONGODB-X509 on cloud-dev (#1757)
papafe Aug 21, 2025
1ab97b1
Removed double definition.
papafe Aug 21, 2025
bc7ec34
Correction.
papafe Aug 21, 2025
c8b702a
Improved exception message.
papafe Aug 25, 2025
0ef36f4
Small correction.
papafe Aug 29, 2025
34d86a2
Added pre-checking of host, username and password length.
papafe Aug 29, 2025
87a0d09
Added explicit error messages.
papafe Aug 29, 2025
8b0c369
Small fixes to tests
papafe Sep 3, 2025
60cf78a
Various small fixes following PR's suggestions
papafe Sep 4, 2025
79fb680
Moved stream extension methods to more appropriate place.
papafe Sep 4, 2025
b4d184a
Corrected order and parameter name.
papafe Sep 4, 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