Skip to content

Commit d8c3020

Browse files
URI parsing tests: assert on whether TLS is enabled
References #764.
1 parent 41ba5bf commit d8c3020

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,18 @@ public TimeSpan ContinuationTimeout
241241
public TimeSpan SocketWriteTimeout { get; set; } = DefaultConnectionTimeout;
242242

243243
/// <summary>
244-
/// Ssl options setting.
244+
/// TLS options setting.
245245
/// </summary>
246246
public SslOption Ssl { get; set; } = new SslOption();
247247

248+
/// <summary>
249+
/// TLS options setting.
250+
/// </summary>
251+
public SslOption Tls {
252+
get { return this.Ssl; }
253+
set { this.Ssl = value; }
254+
}
255+
248256
/// <summary>
249257
/// Set to false to make automatic connection recovery not recover topology (exchanges, queues, bindings, etc).
250258
/// Defaults to true.

projects/client/Unit/src/unit/TestAmqpUri.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ public void TestAmqpUriParseSucceed()
7676
{
7777
/* From the spec */
7878
ParseSuccess("amqp://user:pass@host:10000/vhost",
79-
"user", "pass", "host", 10000, "vhost");
79+
"user", "pass", "host", 10000, "vhost", false);
80+
ParseSuccess("amqps://user:pass@host:10000/vhost",
81+
"user", "pass", "host", 10000, "vhost", true);
8082
ParseSuccess("aMQps://user%61:%61pass@host:10000/v%2fhost",
81-
"usera", "apass", "host", 10000, "v/host");
83+
"usera", "apass", "host", 10000, "v/host", true);
8284
ParseSuccess("amqp://localhost", "guest", "guest", "localhost", 5672, "/");
8385
ParseSuccess("amqp://:@localhost/", "", "", "localhost", 5672, "/");
8486
ParseSuccess("amqp://user@localhost",
@@ -137,12 +139,13 @@ public void TestAmqpUriParseSucceed()
137139
}
138140
}
139141

140-
private static void AssertUriPartEquivalence(string user, string password, int port, string vhost, ConnectionFactory cf)
142+
private static void AssertUriPartEquivalence(ConnectionFactory cf, string user, string password, int port, string vhost, bool tlsEnabled)
141143
{
142144
Assert.AreEqual(user, cf.UserName);
143145
Assert.AreEqual(password, cf.Password);
144146
Assert.AreEqual(port, cf.Port);
145147
Assert.AreEqual(vhost, cf.VirtualHost);
148+
Assert.AreEqual(tlsEnabled, cf.Tls.Enabled);
146149
}
147150

148151
private void ParseFailWith<T>(string uri) where T : Exception
@@ -151,26 +154,27 @@ private void ParseFailWith<T>(string uri) where T : Exception
151154
Assert.That(() => cf.Uri = new Uri(uri), Throws.TypeOf<T>());
152155
}
153156

154-
private void ParseSuccess(string uri, string user, string password, string host, int port, string vhost)
157+
private void ParseSuccess(string uri, string user, string password, string host, int port, string vhost, bool tlsEnabled = false)
155158
{
156159
var factory = new ConnectionFactory
157160
{
158161
Uri = new Uri(uri)
159162
};
160-
AssertUriPartEquivalence(user, password, port, vhost, factory);
163+
AssertUriPartEquivalence(factory, user, password, port, vhost, tlsEnabled);
161164
Assert.AreEqual(host, factory.HostName);
162165
}
163166

164167
private void ParseSuccess(string uri, string user, string password,
165-
string[] hosts, int port, string vhost)
168+
string[] hosts, int port, string vhost, bool tlsEnabled = false)
166169
{
167170
var factory = new ConnectionFactory
168171
{
169172
Uri = new Uri(uri)
170173
};
171-
AssertUriPartEquivalence(user, password, port, vhost, factory);
174+
AssertUriPartEquivalence(factory, user, password, port, vhost, tlsEnabled);
172175
Assert.IsTrue(Array.IndexOf(hosts, factory.HostName) != -1);
173176
}
177+
174178
public static bool IsRunningOnMono()
175179
{
176180
#if CORECLR

0 commit comments

Comments
 (0)