Skip to content

Commit c64af48

Browse files
committed
Evergreen test
1 parent 69d5190 commit c64af48

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

build.cake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ Task("TestLoadBalanced")
229229
Task("TestLoadBalancedNetStandard21").IsDependentOn("TestLoadBalanced");
230230
Task("TestLoadBalancedNet60").IsDependentOn("TestLoadBalanced");
231231

232+
Task("TestSocks5Proxy")
233+
.IsDependentOn("TestLibMongoCrypt")
234+
.DoesForEach(
235+
items: GetFiles("./**/*.Tests.csproj"),
236+
action: (BuildConfig buildConfig, Path testProject) =>
237+
RunTests(buildConfig, testProject, filter: "Category=\"Socks5Proxy\""));
238+
239+
Task("TestSocks5ProxyNet472").IsDependentOn("TestSocks5Proxy");
240+
Task("TestSocks5ProxyNetStandard21").IsDependentOn("TestSocks5Proxy");
241+
Task("TestSocks5ProxyNet60").IsDependentOn("TestSocks5Proxy");
242+
232243
Task("TestCsfleWithMockedKms")
233244
.IsDependentOn("TestLibMongoCrypt")
234245
.DoesForEach(

evergreen/evergreen.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,42 @@ timeout:
2626
2727
functions:
2828

29+
setup-socks5-proxy:
30+
- command: shell.exec
31+
params:
32+
script: |
33+
${PREPARE_SHELL}
34+
# Read the MongoDB URI connection string and extract an arbitrary member's host:port
35+
HOST_PORT=$(echo "$MONGODB_URI" | sed 's|mongodb://||' | cut -d',' -f1)
36+
37+
# Start the SOCKS5 proxy with authentication on port 1080
38+
python $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "localhost:12345 to $HOST_PORT" --port 1080 --auth username:p4ssw0rd &
39+
40+
# Start the SOCKS5 proxy without authentication on port 1081
41+
python $DRIVERS_TOOLS/.evergreen/socks5srv.py --map "localhost:12345 to $HOST_PORT" --port 1081 &
42+
43+
#//TODO Check if we need all those parameters...
44+
run-socks5-proxy-tests:
45+
- command: shell.exec
46+
type: test
47+
params:
48+
working_dir: "mongo-csharp-driver"
49+
shell: "bash"
50+
script: |
51+
export SOCKS5_PROXY_SERVERS_ENABLED=true
52+
${PREPARE_SHELL}
53+
OS=${OS} \
54+
evergreen/add-ca-certs.sh
55+
SSL=${SSL} \
56+
MONGODB_URI="${MONGODB_URI}" \
57+
TOPOLOGY=${TOPOLOGY} \
58+
OS=${OS} \
59+
FRAMEWORK=${FRAMEWORK} \
60+
TARGET="TestSocks5Proxy" \
61+
evergreen/run-tests.sh
62+
OS=${OS} \
63+
evergreen/cleanup-test-resources.sh
64+
2965
fetch-source:
3066
# Executes git clone and applies the submitted patch, if any
3167
- command: git.get_project
@@ -1133,6 +1169,15 @@ tasks:
11331169
vars:
11341170
FRAMEWORK: net60
11351171

1172+
#//TODO need to do the same with the other platforms
1173+
- name: test-socks5-proxy-net60
1174+
commands:
1175+
- func: setup-socks5-proxy
1176+
- func: bootstrap-mongo-orchestration
1177+
- func: run-socks5-proxy-tests
1178+
vars:
1179+
FRAMEWORK: net60
1180+
11361181
- name: test-csfle-with-mocked-kms-tls-net472
11371182
commands:
11381183
- func: setup-csfle-secrets
@@ -2548,7 +2593,18 @@ buildvariants:
25482593
tasks:
25492594
- name: atlas-search-index-helpers-task-group
25502595

2596+
# Socks5 Proxy tests
2597+
# //TODO I don't think we need to do this tests with more than one version, right?
2598+
# //TODO Do we need to run it also on other OSes? Java does only linux
2599+
2600+
- matrix_name: "socks5-proxy-tests"
2601+
matrix_spec: { os: "ubuntu-2004", ssl: ["nossl", "ssl"], version: ["latest"], topology: ["replicaset"] }
2602+
display_name: "Socks5 Proxy ${version} ${os} ${ssl}"
2603+
tasks:
2604+
- name: test-socks5-proxy-net60
2605+
25512606
# CSFLE tests
2607+
25522608
- matrix_name: "csfle-with-mocked-kms-tests-windows"
25532609
matrix_spec: { os: "windows-64", ssl: "nossl", version: ["4.2", "4.4", "5.0", "6.0", "7.0", "8.0", "rapid", "latest"], topology: ["replicaset"] }
25542610
display_name: "CSFLE Mocked KMS ${version} ${os}"

tests/MongoDB.Driver.Tests/Specifications/socks5-support/Socks5SupportProseTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18+
using System.Linq;
1819
using System.Security.Cryptography.X509Certificates;
1920
using System.Threading.Tasks;
2021
using MongoDB.Bson;
22+
using MongoDB.Driver.Core.Clusters;
23+
using MongoDB.Driver.Core.Misc;
2124
using MongoDB.Driver.Core.TestHelpers.Logging;
25+
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
26+
using MongoDB.TestHelpers.XunitExtensions;
2227
using Xunit;
2328
using Xunit.Abstractions;
2429

2530
namespace MongoDB.Driver.Tests.Specifications.socks5_support;
2631

27-
[Trait("Category", "Integration")]
32+
[Trait("Category", "Socks5Proxy")]
2833
public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper) : LoggableTestClass(testOutputHelper)
2934
{
35+
//TODO Fix apicompat
3036
public static IEnumerable<object[]> GetTestCombinations()
3137
{
3238
var testCases = new (string ConnectionString, bool ExpectedResult)[]
@@ -48,7 +54,7 @@ public static IEnumerable<object[]> GetTestCombinations()
4854
{
4955
foreach (var isAsync in new[] { true, false })
5056
{
51-
foreach (var useTls in new[] { true, false })
57+
foreach (var useTls in new[] { false })
5258
{
5359
yield return [connectionString, expectedResult, useTls, isAsync];
5460
}
@@ -60,9 +66,15 @@ public static IEnumerable<object[]> GetTestCombinations()
6066
[MemberData(nameof(GetTestCombinations))]
6167
public async Task TestConnectionStrings(string connectionString, bool expectedResult, bool useTls, bool async)
6268
{
63-
//Requires server versions > 5.0 according to spec tests, not sure why
69+
RequireServer.Check().Tls(required: useTls);
70+
RequireServer.Check().ClusterType(ClusterType.ReplicaSet);
71+
RequireEnvironment.Check().EnvironmentVariable("SOCKS5_PROXY_SERVERS_ENABLED");
6472

65-
connectionString = connectionString.Replace("<mappedhost>", "localhost:27017").Replace("<replicaset>", "localhost:27017");
73+
//Convert the hosts to a format that can be used in the connection string (host:port), and join them into a string.
74+
var hosts = CoreTestConfiguration.ConnectionString.Hosts;
75+
var stringHosts = string.Join(",", hosts.Select(h => h.GetHostAndPort()).Select( h => $"{h.Host}:{h.Port}"));
76+
77+
connectionString = connectionString.Replace("<mappedhost>", "localhost:12345").Replace("<replicaset>", stringHosts);
6678
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
6779

6880
if (useTls)

0 commit comments

Comments
 (0)