Skip to content

Commit 35f688e

Browse files
committed
Improved tests
1 parent 2df31f3 commit 35f688e

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

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

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515

1616
using System;
17+
using System.Collections.Generic;
18+
using System.Security.Cryptography.X509Certificates;
1719
using System.Threading.Tasks;
1820
using MongoDB.Bson;
1921
using MongoDB.Driver.Core.TestHelpers.Logging;
@@ -25,35 +27,57 @@ namespace MongoDB.Driver.Tests.Specifications.socks5_support;
2527
[Trait("Category", "Integration")]
2628
public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper) : LoggableTestClass(testOutputHelper)
2729
{
30+
public static IEnumerable<object[]> GetTestCombinations()
31+
{
32+
var testCases = new (string ConnectionString, bool ExpectedResult)[]
33+
{
34+
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&directConnection=true", false),
35+
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true),
36+
("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080", false),
37+
("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true),
38+
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", false),
39+
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", true),
40+
("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081&proxyUsername=nonexistentuser&proxyPassword=badauth", true),
41+
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=username&proxyPassword=p4ssw0rd&directConnection=true", true),
42+
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true),
43+
("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080&proxyUsername=username&proxyPassword=p4ssw0rd", true),
44+
("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true)
45+
};
46+
47+
foreach (var (connectionString, expectedResult) in testCases)
48+
{
49+
foreach (var isAsync in new[] { true, false })
50+
{
51+
foreach (var useTls in new[] { true, false })
52+
{
53+
yield return [connectionString, expectedResult, useTls, isAsync];
54+
}
55+
}
56+
}
57+
}
58+
2859
[Theory]
29-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&directConnection=true", false, false)]
30-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&directConnection=true", false, true)]
31-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true, false)]
32-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true, true)]
33-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080", false, false)]
34-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080", false, true)]
35-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true, false)]
36-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true, true)]
37-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", false, false)]
38-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", false, true)]
39-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", true, false)]
40-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&proxyUsername=nonexistentuser&proxyPassword=badauth&directConnection=true", true, true)]
41-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081&proxyUsername=nonexistentuser&proxyPassword=badauth", true, false)]
42-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081&proxyUsername=nonexistentuser&proxyPassword=badauth", true, true)]
43-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=username&proxyPassword=p4ssw0rd&directConnection=true", true, false)]
44-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&proxyUsername=username&proxyPassword=p4ssw0rd&directConnection=true", true, true)]
45-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true, false)]
46-
[InlineData("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1081&directConnection=true", true, true)]
47-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080&proxyUsername=username&proxyPassword=p4ssw0rd", true, false)]
48-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1080&proxyUsername=username&proxyPassword=p4ssw0rd", true, true)]
49-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true, false)]
50-
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true, true)]
51-
public async Task TestConnectionStrings(string connectionString, bool expectedResult, bool async)
60+
[MemberData(nameof(GetTestCombinations))]
61+
public async Task TestConnectionStrings(string connectionString, bool expectedResult, bool useTls, bool async)
5262
{
5363
//Requires server versions > 5.0 according to spec tests, not sure why
5464

5565
connectionString = connectionString.Replace("<mappedhost>", "localhost:27017").Replace("<replicaset>", "localhost:27017");
5666
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
67+
68+
if (useTls)
69+
{
70+
mongoClientSettings.UseTls = true;
71+
var certificate = new X509Certificate2("/Users/papafe/dataTlsEnabled/certs/mycert.pfx");
72+
mongoClientSettings.UseTls = true;
73+
mongoClientSettings.SslSettings = new SslSettings
74+
{
75+
ClientCertificates = [certificate],
76+
CheckCertificateRevocation = false,
77+
ServerCertificateValidationCallback = (sender, cert, chain, errors) => true,
78+
};
79+
}
80+
5781
mongoClientSettings.ServerSelectionTimeout = TimeSpan.FromSeconds(1.5);
5882
var client = new MongoClient(mongoClientSettings);
5983

0 commit comments

Comments
 (0)