16
16
using System ;
17
17
using System . Collections . Generic ;
18
18
using System . Linq ;
19
- using System . Security . Cryptography . X509Certificates ;
20
19
using System . Threading . Tasks ;
21
20
using MongoDB . Bson ;
22
21
using MongoDB . Driver . Core . Misc ;
29
28
namespace MongoDB . Driver . Tests . Specifications . socks5_support ;
30
29
31
30
[ Trait ( "Category" , "Socks5Proxy" ) ]
32
- public class Socks5SupportProseTests ( ITestOutputHelper testOutputHelper ) : LoggableTestClass ( testOutputHelper )
31
+ public class Socks5SupportProseTests ( ITestOutputHelper testOutputHelper )
32
+ : LoggableTestClass ( testOutputHelper )
33
33
{
34
- //TODO Fix apicompat
35
34
public static IEnumerable < object [ ] > GetTestCombinations ( )
36
35
{
37
36
var testCases = new ( string ConnectionString , bool ExpectedResult ) [ ]
@@ -49,49 +48,45 @@ public static IEnumerable<object[]> GetTestCombinations()
49
48
( "mongodb://<replicaset>/?proxyHost=localhost&proxyPort=1081" , true )
50
49
} ;
51
50
51
+ var index = 0 ;
52
52
foreach ( var ( connectionString , expectedResult ) in testCases )
53
53
{
54
- foreach ( var isAsync in new [ ] { true , false } )
54
+ foreach ( var useTls in new [ ] { true , false } )
55
55
{
56
- foreach ( var useTls in new [ ] { false } ) //TODO This needs to be changed afterwards
56
+ foreach ( var isAsync in new [ ] { true , false } )
57
57
{
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 ] ;
59
60
}
60
61
}
61
62
}
62
63
}
63
64
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
+
64
73
[ Theory ]
65
74
[ 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 )
67
76
{
68
77
RequireServer . Check ( ) . Tls ( useTls ) ;
69
78
RequireEnvironment . Check ( ) . EnvironmentVariable ( "SOCKS5_PROXY_SERVERS_ENABLED" ) ;
70
79
71
80
//Convert the hosts to a format that can be used in the connection string (host:port), and join them into a string.
72
81
var hosts = CoreTestConfiguration . ConnectionString . Hosts ;
73
82
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 } ") ;
76
83
77
84
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
- }
93
85
86
+ var mongoClientSettings = MongoClientSettings . FromConnectionString ( connectionString ) ;
87
+ mongoClientSettings . UseTls = useTls ;
94
88
mongoClientSettings . ServerSelectionTimeout = TimeSpan . FromSeconds ( 1.5 ) ;
89
+
95
90
var client = new MongoClient ( mongoClientSettings ) ;
96
91
97
92
var database = client . GetDatabase ( "admin" ) ;
0 commit comments