This is an automated email from the ASF dual-hosted git repository. tabish pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-proton-dotnet.git
The following commit(s) were added to refs/heads/main by this push: new 79fe183 PROTON-2719 Ensure configured virtual host value is sent to the remote 79fe183 is described below commit 79fe183edc3f27e919868bb71094c4607b9276e7 Author: Timothy Bish <tabish...@gmail.com> AuthorDate: Mon May 1 16:59:11 2023 -0400 PROTON-2719 Ensure configured virtual host value is sent to the remote The connection options virtual host should be used to override the value set for the connection host or to omit a value if empty string is provided. The host option should be applied both to the Open performative and to the SASLInit performative consistently. --- .../Client/Implementation/ClientConnection.cs | 12 ++- .../Client/Implementation/ClientConnectionTest.cs | 93 ++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/Proton.Client/Client/Implementation/ClientConnection.cs b/src/Proton.Client/Client/Implementation/ClientConnection.cs index 5c79af2..b3c4e83 100644 --- a/src/Proton.Client/Client/Implementation/ClientConnection.cs +++ b/src/Proton.Client/Client/Implementation/ClientConnection.cs @@ -979,10 +979,18 @@ namespace Apache.Qpid.Proton.Client.Implementation protonConnection.ContainerId = connectionId; } + if (options.VirtualHost != null) + { + protonConnection.Hostname = options.VirtualHost.Length == 0 ? null : options.VirtualHost; + } + else + { + protonConnection.Hostname = location.Host; + } + protonConnection.LinkedResource = this; protonConnection.ChannelMax = options.ChannelMax; protonConnection.MaxFrameSize = options.MaxFrameSize; - protonConnection.Hostname = location.Host; protonConnection.IdleTimeout = (uint)options.IdleTimeout; protonConnection.OfferedCapabilities = ClientConversionSupport.ToSymbolArray(options.OfferedCapabilities); protonConnection.DesiredCapabilities = ClientConversionSupport.ToSymbolArray(options.DesiredCapabilities); @@ -1298,7 +1306,7 @@ namespace Apache.Qpid.Proton.Client.Implementation this.options = connection.options; } - public string VHost => options.VirtualHost; + public string VHost => connection.protonConnection.Hostname; public string Username => options.User; diff --git a/test/Proton.Client.Tests/Client/Implementation/ClientConnectionTest.cs b/test/Proton.Client.Tests/Client/Implementation/ClientConnectionTest.cs index 73f38c7..934a52c 100644 --- a/test/Proton.Client.Tests/Client/Implementation/ClientConnectionTest.cs +++ b/test/Proton.Client.Tests/Client/Implementation/ClientConnectionTest.cs @@ -29,6 +29,7 @@ using Apache.Qpid.Proton.Test.Driver.Matchers.Types.Messaging; using System.Linq; using Apache.Qpid.Proton.Test.Driver.Codec.Messaging; using Apache.Qpid.Proton.Client.TestSupport; +using Apache.Qpid.Proton.Test.Driver.Codec.Security; namespace Apache.Qpid.Proton.Client.Implementation { @@ -1923,6 +1924,98 @@ namespace Apache.Qpid.Proton.Client.Implementation } } + [Test] + public void TestCreateConnectionWithNoVHostCarriesRemoteHost() + { + using (ProtonTestServer peer = new ProtonTestServer(TestServerOptions(), loggerFactory)) + { + peer.Start(); + + string remoteAddress = peer.ServerAddress; + int remotePort = peer.ServerPort; + + logger.LogInformation("Test started, peer listening on: {0}:{1}", remoteAddress, remotePort); + + peer.ExpectSASLHeader().RespondWithSASLHeader(); + peer.RemoteSaslMechanisms().WithMechanisms("ANONYMOUS").Queue(); + peer.ExpectSaslInit().WithMechanism("ANONYMOUS").WithHostname(remoteAddress); + peer.RemoteSaslOutcome().WithCode(SaslCode.Ok).Queue(); + peer.ExpectAMQPHeader().RespondWithAMQPHeader(); + peer.ExpectOpen().WithHostname(remoteAddress).Respond(); + peer.ExpectClose().Respond(); + + IClient container = IClient.Create(); + IConnection connection = container.Connect(remoteAddress, remotePort, ConnectionOptions()); + + _ = connection.OpenTask.Wait(TimeSpan.FromSeconds(10)); + connection.CloseAsync().Wait(); + + peer.WaitForScriptToComplete(); + } + } + + [Test] + public void TestCreateConnectionWithSpecifiedVHost() + { + using (ProtonTestServer peer = new ProtonTestServer(TestServerOptions(), loggerFactory)) + { + peer.ExpectSASLHeader().RespondWithSASLHeader(); + peer.RemoteSaslMechanisms().WithMechanisms("ANONYMOUS").Queue(); + peer.ExpectSaslInit().WithMechanism("ANONYMOUS").WithHostname("test"); + peer.RemoteSaslOutcome().WithCode(SaslCode.Ok).Queue(); + peer.ExpectAMQPHeader().RespondWithAMQPHeader(); + peer.ExpectOpen().WithHostname("test").Respond(); + peer.ExpectClose().Respond(); + peer.Start(); + + string remoteAddress = peer.ServerAddress; + int remotePort = peer.ServerPort; + + logger.LogInformation("Test started, peer listening on: {0}:{1}", remoteAddress, remotePort); + + IClient container = IClient.Create(); + ConnectionOptions options = ConnectionOptions(); + options.VirtualHost = "test"; + IConnection connection = container.Connect(remoteAddress, remotePort, options); + + _ = connection.OpenTask.Wait(TimeSpan.FromSeconds(10)); + connection.CloseAsync().Wait(); + + peer.WaitForScriptToComplete(); + } + } + + [Test] + public void TestCreateConnectionWithEmptyVHostSendsNullValueInOpen() + { + using (ProtonTestServer peer = new ProtonTestServer(TestServerOptions(), loggerFactory)) + { + peer.ExpectSASLHeader().RespondWithSASLHeader(); + peer.RemoteSaslMechanisms().WithMechanisms("ANONYMOUS").Queue(); + peer.ExpectSaslInit().WithMechanism("ANONYMOUS").WithHostname(Test.Driver.Matchers.Is.NullValue()); + peer.RemoteSaslOutcome().WithCode(SaslCode.Ok).Queue(); + peer.ExpectAMQPHeader().RespondWithAMQPHeader(); + peer.ExpectOpen().WithHostname(Test.Driver.Matchers.Is.NullValue()).Respond(); + peer.ExpectClose().Respond(); + peer.Start(); + + string remoteAddress = peer.ServerAddress; + int remotePort = peer.ServerPort; + + logger.LogInformation("Test started, peer listening on: {0}:{1}", remoteAddress, remotePort); + + IClient container = IClient.Create(); + ConnectionOptions options = ConnectionOptions(); + options.VirtualHost = ""; + IConnection connection = container.Connect(remoteAddress, remotePort, options); + + _ = connection.OpenTask.Wait(TimeSpan.FromSeconds(10)); + connection.CloseAsync().Wait(); + + peer.WaitForScriptToComplete(); + } + } + [Ignore("Client local bind not yet implemented")] [Test] public void TestLocalPortOption() --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org