Skip to content

Commit d53fda2

Browse files
committed
Test improvements
1 parent 3ab4115 commit d53fda2

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Linq;
19-
using System.Security.Cryptography.X509Certificates;
2019
using System.Threading.Tasks;
2120
using MongoDB.Bson;
2221
using MongoDB.Driver.Core.Misc;
@@ -29,9 +28,9 @@
2928
namespace MongoDB.Driver.Tests.Specifications.socks5_support;
3029

3130
[Trait("Category", "Socks5Proxy")]
32-
public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper) : LoggableTestClass(testOutputHelper)
31+
public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper)
32+
: LoggableTestClass(testOutputHelper)
3333
{
34-
//TODO Fix apicompat
3534
public static IEnumerable<object[]> GetTestCombinations()
3635
{
3736
var testCases = new (string ConnectionString, bool ExpectedResult)[]
@@ -49,49 +48,45 @@ public static IEnumerable<object[]> GetTestCombinations()
4948
("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true)
5049
};
5150

51+
var index = 0;
5252
foreach (var (connectionString, expectedResult) in testCases)
5353
{
54-
foreach (var isAsync in new[] { true, false })
54+
foreach (var useTls in new[] { true, false })
5555
{
56-
foreach (var useTls in new[] { false }) //TODO This needs to be changed afterwards
56+
foreach (var isAsync in new[] { true, false })
5757
{
58-
yield return [connectionString, expectedResult, useTls, isAsync];
58+
var id = $"{index++}_{(useTls ? "Tls" : "NoTls")}_{(isAsync ? "Async" : "Sync")}";
59+
yield return [id, connectionString, expectedResult, useTls, isAsync];
5960
}
6061
}
6162
}
6263
}
6364

65+
/* TODO:
66+
* - check if apiCompat is ok
67+
* - need to run the tests on .net framework as well
68+
* - cleanup tests
69+
*
70+
*
71+
*/
72+
6473
[Theory]
6574
[MemberData(nameof(GetTestCombinations))]
66-
public async Task TestConnectionStrings(string connectionString, bool expectedResult, bool useTls, bool async)
75+
public async Task TestConnectionStrings(string id, string connectionString, bool expectedResult, bool useTls, bool async)
6776
{
6877
RequireServer.Check().Tls(useTls);
6978
RequireEnvironment.Check().EnvironmentVariable("SOCKS5_PROXY_SERVERS_ENABLED");
7079

7180
//Convert the hosts to a format that can be used in the connection string (host:port), and join them into a string.
7281
var hosts = CoreTestConfiguration.ConnectionString.Hosts;
7382
var stringHosts = string.Join(",", hosts.Select(h => h.GetHostAndPort()).Select( h => $"{h.Host}:{h.Port}"));
74-
testOutputHelper.WriteLine($"ConnectionString: {CoreTestConfiguration.ConnectionString}");
75-
testOutputHelper.WriteLine($"StringHosts: {stringHosts}");
7683

7784
connectionString = connectionString.Replace("<mappedhost>", "localhost:12345").Replace("<replicaset>", stringHosts);
78-
testOutputHelper.WriteLine($"Modified ConnectionString: {connectionString}");
79-
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
80-
81-
if (useTls)
82-
{
83-
mongoClientSettings.UseTls = true;
84-
var certificate = new X509Certificate2("/Users/papafe/dataTlsEnabled/certs/mycert.pfx");
85-
mongoClientSettings.UseTls = true;
86-
mongoClientSettings.SslSettings = new SslSettings
87-
{
88-
ClientCertificates = [certificate],
89-
CheckCertificateRevocation = false,
90-
ServerCertificateValidationCallback = (_, _, _, _) => true,
91-
};
92-
}
9385

86+
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
87+
mongoClientSettings.UseTls = useTls;
9488
mongoClientSettings.ServerSelectionTimeout = TimeSpan.FromSeconds(1.5);
89+
9590
var client = new MongoClient(mongoClientSettings);
9691

9792
var database = client.GetDatabase("admin");

0 commit comments

Comments
 (0)