Skip to content

Commit 391bbe5

Browse files
authored
Merge pull request #1170 from rabbitmq/lukebakken/fix-tls-concourse-ci-6.x
Merge pull request #1169 from rabbitmq/lukebakken/fix-tls-concourse-ci
2 parents c9201e4 + 8a7fa63 commit 391bbe5

File tree

4 files changed

+90
-65
lines changed

4 files changed

+90
-65
lines changed

projects/Unit/TestConnectionRecovery.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,21 @@ public void TestBasicConnectionRecoveryStopsAfterManualClose()
228228
AutorecoveringConnection c = CreateAutorecoveringConnection();
229229
var latch = new AutoResetEvent(false);
230230
c.ConnectionRecoveryError += (o, args) => latch.Set();
231-
StopRabbitMQ();
232-
latch.WaitOne(30000); // we got the failed reconnection event.
233-
bool triedRecoveryAfterClose = false;
234-
c.Close();
235-
Thread.Sleep(5000);
236-
c.ConnectionRecoveryError += (o, args) => triedRecoveryAfterClose = true;
237-
Thread.Sleep(10000);
238-
Assert.IsFalse(triedRecoveryAfterClose);
239-
StartRabbitMQ();
231+
try
232+
{
233+
StopRabbitMQ();
234+
latch.WaitOne(30000); // we got the failed reconnection event.
235+
bool triedRecoveryAfterClose = false;
236+
c.Close();
237+
Thread.Sleep(5000);
238+
c.ConnectionRecoveryError += (o, args) => triedRecoveryAfterClose = true;
239+
Thread.Sleep(10000);
240+
Assert.False(triedRecoveryAfterClose);
241+
}
242+
finally
243+
{
244+
StartRabbitMQ();
245+
}
240246
}
241247

242248
[Test]
@@ -767,14 +773,21 @@ public void TestShutdownEventHandlersRecoveryOnConnectionAfterDelayedServerResta
767773
ManualResetEventSlim recoveryLatch = PrepareForRecovery((AutorecoveringConnection)Conn);
768774

769775
Assert.IsTrue(Conn.IsOpen);
770-
StopRabbitMQ();
771-
Console.WriteLine("Stopped RabbitMQ. About to sleep for multiple recovery intervals...");
772-
Thread.Sleep(7000);
773-
StartRabbitMQ();
776+
777+
try
778+
{
779+
StopRabbitMQ();
780+
Console.WriteLine("Stopped RabbitMQ. About to sleep for multiple recovery intervals...");
781+
Thread.Sleep(7000);
782+
}
783+
finally
784+
{
785+
StartRabbitMQ();
786+
}
787+
774788
Wait(shutdownLatch, TimeSpan.FromSeconds(30));
775789
Wait(recoveryLatch, TimeSpan.FromSeconds(30));
776790
Assert.IsTrue(Conn.IsOpen);
777-
778791
Assert.IsTrue(counter >= 1);
779792
}
780793

projects/Unit/TestFloodPublishing.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32-
using NUnit.Framework;
33-
using RabbitMQ.Client.Events;
3432
using System;
3533
using System.Diagnostics;
3634
using System.Linq;
3735
using System.Text;
3836
using System.Threading;
3937
using System.Threading.Tasks;
4038

