Skip to content

Commit e6b48b4

Browse files
Vladimir-FrolovVladimir
andauthored
Fixed ssl options mapping (#1912)
* Fixed ssl options mapping * Added units test for ssl options mapping --------- Co-authored-by: Vladimir <example@com>
1 parent 7cb3f43 commit e6b48b4

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

Source/EasyNetQ.Tests/PersistentConnectionTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using EasyNetQ.ConnectionString;
12
using EasyNetQ.Persistent;
23
using EasyNetQ.Tests.Mocking;
34
using Microsoft.Extensions.Logging;
@@ -99,4 +100,28 @@ public async Task Should_establish_connection_when_persistent_connection_created
99100
connection.Status.State.Should().Be(PersistentConnectionState.Connected);
100101
await mockBuilder.ConnectionFactory.Received(1).CreateConnectionAsync(Arg.Any<IList<AmqpTcpEndpoint>>());
101102
}
103+
104+
[Fact]
105+
public async Task Should_pass_ssl_servername_the_same_as_hostname()
106+
{
107+
var config = new ConnectionStringParser().Parse("host=test-host:5671;ssl=true");
108+
109+
await using var mockBuilder = new MockBuilder();
110+
using var connection = new PersistentConnection(
111+
PersistentConnectionType.Producer,
112+
Substitute.For<ILogger<IPersistentConnection>>(),
113+
config,
114+
mockBuilder.ConnectionFactory,
115+
mockBuilder.EventBus
116+
);
117+
118+
connection.Status.State.Should().Be(PersistentConnectionState.NotInitialised);
119+
120+
await connection.CreateChannelAsync();
121+
122+
await mockBuilder.ConnectionFactory.Received(1)
123+
.CreateConnectionAsync(Arg.Is<IList<AmqpTcpEndpoint>>(eps => eps.Single().Ssl.ServerName == eps.Single().HostName));
124+
125+
connection.Status.State.Should().Be(PersistentConnectionState.Connected);
126+
}
102127
}

Source/EasyNetQ/Persistent/PersistentConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ private static SslOption NewSslForHost(SslOption option, string host) =>
203203
CertificateValidationCallback = option.CertificateValidationCallback,
204204
CheckCertificateRevocation = option.CheckCertificateRevocation,
205205
Enabled = option.Enabled,
206-
ServerName = option.ServerName ?? host,
206+
ServerName = string.IsNullOrEmpty(option.ServerName) ? host : option.ServerName,
207207
Version = option.Version,
208208
};
209209
}

0 commit comments

Comments
 (0)