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

Draft
wants to merge 55 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a09ba4f
CSHARP-734: SOCKS5 Proxy Support
papafe Jun 24, 2025
6696184
Small fix
papafe Jun 24, 2025
b3020b5
Added options to MongoClient settings
papafe Jun 24, 2025
7931f70
Added uri options test for proxy options
papafe Jun 24, 2025
186df67
Added additional checks on parsing.
papafe Jun 24, 2025
567bfa7
Small fix
papafe Jul 16, 2025
feaa948
Added base implementation
papafe Jul 17, 2025
f8bd6a3
Improvements plus initial tests
papafe Jul 17, 2025
3665a29
Various corrections
papafe Jul 18, 2025
3845931
Improvements
papafe Jul 18, 2025
83cace4
Various fixes
papafe Jul 18, 2025
fad7d42
Simplification
papafe Jul 18, 2025
2ca4b3f
Added comments
papafe Jul 21, 2025
a715fef
First version of setting class
papafe Jul 22, 2025
e710b13
Various fixes
papafe Jul 23, 2025
cbea41d
Small improvements
papafe Jul 23, 2025
d49fff5
Added async version
papafe Jul 23, 2025
74ade29
Simplifications
papafe Jul 23, 2025
b9ceea0
Removed unused
papafe Jul 23, 2025
d2cc5f9
Removed flush and simplified
papafe Jul 23, 2025
fda35a1
Simplification
papafe Jul 23, 2025
a76dc1d
Fixed auth
papafe Jul 23, 2025
8e7570f
Removed unused parameters
papafe Jul 23, 2025
9d23395
Fixed whitespace
papafe Jul 23, 2025
3cfe101
Added use of async
papafe Jul 23, 2025
896292d
Added comments and removed unused methods
papafe Jul 24, 2025
3d1d2bd
File scoped namespaces
papafe Jul 24, 2025
01dfdb1
Added connection string tests
papafe Jul 24, 2025
6064af9
Added MongoClientSettings test
papafe Jul 24, 2025
fb50e10
Removed unused using.
papafe Jul 24, 2025
e78c55d
Removed the builder
papafe Jul 29, 2025
aa676d5
Added unit tests
papafe Jul 29, 2025
2293afb
Fixed tests and renaming
papafe Jul 29, 2025
26fa95b
Removed comment
papafe Jul 29, 2025
a1bb6d3
Small correction
papafe Jul 29, 2025
b57542d
Fixed test
papafe Jul 29, 2025
2df31f3
Fixed test
papafe Jul 29, 2025
35f688e
Improved tests
papafe Jul 30, 2025
35f98d1
Improved test.
papafe Jul 30, 2025
69d5190
Removed unused parameter.
papafe Jul 31, 2025
c64af48
Evergreen test
papafe Aug 4, 2025
cfc32f1
Correction
papafe Aug 4, 2025
05612e1
Small fixes
papafe Aug 4, 2025
3ab4115
Evergreen improvements
papafe Aug 5, 2025
d53fda2
Test improvements
papafe Aug 5, 2025
d84416e
Small improvements and fix
papafe Aug 6, 2025
58ffb77
Small fixes
papafe Aug 6, 2025
57e6354
Small fix
papafe Aug 6, 2025
dfea13d
Small fix
papafe Aug 6, 2025
91fb165
Added missing trait.
papafe Aug 6, 2025
bb34734
Trying to add command check
papafe Aug 11, 2025
d8e1ecd
Corrected the command calculation
papafe Aug 11, 2025
d8569f4
Corrected API
papafe Aug 11, 2025
345614e
Small corrections
papafe Aug 11, 2025
4402181
Smal fix
papafe Aug 11, 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 @@ -229,6 +229,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 @@ -265,6 +269,13 @@ Task("TestCsfleWithGcpKms")
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"CsfleGCPKMS\""));

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
81 changes: 81 additions & 0 deletions evergreen/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,40 @@ functions:
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/run-driver-test.sh
bash $DRIVERS_TOOLS/.evergreen/auth_oidc/k8s/teardown-pod.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 &
python3 $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "$MAP_ARG" --port 1081

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
OS=${OS} \
evergreen/cleanup-test-resources.sh
pre:
- func: fetch-source
- func: prepare-resources
Expand Down Expand Up @@ -1209,6 +1243,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 @@ -2548,6 +2606,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": {}
}
]
}
121 changes: 121 additions & 0 deletions specifications/uri-options/tests/proxy-options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
tests:
-
description: "proxyPort without proxyHost"
uri: "mongodb://localhost/?proxyPort=1080"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "proxyUsername without proxyHost"
uri: "mongodb://localhost/?proxyUsername=abc"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "proxyPassword without proxyHost"
uri: "mongodb://localhost/?proxyPassword=def"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "all other proxy options without proxyHost"
uri: "mongodb://localhost/?proxyPort=1080&proxyUsername=abc&proxyPassword=def"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "proxyUsername without proxyPassword"
uri: "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "proxyPassword without proxyUsername"
uri: "mongodb://localhost/?proxyHost=localhost&proxyPassword=def"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "multiple proxyHost parameters"
uri: "mongodb://localhost/?proxyHost=localhost&proxyHost=localhost2"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "multiple proxyPort parameters"
uri: "mongodb://localhost/?proxyHost=localhost&proxyPort=1234&proxyPort=12345"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "multiple proxyUsername parameters"
uri: "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc&proxyUsername=def&proxyPassword=123"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "multiple proxyPassword parameters"
uri: "mongodb://localhost/?proxyHost=localhost&proxyUsername=abc&proxyPassword=123&proxyPassword=456"
valid: false
warning: false
hosts: ~
auth: ~
options: ~
-
description: "only host present"
uri: "mongodb://localhost/?proxyHost=localhost"
valid: true
warning: false
hosts: ~
auth: ~
options: {}
-
description: "host and default port present"
uri: "mongodb://localhost/?proxyHost=localhost&proxyPort=1080"
valid: true
warning: false
hosts: ~
auth: ~
options: {}
-
description: "host and non-default port present"
uri: "mongodb://localhost/?proxyHost=localhost&proxyPort=12345"
valid: true
warning: false
hosts: ~
auth: ~
options: {}
-
description: "replicaset, host and non-default port present"
uri: "mongodb://rs1,rs2,rs3/?proxyHost=localhost&proxyPort=12345"
valid: true
warning: false
hosts: ~
auth: ~
options: {}
-
description: "all options present"
uri: "mongodb://rs1,rs2,rs3/?proxyHost=localhost&proxyPort=12345&proxyUsername=asdf&proxyPassword=qwerty"
valid: true
warning: false
hosts: ~
auth: ~
options: {}
Loading