Skip to content

Commit 01dfdb1

Browse files
committed
Added connection string tests
1 parent 3d1d2bd commit 01dfdb1

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

tests/MongoDB.Driver.Tests/Core/Configuration/ConnectionStringTests.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ public void When_nothing_is_specified(string connectionString)
374374
subject.MaxPoolSize.Should().Be(null);
375375
subject.MinPoolSize.Should().Be(null);
376376
subject.Password.Should().BeNull();
377+
subject.ProxyHost.Should().Be(null);
378+
subject.ProxyPort.Should().Be(null);
379+
subject.ProxyPassword.Should().Be(null);
380+
subject.ProxyUsername.Should().Be(null);
377381
subject.ReadConcernLevel.Should().BeNull();
378382
subject.ReadPreference.Should().BeNull();
379383
subject.ReadPreferenceTags.Should().BeNull();
@@ -420,6 +424,10 @@ public void When_everything_is_specified()
420424
"maxLifeTime=5ms;" +
421425
"maxPoolSize=20;" +
422426
"minPoolSize=15;" +
427+
"proxyHost=host.com;" +
428+
"proxyPort=2020;" +
429+
"proxyUsername=user;" +
430+
"proxyPassword=passw;" +
423431
"readConcernLevel=majority;" +
424432
"readPreference=primary;" +
425433
"readPreferenceTags=dc:1;" +
@@ -462,6 +470,10 @@ public void When_everything_is_specified()
462470
subject.MaxPoolSize.Should().Be(20);
463471
subject.MinPoolSize.Should().Be(15);
464472
subject.Password.Should().Be("pass");
473+
subject.ProxyHost.Should().Be("host.com");
474+
subject.ProxyPort.Should().Be(2020);
475+
subject.ProxyUsername.Should().Be("user");
476+
subject.ProxyPassword.Should().Be("passw");
465477
subject.ReadConcernLevel.Should().Be(ReadConcernLevel.Majority);
466478
subject.ReadPreference.Should().Be(ReadPreferenceMode.Primary);
467479
subject.ReadPreferenceTags.Single().Should().Be(new TagSet(new[] { new Tag("dc", "1") }));
@@ -1200,6 +1212,46 @@ public void When_srvServiceName_is_specified_without_a_srv_scheme()
12001212
exception.Message.Should().Contain("srvServiceName");
12011213
}
12021214

1215+
[Theory]
1216+
[InlineData("mongodb://localhost?proxyHost=222.222.222.12", "222.222.222.12", null, null, null)]
1217+
[InlineData("mongodb://localhost?proxyHost=222.222.222.12&proxyPort=8080", "222.222.222.12", 8080, null, null)]
1218+
[InlineData("mongodb://localhost?proxyHost=example.com", "example.com", null, null, null)]
1219+
[InlineData("mongodb://localhost?proxyHost=example.com&proxyPort=8080", "example.com", 8080, null, null)]
1220+
[InlineData("mongodb://localhost?proxyHost=example.com&proxyUsername=user&proxyPassword=passw", "example.com", null, "user", "passw")]
1221+
[InlineData("mongodb://localhost?proxyHost=example.com&proxyPort=8080&proxyUsername=user&proxyPassword=passw", "example.com", 8080, "user", "passw")]
1222+
public void When_proxy_parameters_are_specified(string connectionString, string host, int? port, string username, string password)
1223+
{
1224+
var subject = new ConnectionString(connectionString);
1225+
1226+
subject.ProxyHost.Should().Be(host);
1227+
subject.ProxyPort.Should().Be(port);
1228+
subject.ProxyUsername.Should().Be(username);
1229+
subject.ProxyPassword.Should().Be(password);
1230+
}
1231+
1232+
[Theory]
1233+
[InlineData("mongodb://localhost?proxyPort=2020", "proxyPort")]
1234+
[InlineData("mongodb://localhost?proxyUsername=user", "proxyUsername")]
1235+
[InlineData("mongodb://localhost?proxyPassword=pasw", "proxyPassword")]
1236+
public void When_proxyParameter_is_specified_without_proxyHost(string connectionString, string parameterName)
1237+
{
1238+
var exception = Record.Exception(() => new ConnectionString(connectionString));
1239+
1240+
exception.Should().BeOfType<MongoConfigurationException>();
1241+
exception.Message.Should().Contain(parameterName);
1242+
}
1243+
1244+
[Theory]
1245+
[InlineData("mongodb://localhost?proxyHost=host.com&proxyUsername=user")]
1246+
[InlineData("mongodb://localhost?proxyHost=host.com&proxyPassword=pasw")]
1247+
public void When_proxyPassword_and_proxyUsername_are_not_specified_together(string connectionString)
1248+
{
1249+
var exception = Record.Exception(() => new ConnectionString(connectionString));
1250+
1251+
exception.Should().BeOfType<MongoConfigurationException>();
1252+
exception.Message.Should().Contain("proxyUsername and proxyPassword");
1253+
}
1254+
12031255
[Theory]
12041256
[ParameterAttributeData]
12051257
public void Valid_srvMaxHosts_with_mongodbsrv_scheme_should_be_valid([Values(0, 42)]int srvMaxHosts)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public class Socks5SupportProseTests(ITestOutputHelper testOutputHelper) : Logga
5050
[InlineData("mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081", true, true)]
5151
public async Task TestConnectionStrings(string connectionString, bool expectedResult, bool async)
5252
{
53+
//Requires server versions > 5.0 according to spec tests, not sure why
54+
5355
connectionString = connectionString.Replace("<mappedhost>", "localhost:27017").Replace("<replicaset>", "localhost:27017");
5456
var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString);
5557
mongoClientSettings.ServerSelectionTimeout = TimeSpan.FromSeconds(1.5);

0 commit comments

Comments
 (0)