Skip to content

Commit 451627a

Browse files
authored
feat(NODE-3633): add Socks5 support (#3041)
1 parent 76fff97 commit 451627a

19 files changed

+1045
-16
lines changed

.evergreen/config.yml

+75
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,54 @@ functions:
293293
export NODE_LTS_NAME='${NODE_LTS_NAME}'
294294
295295
bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
296+
run socks5 tests:
297+
- command: shell.exec
298+
type: test
299+
params:
300+
silent: true
301+
working_dir: src
302+
script: |
303+
${PREPARE_SHELL}
304+
cat <<EOT > prepare_client_encryption.sh
305+
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
306+
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
307+
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
308+
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
309+
export CSFLE_GIT_REF="${CSFLE_GIT_REF}"
310+
export CDRIVER_GIT_REF="${CDRIVER_GIT_REF}"
311+
EOT
312+
- command: shell.exec
313+
type: test
314+
params:
315+
working_dir: src
316+
script: >
317+
${PREPARE_SHELL}
318+
319+
320+
export PYTHON_BINARY=$([ "Windows_NT" = "$OS" ] && echo "/cygdrive/c/python/python38/python.exe" || echo
321+
"/opt/mongodbtoolchain/v3/bin/python3")
322+
323+
export PROJECT_DIRECTORY="$(pwd)"
324+
325+
export DRIVERS_TOOLS="${DRIVERS_TOOLS}"
326+
327+
export NODE_LTS_NAME='${NODE_LTS_NAME}'
328+
329+
export MONGODB_URI="${MONGODB_URI}"
330+
331+
export SSL="${SSL}"
332+
333+
334+
# Disable xtrace (just in case it was accidentally set).
335+
336+
set +x
337+
338+
. ./prepare_client_encryption.sh
339+
340+
rm -f ./prepare_client_encryption.sh
341+
342+
343+
bash ${PROJECT_DIRECTORY}/.evergreen/run-socks5-tests.sh
296344
run kerberos tests:
297345
- command: shell.exec
298346
type: test
@@ -907,6 +955,27 @@ tasks:
907955
commands:
908956
- func: install dependencies
909957
- func: run ldap tests
958+
- name: test-socks5
959+
tags: []
960+
commands:
961+
- func: install dependencies
962+
- func: bootstrap mongo-orchestration
963+
vars:
964+
VERSION: latest
965+
TOPOLOGY: replica_set
966+
- func: run socks5 tests
967+
- name: test-socks5-tls
968+
tags: []
969+
commands:
970+
- func: install dependencies
971+
- func: bootstrap mongo-orchestration
972+
vars:
973+
SSL: ssl
974+
VERSION: latest
975+
TOPOLOGY: replica_set
976+
- func: run socks5 tests
977+
vars:
978+
SSL: ssl
910979
- name: test-ocsp-valid-cert-server-staples
911980
tags:
912981
- ocsp
@@ -1683,6 +1752,8 @@ buildvariants:
16831752
- test-atlas-data-lake
16841753
- test-auth-kerberos
16851754
- test-auth-ldap
1755+
- test-socks5
1756+
- test-socks5-tls
16861757
- test-ocsp-valid-cert-server-staples
16871758
- test-ocsp-invalid-cert-server-staples
16881759
- test-ocsp-valid-cert-server-does-not-staple
@@ -1753,6 +1824,8 @@ buildvariants:
17531824
- test-load-balancer
17541825
- test-auth-kerberos
17551826
- test-auth-ldap
1827+
- test-socks5
1828+
- test-socks5-tls
17561829
- test-ocsp-valid-cert-server-staples
17571830
- test-ocsp-invalid-cert-server-staples
17581831
- test-ocsp-valid-cert-server-does-not-staple
@@ -1819,6 +1892,8 @@ buildvariants:
18191892
- test-3.6-sharded_cluster
18201893
- test-latest-server-v1-api
18211894
- test-atlas-data-lake
1895+
- test-socks5
1896+
- test-socks5-tls
18221897
- test-ocsp-valid-cert-server-staples
18231898
- test-ocsp-invalid-cert-server-staples
18241899
- test-ocsp-valid-cert-server-does-not-staple

.evergreen/config.yml.in

+37
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,43 @@ functions:
326326

327327
bash ${PROJECT_DIRECTORY}/.evergreen/run-atlas-tests.sh
328328

329+
"run socks5 tests":
330+
- command: shell.exec
331+
type: test
332+
params:
333+
silent: true
334+
working_dir: "src"
335+
script: |
336+
${PREPARE_SHELL}
337+
cat <<EOT > prepare_client_encryption.sh
338+
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
339+
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
340+
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
341+
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
342+
export CSFLE_GIT_REF="${CSFLE_GIT_REF}"
343+
export CDRIVER_GIT_REF="${CDRIVER_GIT_REF}"
344+
EOT
345+
- command: shell.exec
346+
type: test
347+
params:
348+
working_dir: "src"
349+
script: |
350+
${PREPARE_SHELL}
351+
352+
export PYTHON_BINARY=$([ "Windows_NT" = "$OS" ] && echo "/cygdrive/c/python/python38/python.exe" || echo "/opt/mongodbtoolchain/v3/bin/python3")
353+
export PROJECT_DIRECTORY="$(pwd)"
354+
export DRIVERS_TOOLS="${DRIVERS_TOOLS}"
355+
export NODE_LTS_NAME='${NODE_LTS_NAME}'
356+
export MONGODB_URI="${MONGODB_URI}"
357+
export SSL="${SSL}"
358+
359+
# Disable xtrace (just in case it was accidentally set).
360+
set +x
361+
. ./prepare_client_encryption.sh
362+
rm -f ./prepare_client_encryption.sh
363+
364+
bash ${PROJECT_DIRECTORY}/.evergreen/run-socks5-tests.sh
365+
329366
"run kerberos tests":
330367
- command: shell.exec
331368
type: test

.evergreen/generate_evergreen_tasks.js

+31
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,37 @@ TASKS.push(
136136
tags: ['auth', 'ldap'],
137137
commands: [{ func: 'install dependencies' }, { func: 'run ldap tests' }]
138138
},
139+
{
140+
name: 'test-socks5',
141+
tags: [],
142+
commands: [
143+
{ func: 'install dependencies' },
144+
{
145+
func: 'bootstrap mongo-orchestration',
146+
vars: {
147+
VERSION: 'latest',
148+
TOPOLOGY: 'replica_set'
149+
}
150+
},
151+
{ func: 'run socks5 tests' }
152+
]
153+
},
154+
{
155+
name: 'test-socks5-tls',
156+
tags: [],
157+
commands: [
158+
{ func: 'install dependencies' },
159+
{
160+
func: 'bootstrap mongo-orchestration',
161+
vars: {
162+
SSL: 'ssl',
163+
VERSION: 'latest',
164+
TOPOLOGY: 'replica_set'
165+
}
166+
},
167+
{ func: 'run socks5 tests', vars: { SSL: 'ssl' } }
168+
]
169+
},
139170
{
140171
name: 'test-ocsp-valid-cert-server-staples',
141172
tags: ['ocsp'],

.evergreen/run-custom-csfle-tests.sh

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#! /usr/bin/env bash
22

3+
set +o xtrace # Do not write AWS credentials to stderr
4+
35
# Initiail checks for running these tests
46
if [ -z ${AWS_ACCESS_KEY_ID+omitted} ]; then echo "AWS_ACCESS_KEY_ID is unset" && exit 1; fi
57
if [ -z ${AWS_SECRET_ACCESS_KEY+omitted} ]; then echo "AWS_SECRET_ACCESS_KEY is unset" && exit 1; fi
@@ -38,12 +40,14 @@ git clone https://github.com./mongodb/libmongocrypt.git
3840
pushd libmongocrypt
3941
git fetch --tags
4042
git checkout "$CSFLE_GIT_REF" -b csfle-custom
43+
echo "checked out libmongocrypt at $(git rev-parse HEAD)"
4144
popd # libmongocrypt
4245

4346
git clone https://github.com./mongodb/mongo-c-driver.git
4447
pushd mongo-c-driver
4548
git fetch --tags
4649
git checkout "$CDRIVER_GIT_REF" -b cdriver-custom
50+
echo "checked out C driver at $(git rev-parse HEAD)"
4751
popd # mongo-c-driver
4852

4953
pushd libmongocrypt/bindings/node

.evergreen/run-socks5-tests.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
4+
5+
set -o errexit # Exit the script with error if any of the commands fail
6+
set -o xtrace # For debuggability, no external credentials are used here
7+
8+
PYTHON_BINARY=${PYTHON_BINARY:-python3}
9+
10+
# ssl setup
11+
SSL=${SSL:-nossl}
12+
if [ "$SSL" != "nossl" ]; then
13+
export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
14+
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
15+
fi
16+
17+
# Grab a connection string that only refers to *one* of the hosts in MONGODB_URI
18+
FIRST_HOST=$(node -p 'new (require("mongodb-connection-string-url").default)(process.env.MONGODB_URI).hosts[0]')
19+
# Use localhost:12345 as the URL for the single host that we connect to,
20+
# we configure the Socks5 proxy server script to redirect from this to FIRST_HOST
21+
export MONGODB_URI_SINGLEHOST="mongodb://localhost:12345/"
22+
23+
# Compute path to socks5 fake server script in a way that works on Windows
24+
SOCKS5_SERVER_SCRIPT="$DRIVERS_TOOLS/.evergreen/socks5srv.py"
25+
if [ "Windows_NT" = "$OS" ]; then
26+
SOCKS5_SERVER_SCRIPT=$(cygpath -w "$SOCKS5_SERVER_SCRIPT")
27+
fi
28+
29+
# First, test with Socks5 + authentication required
30+
"$PYTHON_BINARY" "$SOCKS5_SERVER_SCRIPT" --port 1080 --auth username:p4ssw0rd --map "localhost:12345 to $FIRST_HOST" &
31+
PID=$!
32+
env SOCKS5_CONFIG='["localhost",1080,"username","p4ssw0rd"]' npm run check:socks5
33+
[ "$SSL" == "nossl" ] && [[ "$OSTYPE" == "linux-gnu"* ]] && \
34+
env MONGODB_URI='mongodb://localhost:12345/?proxyHost=localhost&proxyUsername=username&proxyPassword=p4ssw0rd' \
35+
bash "${PROJECT_DIRECTORY}/.evergreen/run-custom-csfle-tests.sh"
36+
kill $PID
37+
38+
# Second, test with Socks5 + no authentication
39+
"$PYTHON_BINARY" "$SOCKS5_SERVER_SCRIPT" --port 1081 --map "localhost:12345 to $FIRST_HOST" &
40+
PID=$!
41+
env SOCKS5_CONFIG='["localhost",1081]' npm run check:socks5
42+
[ "$SSL" == "nossl" ] && [[ "$OSTYPE" == "linux-gnu"* ]] && \
43+
env MONGODB_URI='mongodb://localhost:12345/?proxyHost=localhost&proxyPort=1081' \
44+
bash "${PROJECT_DIRECTORY}/.evergreen/run-custom-csfle-tests.sh"
45+
kill $PID
46+
47+
# TODO: It might be worth using something more robust to control
48+
# the Socks5 proxy server script's lifetime

package-lock.json

+48-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"dependencies": {
3535
"bson": "^4.6.0",
3636
"denque": "^2.0.1",
37-
"mongodb-connection-string-url": "^2.3.2"
37+
"mongodb-connection-string-url": "^2.3.2",
38+
"socks": "^2.6.1"
3839
},
3940
"devDependencies": {
4041
"@istanbuljs/nyc-config-typescript": "^1.0.2",
@@ -113,6 +114,7 @@
113114
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
114115
"check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
115116
"check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
117+
"check:socks5": "mocha --config \"test/manual/mocharc.json\" test/manual/socks5.test.ts",
116118
"check:csfle": "mocha --file test/tools/runner test/integration/client-side-encryption",
117119
"check:snappy": "mocha --file test/tools/runner test/functional/unit_snappy.test.js",
118120
"prepare": "node etc/prepare.js",

0 commit comments

Comments
 (0)