-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2049 from hongdai/testfix
Cherry pick set up tests fixes
- Loading branch information
Showing
3 changed files
with
160 additions
and
127 deletions.
There are no files selected for viewing
156 changes: 156 additions & 0 deletions
156
src/System.Private.ServiceModel/tests/Common/Scenarios/SetupValidationTests.4.1.1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
// 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; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.ServiceModel; | ||
using System.ServiceModel.Channels; | ||
using System.ServiceModel.Security; | ||
using Infrastructure.Common; | ||
using Xunit; | ||
|
||
public class SetupValidationTests : ConditionalWcfTest | ||
{ | ||
[WcfFact] | ||
[Condition(nameof(Root_Certificate_Installed))] | ||
[OuterLoop] | ||
public static void Root_Certificate_Correctly_Installed() | ||
{ | ||
string testString = "Hello"; | ||
CustomBinding binding = null; | ||
ChannelFactory<IWcfService> factory = null; | ||
IWcfService serviceProxy = null; | ||
|
||
try | ||
{ | ||
// *** SETUP *** \\ | ||
binding = new CustomBinding(new TextMessageEncodingBindingElement(), new HttpsTransportBindingElement()); | ||
factory = new ChannelFactory<IWcfService>(binding, new EndpointAddress(Endpoints.HttpsSoap12_Address)); | ||
serviceProxy = factory.CreateChannel(); | ||
|
||
// *** EXECUTE *** \\ | ||
string result = serviceProxy.Echo(testString); | ||
|
||
// *** VALIDATE *** \\ | ||
Assert.NotNull(result); | ||
Assert.Equal(testString, result); | ||
|
||
// *** CLEANUP *** \\ | ||
factory.Close(); | ||
((ICommunicationObject)serviceProxy).Close(); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); | ||
} | ||
} | ||
|
||
[WcfFact] | ||
[Issue(1886, OS = OSID.AnyOSX)] | ||
[Condition(nameof(Client_Certificate_Installed))] | ||
[OuterLoop] | ||
public static void Client_Certificate_Correctly_Installed() | ||
{ | ||
string clientCertThumb = null; | ||
EndpointAddress endpointAddress = null; | ||
string testString = "Hello"; | ||
ChannelFactory<IWcfService> factory = null; | ||
IWcfService serviceProxy = null; | ||
|
||
try | ||
{ | ||
// *** SETUP *** \\ | ||
NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport); | ||
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Certificate; | ||
|
||
endpointAddress = new EndpointAddress(new Uri(Endpoints.Tcp_ClientCredentialType_Certificate_Address), | ||
new DnsEndpointIdentity(Endpoints.Tcp_VerifyDNS_HostName)); | ||
clientCertThumb = ServiceUtilHelper.ClientCertificate.Thumbprint; | ||
|
||
factory = new ChannelFactory<IWcfService>(binding, endpointAddress); | ||
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; | ||
factory.Credentials.ClientCertificate.SetCertificate( | ||
StoreLocation.CurrentUser, | ||
StoreName.My, | ||
X509FindType.FindByThumbprint, | ||
clientCertThumb); | ||
|
||
serviceProxy = factory.CreateChannel(); | ||
|
||
// *** EXECUTE *** \\ | ||
string result = serviceProxy.Echo(testString); | ||
|
||
// *** VALIDATE *** \\ | ||
Assert.Equal(testString, result); | ||
|
||
// *** CLEANUP *** \\ | ||
((ICommunicationObject)serviceProxy).Close(); | ||
factory.Close(); | ||
} | ||
finally | ||
{ | ||
// *** ENSURE CLEANUP *** \\ | ||
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); | ||
} | ||
} | ||
|
||
[WcfFact] | ||
[Issue(1945, OS = OSID.AnyOSX)] | ||
[Condition(nameof(Peer_Certificate_Installed))] | ||
[OuterLoop] | ||
public static void Peer_Certificate_Correctly_Installed() | ||
{ | ||
// *** SETUP *** \\ | ||
InvalidOperationException exception = null; | ||
|
||
// *** EXECUTE *** \\ | ||
try | ||
{ | ||
DateTime now = DateTime.Now; | ||
X509Certificate2 certificate = ServiceUtilHelper.PeerCertificate; | ||
StoreName storeName = StoreName.TrustedPeople; | ||
StoreLocation storeLocation = StoreLocation.CurrentUser; | ||
|
||
Assert.True(certificate != null, "Certificate is null"); | ||
Assert.True(now > certificate.NotBefore, | ||
String.Format("The current date {{0}} is earlier than NotBefore ({1})", | ||
now, | ||
certificate.NotBefore)); | ||
|
||
Assert.True(now < certificate.NotAfter, | ||
String.Format("The current date {{0}} is later than NotAfter ({1})", | ||
now, | ||
certificate.NotAfter)); | ||
|
||
using (X509Store store = new X509Store(storeName, storeLocation)) | ||
{ | ||
store.Open(OpenFlags.ReadOnly); | ||
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindByThumbprint, certificate.Thumbprint, validOnly: true); | ||
Assert.True(certificates.Count == 1, | ||
String.Format("Did not find valid certificate with thumbprint {0} in StoreName '{1}', StoreLocation '{2}'", | ||
certificate.Thumbprint, | ||
storeName, | ||
storeLocation)); | ||
} | ||
|
||
using (X509Store store = new X509Store(StoreName.Disallowed, storeLocation)) | ||
{ | ||
store.Open(OpenFlags.ReadOnly); | ||
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindByThumbprint, certificate.Thumbprint, validOnly: false); | ||
Assert.True(certificates.Count == 0, "Certificate was found in Disallowed store."); | ||
} | ||
} | ||
catch (InvalidOperationException e) | ||
{ | ||
exception = e; | ||
} | ||
|
||
// *** VALIDATE *** \\ | ||
// Validate rather than allowing an exception to propagate | ||
// to be clear the exception was anticipated. | ||
Assert.True(exception == null, exception == null ? String.Empty : exception.ToString()); | ||
} | ||
} |
123 changes: 0 additions & 123 deletions
123
src/System.Private.ServiceModel/tests/Scenarios/Infrastructure/SetupValidationTests.4.1.1.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters