From 0dc86cfe86fbe70ec761c2a3963b384fd047a380 Mon Sep 17 00:00:00 2001 From: "Carol Wang (Inspur Worldwide Services Ltd)" Date: Wed, 12 Jun 2019 18:29:56 +0800 Subject: [PATCH] Add unit test for #3657 --- ...yModeTransportWithMessageCredentialTest.cs | 32 +++++++++++++++++++ .../TcpTransportBindingElementTest.cs | 5 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/System.ServiceModel.NetTcp/tests/Channels/SecurityModeTransportWithMessageCredentialTest.cs diff --git a/src/System.ServiceModel.NetTcp/tests/Channels/SecurityModeTransportWithMessageCredentialTest.cs b/src/System.ServiceModel.NetTcp/tests/Channels/SecurityModeTransportWithMessageCredentialTest.cs new file mode 100644 index 00000000000..b18ba6015e4 --- /dev/null +++ b/src/System.ServiceModel.NetTcp/tests/Channels/SecurityModeTransportWithMessageCredentialTest.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ServiceModel.Channels; +using System.ServiceModel.Security; +using Infrastructure.Common; +using Xunit; + +namespace System.ServiceModel.NetTcp.Tests +{ + public static class SecurityModeTransportWithMessageCredentialTest + { + [WcfFact] + public static void Init_TransportWithMessageCredentialSecurityMode() + { + NetTcpBinding binding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential); + binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; + BindingElementCollection bindingElements = binding.CreateBindingElements(); + SecurityBindingElement secutityBindingElement = bindingElements.Find(); + + Assert.StrictEqual(binding.Security.Mode, SecurityMode.TransportWithMessageCredential); + Assert.True(secutityBindingElement != null, "SecurityBindingElement should not be null."); + + Assert.True(binding.Security.Message.AlgorithmSuite == SecurityAlgorithmSuite.Default, "AlgorithmSuite should be Default."); + Assert.True(binding.Security.Message.ClientCredentialType == MessageCredentialType.UserName, "ClientCredentialType should be UserName."); + + binding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate; + Assert.True(binding.Security.Message.ClientCredentialType == MessageCredentialType.Certificate, "ClientCredentialType should be Certifiacte."); + } + } +} diff --git a/src/System.ServiceModel.NetTcp/tests/Channels/TcpTransportBindingElementTest.cs b/src/System.ServiceModel.NetTcp/tests/Channels/TcpTransportBindingElementTest.cs index beea23cd760..1077250f5fb 100644 --- a/src/System.ServiceModel.NetTcp/tests/Channels/TcpTransportBindingElementTest.cs +++ b/src/System.ServiceModel.NetTcp/tests/Channels/TcpTransportBindingElementTest.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - using System; using System.ServiceModel.Channels; using Infrastructure.Common; @@ -21,5 +20,9 @@ public static void Ctor_Default_Properties() // Validate only a non-null TcpConnectionPoolSetting. // Its own default values are validated in that type's test methods Assert.True(element.ConnectionPoolSettings != null, "ConnectionPoolSettings should not be null."); + + // Validate a non-null ExtendedProtectionPolicy. + Assert.True(element.ExtendedProtectionPolicy != null, "ExtendedProtectionPolicy should not be null."); + } }