2929// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030//---------------------------------------------------------------------------
3131
32+ using System ;
3233using System . IO ;
33- using System . Net ;
3434using System . Net . Security ;
3535using System . Security . Authentication ;
3636using RabbitMQ . Client ;
@@ -50,8 +50,6 @@ public TestSsl(ITestOutputHelper output) : base(output)
5050
5151 protected override void SetUp ( )
5252 {
53- ServicePointManager . SecurityProtocol |= SecurityProtocolType . Tls11 | SecurityProtocolType . Tls12 ;
54-
5553 Assert . Null ( _connFactory ) ;
5654 Assert . Null ( _conn ) ;
5755 Assert . Null ( _channel ) ;
@@ -62,25 +60,32 @@ public void TestServerVerifiedIgnoringNameMismatch()
6260 {
6361 Skip . IfNot ( _sslEnv . IsSslConfigured , "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test" ) ;
6462
65- var cf = CreateConnectionFactory ( ) ;
66- cf . Port = 5671 ;
63+ ConnectionFactory ConnectionFactoryConfigurator ( ConnectionFactory cf )
64+ {
65+ cf . Port = 5671 ;
66+ cf . Ssl . ServerName = "*" ;
67+ cf . Ssl . AcceptablePolicyErrors = SslPolicyErrors . RemoteCertificateNameMismatch ;
68+ cf . Ssl . Enabled = true ;
69+ return cf ;
70+ }
6771
68- cf . Ssl . ServerName = "*" ;
69- cf . Ssl . AcceptablePolicyErrors = SslPolicyErrors . RemoteCertificateNameMismatch ;
70- cf . Ssl . Enabled = true ;
71- SendReceive ( cf ) ;
72+ SendReceive ( ConnectionFactoryConfigurator ) ;
7273 }
7374
7475 [ SkippableFact ]
7576 public void TestServerVerified ( )
7677 {
7778 Skip . IfNot ( _sslEnv . IsSslConfigured , "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test" ) ;
7879
79- var cf = CreateConnectionFactory ( ) ;
80- cf . Port = 5671 ;
81- cf . Ssl . ServerName = _sslEnv . Hostname ;
82- cf . Ssl . Enabled = true ;
83- SendReceive ( cf ) ;
80+ ConnectionFactory ConnectionFactoryConfigurator ( ConnectionFactory cf )
81+ {
82+ cf . Port = 5671 ;
83+ cf . Ssl . ServerName = _sslEnv . Hostname ;
84+ cf . Ssl . Enabled = true ;
85+ return cf ;
86+ }
87+
88+ SendReceive ( ConnectionFactoryConfigurator ) ;
8489 }
8590
8691 [ SkippableFact ]
@@ -91,13 +96,17 @@ public void TestClientAndServerVerified()
9196 string certPath = _sslEnv . CertPath ;
9297 Assert . True ( File . Exists ( certPath ) ) ;
9398
94- var cf = CreateConnectionFactory ( ) ;
95- cf . Port = 5671 ;
96- cf . Ssl . ServerName = _sslEnv . Hostname ;
97- cf . Ssl . CertPath = certPath ;
98- cf . Ssl . CertPassphrase = _sslEnv . CertPassphrase ;
99- cf . Ssl . Enabled = true ;
100- SendReceive ( cf ) ;
99+ ConnectionFactory ConnectionFactoryConfigurator ( ConnectionFactory cf )
100+ {
101+ cf . Port = 5671 ;
102+ cf . Ssl . ServerName = _sslEnv . Hostname ;
103+ cf . Ssl . CertPath = certPath ;
104+ cf . Ssl . CertPassphrase = _sslEnv . CertPassphrase ;
105+ cf . Ssl . Enabled = true ;
106+ return cf ;
107+ }
108+
109+ SendReceive ( ConnectionFactoryConfigurator ) ;
101110 }
102111
103112 // rabbitmq/rabbitmq-dotnet-client#46, also #44 and #45
@@ -106,25 +115,28 @@ public void TestNoClientCertificate()
106115 {
107116 Skip . IfNot ( _sslEnv . IsSslConfigured , "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test" ) ;
108117
109- var cf = CreateConnectionFactory ( ) ;
110- cf . Port = 5671 ;
111- cf . Ssl = new SslOption ( )
118+ ConnectionFactory ConnectionFactoryConfigurator ( ConnectionFactory cf )
112119 {
113- CertPath = null ,
114- Enabled = true ,
115- ServerName = _sslEnv . Hostname ,
116- Version = SslProtocols . None ,
117- AcceptablePolicyErrors =
118- SslPolicyErrors . RemoteCertificateNotAvailable |
119- SslPolicyErrors . RemoteCertificateNameMismatch
120- } ;
121-
122- SendReceive ( cf ) ;
120+ cf . Port = 5671 ;
121+ cf . Ssl = new SslOption ( )
122+ {
123+ CertPath = null ,
124+ Enabled = true ,
125+ ServerName = _sslEnv . Hostname ,
126+ Version = SslProtocols . None ,
127+ AcceptablePolicyErrors =
128+ SslPolicyErrors . RemoteCertificateNotAvailable |
129+ SslPolicyErrors . RemoteCertificateNameMismatch
130+ } ;
131+ return cf ;
132+ }
133+
134+ SendReceive ( ConnectionFactoryConfigurator ) ;
123135 }
124136
125- private void SendReceive ( ConnectionFactory cf )
137+ private void SendReceive ( Func < ConnectionFactory , ConnectionFactory > cfconfig )
126138 {
127- using ( IConnection conn = cf . CreateConnection ( _testDisplayName ) )
139+ using ( IConnection conn = CreateConnectionWithRetries ( cfconfig ) )
128140 {
129141 using ( IChannel ch = conn . CreateChannel ( ) )
130142 {
0 commit comments