39+
using NUnit.Framework;
40+
using RabbitMQ.Client.Events;
41+
4142
namespace RabbitMQ.Client.Unit
4243
{
4344
[TestFixture]

projects/Unit/TestHeartbeats.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
using System;
3333
using System.Collections.Generic;
34+
using System.IO;
3435
using System.Threading;
3536

3637
using NUnit.Framework;
@@ -58,8 +59,7 @@ public void TestThatHeartbeatWriterWithTLSEnabled()
5859
{
5960
if (!LongRunningTestsEnabled())
6061
{
61-
Console.WriteLine("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
62-
return;
62+
Assert.Ignore("RABBITMQ_LONG_RUNNING_TESTS is not set, skipping test");
6363
}
6464

6565
var cf = new ConnectionFactory()
@@ -70,15 +70,18 @@ public void TestThatHeartbeatWriterWithTLSEnabled()
7070
};
7171

7272
string sslDir = IntegrationFixture.CertificatesDirectory();
73-
if (null == sslDir)
73+
string certPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
74+
bool sslConfigured = Directory.Exists(sslDir) &&
75+
(false == string.IsNullOrEmpty(certPassphrase));
76+
if (false == sslConfigured)
7477
{
75-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
76-
return;
78+
Assert.Ignore("SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
7779
}
78-
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
79-
Assert.IsNotNull(sslDir);
80-
cf.Ssl.CertPath = $"{sslDir}/client_key.p12";
81-
cf.Ssl.CertPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
80+
81+
string hostName = System.Net.Dns.GetHostName();
82+
cf.Ssl.ServerName = hostName;
83+
cf.Ssl.CertPath = $"{sslDir}/client_{hostName}_key.p12";
84+
cf.Ssl.CertPassphrase = certPassphrase;
8285
cf.Ssl.Enabled = true;
8386

8487
RunSingleConnectionTest(cf);

projects/Unit/TestSsl.cs

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33+
using System.IO;
3334
using System.Net.Security;
35+
using System.Reflection;
3436
using System.Security.Authentication;
3537

3638
using NUnit.Framework;
@@ -40,37 +42,25 @@ namespace RabbitMQ.Client.Unit
4042
[TestFixture]
4143
public class TestSsl
4244
{
43-
public void SendReceive(ConnectionFactory cf)
44-
{
45-
using (IConnection conn = cf.CreateConnection())
46-
{
47-
IModel ch = conn.CreateModel();
48-
49-
ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
50-
string qName = ch.QueueDeclare();
51-
ch.QueueBind(qName, "Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null);
52-
53-
string message = "Hello C# SSL Client World";
54-
byte[] msgBytes = System.Text.Encoding.UTF8.GetBytes(message);
55-
ch.BasicPublish("Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null, msgBytes);
56-
57-
bool autoAck = false;
58-
BasicGetResult result = ch.BasicGet(qName, autoAck);
59-
byte[] body = result.Body.ToArray();
60-
string resultMessage = System.Text.Encoding.UTF8.GetString(body);
45+
private readonly string _testDisplayName;
46+
private readonly string _sslDir;
47+
private readonly string _certPassphrase;
48+
private readonly bool _sslConfigured;
6149

62-
Assert.AreEqual(message, resultMessage);
63-
}
50+
public TestSsl()
51+
{
52+
_sslDir = IntegrationFixture.CertificatesDirectory();
53+
_certPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
54+
_sslConfigured = Directory.Exists(_sslDir) &&
55+
(false == string.IsNullOrEmpty(_certPassphrase));
6456
}
6557

6658
[Test]
6759
public void TestServerVerifiedIgnoringNameMismatch()
6860
{
69-
string sslDir = IntegrationFixture.CertificatesDirectory();
70-
if (null == sslDir)
61+
if (false == _sslConfigured)
7162
{
72-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
73-
return;
63+
Assert.Ignore("SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
7464
}
7565

7666
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
@@ -83,11 +73,9 @@ public void TestServerVerifiedIgnoringNameMismatch()
8373
[Test]
8474
public void TestServerVerified()
8575
{
86-
string sslDir = IntegrationFixture.CertificatesDirectory();
87-
if (null == sslDir)
76+
if (false == _sslConfigured)
8877
{
89-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
90-
return;
78+
Assert.Ignore("SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
9179
}
9280

9381
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
@@ -99,18 +87,16 @@ public void TestServerVerified()
9987
[Test]
10088
public void TestClientAndServerVerified()
10189
{
102-
string sslDir = IntegrationFixture.CertificatesDirectory();
103-
if (null == sslDir)
90+
if (false == _sslConfigured)
10491
{
105-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
106-
return;
92+
Assert.Ignore("SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
10793
}
10894

95+
string hostName = System.Net.Dns.GetHostName();
10996
ConnectionFactory cf = new ConnectionFactory { Port = 5671 };
110-
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
111-
Assert.IsNotNull(sslDir);
112-
cf.Ssl.CertPath = $"{sslDir}/client_key.p12";
113-
cf.Ssl.CertPassphrase = Environment.GetEnvironmentVariable("PASSWORD");
97+
cf.Ssl.ServerName = hostName;
98+
cf.Ssl.CertPath = $"{_sslDir}/client_{hostName}_key.p12";
99+
cf.Ssl.CertPassphrase = _certPassphrase;
114100
cf.Ssl.Enabled = true;
115101
SendReceive(cf);
116102
}
@@ -119,11 +105,9 @@ public void TestClientAndServerVerified()
119105
[Test]
120106
public void TestNoClientCertificate()
121107
{
122-
string sslDir = IntegrationFixture.CertificatesDirectory();
123-
if (null == sslDir)
108+
if (false == _sslConfigured)
124109
{
125-
Console.WriteLine("SSL_CERTS_DIR is not configured, skipping test");
126-
return;
110+
Assert.Ignore("SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test");
127111
}
128112

129113
ConnectionFactory cf = new ConnectionFactory
@@ -143,5 +127,29 @@ public void TestNoClientCertificate()
143127

144128
SendReceive(cf);
145129
}
130+
131+
private void SendReceive(ConnectionFactory cf)
132+
{
133+
using (IConnection conn = cf.CreateConnection($"{_testDisplayName}:{Guid.NewGuid()}"))
134+
{
135+
using (IModel ch = conn.CreateModel())
136+
{
137+
ch.ExchangeDeclare("Exchange_TestSslEndPoint", ExchangeType.Direct);
138+
string qName = ch.QueueDeclare();
139+
ch.QueueBind(qName, "Exchange_TestSslEndPoint", "Key_TestSslEndpoint", null);
140+
141+
string message = "Hello C# SSL Client World";
142+
byte[] msgBytes = System.Text.Encoding.UTF8.GetBytes(message);
143+
ch.BasicPublish("Exchange_TestSslEndPoint", "Key_TestSslEndpoint", true, null, msgBytes);
144+
145+
bool autoAck = false;
146+
BasicGetResult result = ch.BasicGet(qName, autoAck);
147+
byte[] body = result.Body.ToArray();
148+
string resultMessage = System.Text.Encoding.UTF8.GetString(body);
149+
150+
Assert.AreEqual(message, resultMessage);
151+
}
152+
}
153+
}
146154
}
147155
}

0 commit comments

Comments
 (0)