Skip to content

Commit 97a420d

Browse files
committed
Various small corrections.
1 parent 4402181 commit 97a420d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper)
3535
{
3636
public static IEnumerable<object[]> GetTestCombinations()
3737
{
38+
/* From the Socks5 Proxy Support Prose Tests:
39+
*
40+
* Drivers MUST create a MongoClient for each of these connection strings, and attempt to run a hello command using each client.
41+
* The operation must succeed for table entries marked (succeeds) and fail for table entries marked (fails).
42+
* The connection strings MUST all be accepted as valid connection strings.
43+
*
44+
* Drivers MUST run variants of these tests in which the proxy options are substituted for MongoClient options -- This is not done as it would mostly be a repetition of the connection string tests.
45+
*
46+
* Drivers MUST verify for at least one of the connection strings marked (succeeds) that command monitoring events do not reference the SOCKS5 proxy host where the MongoDB service server/port are referenced.
47+
*/
3848
var testCases = new (string ConnectionString, bool ExpectedResult)[]
3949
{
4050
("mongodb://<mappedhost>/?proxyHost=localhost&proxyPort=1080&directConnection=true", false),
@@ -77,6 +87,8 @@ public async Task TestConnectionStrings(string id, string connectionString, bool
7787

7888
if (isMappedHost)
7989
{
90+
//<mappedhost> is always replaced with localhost:12345, and it's used to verify that the test proxy server is actually used.
91+
//Internally localhost:12345 is mapped to the actual hosts by the test proxy server.
8092
connectionString = connectionString.Replace("<mappedhost>", "localhost:12345");
8193
actualHosts = [("localhost", 12345)];
8294
}
@@ -90,14 +102,15 @@ public async Task TestConnectionStrings(string id, string connectionString, bool
90102

91103
var eventList = new List<CommandStartedEvent>();
92104
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
105+
mongoClientSettings.ClusterSource = DisposingClusterSource.Instance;
93106
mongoClientSettings.UseTls = useTls;
94107
mongoClientSettings.ServerSelectionTimeout = TimeSpan.FromSeconds(1.5);
95108
mongoClientSettings.ClusterConfigurator = cb =>
96109
{
97110
cb.Subscribe<CommandStartedEvent>(eventList.Add);
98111
};
99112

100-
var client = new MongoClient(mongoClientSettings);
113+
using var client = new MongoClient(mongoClientSettings);
101114
var database = client.GetDatabase("admin");
102115

103116
var command = new BsonDocument("hello", 1);
@@ -109,7 +122,7 @@ public async Task TestConnectionStrings(string id, string connectionString, bool
109122
: database.RunCommand<BsonDocument>(command);
110123

111124
Assert.NotEmpty(result);
112-
AssertEventListDoesNotContainSocks5Proxy(actualHosts, eventList);
125+
AssertEventListContainsCorrectEndpoints(actualHosts, eventList);
113126
}
114127
else
115128
{
@@ -121,7 +134,7 @@ public async Task TestConnectionStrings(string id, string connectionString, bool
121134
}
122135
}
123136

124-
private static void AssertEventListDoesNotContainSocks5Proxy(List<(string Host, int Port)> hosts, List<CommandStartedEvent> eventList)
137+
private static void AssertEventListContainsCorrectEndpoints(List<(string Host, int Port)> hosts, List<CommandStartedEvent> eventList)
125138
{
126139
var proxyHosts = new List<(string Host, int Port)>
127140
{

0 commit comments

Comments
 (0)