14
14
*/
15
15
16
16
using System ;
17
+ using System . Collections . Generic ;
18
+ using System . Security . Cryptography . X509Certificates ;
17
19
using System . Threading . Tasks ;
18
20
using MongoDB . Bson ;
19
21
using MongoDB . Driver . Core . TestHelpers . Logging ;
@@ -25,35 +27,57 @@ namespace MongoDB.Driver.Tests.Specifications.socks5_support;
25
27
[ Trait ( "Category" , "Integration" ) ]
26
28
public class Socks5SupportProseTests ( ITestOutputHelper testOutputHelper ) : LoggableTestClass ( testOutputHelper )
27
29
{
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
+
28
59
[ 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 )
52
62
{
53
63
//Requires server versions > 5.0 according to spec tests, not sure why
54
64
55
65
connectionString = connectionString . Replace ( "<mappedhost>" , "localhost:27017" ) . Replace ( "<replicaset>" , "localhost:27017" ) ;
56
66
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
+
57
81
mongoClientSettings . ServerSelectionTimeout = TimeSpan . FromSeconds ( 1.5 ) ;
58
82
var client = new MongoClient ( mongoClientSettings ) ;
59
83
0 commit comments