public void ServiceCredentialsElement_defaults() { ServiceCredentialsElement element = new ServiceCredentialsElement(); Assert.AreEqual(typeof(ServiceCredentials), element.BehaviorType, "BehaviorType"); Assert.AreEqual("serviceCredentials", element.ConfigurationElementName, "ConfigurationElementName"); Assert.AreEqual(String.Empty, element.Type, "Type"); Assert.AreEqual(String.Empty, element.ClientCertificate.Certificate.FindValue, "ClientCertificate.Certificate.FindValue"); Assert.AreEqual(StoreLocation.LocalMachine, element.ClientCertificate.Certificate.StoreLocation, "ClientCertificate.Certificate.StoreLocation"); Assert.AreEqual(StoreName.My, element.ClientCertificate.Certificate.StoreName, "ClientCertificate.Certificate.StoreName"); Assert.AreEqual(X509FindType.FindBySubjectDistinguishedName, element.ClientCertificate.Certificate.X509FindType, "ClientCertificate.Certificate.X509FindType"); Assert.AreEqual(String.Empty, element.ClientCertificate.Authentication.CustomCertificateValidatorType, "ClientCertificate.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.ChainTrust, element.ClientCertificate.Authentication.CertificateValidationMode, "ClientCertificate.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Online, element.ClientCertificate.Authentication.RevocationMode, "ClientCertificate.Authentication.RevocationMode"); Assert.AreEqual(StoreLocation.LocalMachine, element.ClientCertificate.Authentication.TrustedStoreLocation, "ClientCertificate.Authentication.TrustedStoreLocation"); Assert.AreEqual(true, element.ClientCertificate.Authentication.IncludeWindowsGroups, "ClientCertificate.Authentication.IncludeWindowsGroups"); Assert.AreEqual(false, element.ClientCertificate.Authentication.MapClientCertificateToWindowsAccount, "ClientCertificate.Authentication.MapClientCertificateToWindowsAccount"); Assert.AreEqual(String.Empty, element.ServiceCertificate.FindValue, "ServiceCertificate.FindValue"); Assert.AreEqual(StoreLocation.LocalMachine, element.ServiceCertificate.StoreLocation, "ServiceCertificate.StoreLocation"); Assert.AreEqual(StoreName.My, element.ServiceCertificate.StoreName, "ServiceCertificate.StoreName"); Assert.AreEqual(X509FindType.FindBySubjectDistinguishedName, element.ServiceCertificate.X509FindType, "ServiceCertificate.X509FindType"); Assert.AreEqual(UserNamePasswordValidationMode.Windows, element.UserNameAuthentication.UserNamePasswordValidationMode, "UserNameAuthentication.UserNamePasswordValidationMode"); Assert.AreEqual(true, element.UserNameAuthentication.IncludeWindowsGroups, "UserNameAuthentication.IncludeWindowsGroups"); Assert.AreEqual(String.Empty, element.UserNameAuthentication.MembershipProviderName, "UserNameAuthentication.MembershipProviderName"); Assert.AreEqual(String.Empty, element.UserNameAuthentication.CustomUserNamePasswordValidatorType, "UserNameAuthentication.customUserNamePasswordValidatorType"); Assert.AreEqual(false, element.UserNameAuthentication.CacheLogonTokens, "UserNameAuthentication.CacheLogonTokens"); Assert.AreEqual(128, element.UserNameAuthentication.MaxCachedLogonTokens, "UserNameAuthentication.MaxCachedLogonTokens"); Assert.AreEqual(new TimeSpan(0, 15, 0), element.UserNameAuthentication.CachedLogonTokenLifetime, "UserNameAuthentication.CachedLogonTokenLifetime"); Assert.AreEqual(String.Empty, element.Peer.Certificate.FindValue, "Peer.Certificate.FindValue"); Assert.AreEqual(StoreLocation.CurrentUser, element.Peer.Certificate.StoreLocation, "Peer.Certificate.StoreLocation"); Assert.AreEqual(StoreName.My, element.Peer.Certificate.StoreName, "Peer.Certificate.StoreName"); Assert.AreEqual(X509FindType.FindBySubjectDistinguishedName, element.Peer.Certificate.X509FindType, "Peer.Certificate.X509FindType"); Assert.AreEqual(String.Empty, element.Peer.PeerAuthentication.CustomCertificateValidatorType, "Peer.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.PeerOrChainTrust, element.Peer.PeerAuthentication.CertificateValidationMode, "Peer.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Online, element.Peer.PeerAuthentication.RevocationMode, "Peer.Authentication.RevocationMode"); Assert.AreEqual(StoreLocation.CurrentUser, element.Peer.PeerAuthentication.TrustedStoreLocation, "Peer.Authentication.TrustedStoreLocation"); Assert.AreEqual(String.Empty, element.Peer.MessageSenderAuthentication.CustomCertificateValidatorType, "Peer.MessageSenderAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.PeerOrChainTrust, element.Peer.MessageSenderAuthentication.CertificateValidationMode, "Peer.MessageSenderAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Online, element.Peer.MessageSenderAuthentication.RevocationMode, "Peer.MessageSenderAuthentication.RevocationMode"); Assert.AreEqual(StoreLocation.CurrentUser, element.Peer.MessageSenderAuthentication.TrustedStoreLocation, "Peer.MessageSenderAuthentication.TrustedStoreLocation"); Assert.AreEqual(String.Empty, element.IssuedTokenAuthentication.CustomCertificateValidatorType, "IssuedTokenAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.ChainTrust, element.IssuedTokenAuthentication.CertificateValidationMode, "IssuedTokenAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Online, element.IssuedTokenAuthentication.RevocationMode, "IssuedTokenAuthentication.RevocationMode"); Assert.AreEqual(StoreLocation.LocalMachine, element.IssuedTokenAuthentication.TrustedStoreLocation, "IssuedTokenAuthentication.TrustedStoreLocation"); Assert.AreEqual(String.Empty, element.IssuedTokenAuthentication.SamlSerializerType, "IssuedTokenAuthentication.SamlSerializerType"); Assert.AreEqual(false, element.IssuedTokenAuthentication.AllowUntrustedRsaIssuers, "IssuedTokenAuthentication.AllowUntrustedRsaIssuers"); Assert.AreEqual(0, element.IssuedTokenAuthentication.KnownCertificates.Count, "IssuedTokenAuthentication.KnownCertificates.Count"); Assert.AreEqual(String.Empty, element.SecureConversationAuthentication.SecurityStateEncoderType, "SecureConversationAuthentication.SecurityStateEncoderType"); }
public void GetBehaviorExtensionTest() { NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> element = LoadManager().GetBehavior(Constants.ServiceBehaviorExtension); ServiceCredentialsElement extension = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ServiceCredentialsElement>(element); Assert.IsNotNull(extension); Assert.AreEqual(Constants.TestCert, extension.ServiceCertificate.FindValue); }
public void UpdateBehaviorExtensionTest() { NamedServiceModelExtensionCollectionElement <BehaviorExtensionElement> element = LoadManager().GetBehavior(Constants.ServiceBehaviorName); ServiceCredentialsElement extension = new ServiceCredentialsElement(); extension.UserNameAuthentication.MembershipProviderName = Constants.MembershipProviderName; ServiceCredentialsElement updatedExtension = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ServiceCredentialsElement>(element); Assert.IsNotNull(updatedExtension); Assert.AreEqual(updatedExtension.BehaviorType, extension.BehaviorType); Assert.AreEqual(Constants.MembershipProviderName, updatedExtension.UserNameAuthentication.MembershipProviderName); }
/// <summary> /// Checks the specified configuration manager. /// </summary> /// <param name="configurationManager">The configuration manager.</param> /// <returns></returns> public override ProblemCollection Check(ServiceModelConfigurationManager configurationManager) { foreach (ServiceBehaviorElement behaviorElement in configurationManager.ServiceModelSection.Behaviors.ServiceBehaviors) { ServiceCredentialsElement serviceCredentials = ServiceModelConfigurationManager.GetBehaviorExtensionElement <ServiceCredentialsElement>(behaviorElement); X509RevocationMode revocationMode = serviceCredentials.ClientCertificate.Authentication.RevocationMode; if (revocationMode == X509RevocationMode.NoCheck) { Resolution resolution = base.GetResolution(revocationMode.ToString()); Problem problem = new Problem(resolution); problem.SourceFile = base.SourceFile; base.Problems.Add(problem); } } return(base.Problems); }
public void ServiceCredentialsElement() { ServiceBehaviorElement behavior = OpenConfig(); ServiceCredentialsElement element = (ServiceCredentialsElement)behavior [typeof(ServiceCredentialsElement)]; if (element == null) { Assert.Fail("ServiceCredentialsElement is not exist in collection."); } Assert.AreEqual(typeof(ServiceCredentials), element.BehaviorType, "BehaviorType"); Assert.AreEqual("serviceCredentials", element.ConfigurationElementName, "ConfigurationElementName"); Assert.AreEqual("ServiceCredentialsType", element.Type, "Type"); Assert.AreEqual("FindValue", element.ClientCertificate.Certificate.FindValue, "ClientCertificate.Certificate.FindValue"); Assert.AreEqual(StoreLocation.CurrentUser, element.ClientCertificate.Certificate.StoreLocation, "ClientCertificate.Certificate.StoreLocation"); Assert.AreEqual(StoreName.Root, element.ClientCertificate.Certificate.StoreName, "ClientCertificate.Certificate.StoreName"); Assert.AreEqual(X509FindType.FindByIssuerName, element.ClientCertificate.Certificate.X509FindType, "ClientCertificate.Certificate.X509FindType"); Assert.AreEqual("CustomCertificateValidationType", element.ClientCertificate.Authentication.CustomCertificateValidatorType, "ClientCertificate.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.PeerOrChainTrust, element.ClientCertificate.Authentication.CertificateValidationMode, "ClientCertificate.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Offline, element.ClientCertificate.Authentication.RevocationMode, "ClientCertificate.Authentication.RevocationMode"); Assert.AreEqual(StoreLocation.CurrentUser, element.ClientCertificate.Authentication.TrustedStoreLocation, "ClientCertificate.Authentication.TrustedStoreLocation"); Assert.AreEqual(false, element.ClientCertificate.Authentication.IncludeWindowsGroups, "ClientCertificate.Authentication.IncludeWindowsGroups"); Assert.AreEqual(true, element.ClientCertificate.Authentication.MapClientCertificateToWindowsAccount, "ClientCertificate.Authentication.MapClientCertificateToWindowsAccount"); Assert.AreEqual("FindValue", element.ServiceCertificate.FindValue, "ServiceCertificate.FindValue"); Assert.AreEqual(StoreLocation.CurrentUser, element.ServiceCertificate.StoreLocation, "ServiceCertificate.StoreLocation"); Assert.AreEqual(StoreName.Root, element.ServiceCertificate.StoreName, "ServiceCertificate.StoreName"); Assert.AreEqual(X509FindType.FindByIssuerName, element.ServiceCertificate.X509FindType, "ServiceCertificate.X509FindType"); Assert.AreEqual(UserNamePasswordValidationMode.MembershipProvider, element.UserNameAuthentication.UserNamePasswordValidationMode, "UserNameAuthentication.UserNamePasswordValidationMode"); Assert.AreEqual(false, element.UserNameAuthentication.IncludeWindowsGroups, "UserNameAuthentication.IncludeWindowsGroups"); Assert.AreEqual("MembershipProviderName", element.UserNameAuthentication.MembershipProviderName, "UserNameAuthentication.MembershipProviderName"); Assert.AreEqual("CustomUserNamePasswordValidatorType", element.UserNameAuthentication.CustomUserNamePasswordValidatorType, "UserNameAuthentication.customUserNamePasswordValidatorType"); Assert.AreEqual(true, element.UserNameAuthentication.CacheLogonTokens, "UserNameAuthentication.CacheLogonTokens"); Assert.AreEqual(252, element.UserNameAuthentication.MaxCachedLogonTokens, "UserNameAuthentication.MaxCachedLogonTokens"); Assert.AreEqual(new TimeSpan(0, 30, 0), element.UserNameAuthentication.CachedLogonTokenLifetime, "UserNameAuthentication.CachedLogonTokenLifetime"); Assert.AreEqual("FindValue", element.Peer.Certificate.FindValue, "Peer.Certificate.FindValue"); Assert.AreEqual(StoreLocation.LocalMachine, element.Peer.Certificate.StoreLocation, "Peer.Certificate.StoreLocation"); Assert.AreEqual(StoreName.Root, element.Peer.Certificate.StoreName, "Peer.Certificate.StoreName"); Assert.AreEqual(X509FindType.FindByIssuerName, element.Peer.Certificate.X509FindType, "Peer.Certificate.X509FindType"); Assert.AreEqual("CustomCertificateValidatorType", element.Peer.PeerAuthentication.CustomCertificateValidatorType, "Peer.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.Custom, element.Peer.PeerAuthentication.CertificateValidationMode, "Peer.Authentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Offline, element.Peer.PeerAuthentication.RevocationMode, "Peer.Authentication.RevocationMode"); Assert.AreEqual(StoreLocation.LocalMachine, element.Peer.PeerAuthentication.TrustedStoreLocation, "Peer.Authentication.TrustedStoreLocation"); Assert.AreEqual("CustomCertificateValidatorType", element.Peer.MessageSenderAuthentication.CustomCertificateValidatorType, "Peer.MessageSenderAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.None, element.Peer.MessageSenderAuthentication.CertificateValidationMode, "Peer.MessageSenderAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Offline, element.Peer.MessageSenderAuthentication.RevocationMode, "Peer.MessageSenderAuthentication.RevocationMode"); Assert.AreEqual(StoreLocation.LocalMachine, element.Peer.MessageSenderAuthentication.TrustedStoreLocation, "Peer.MessageSenderAuthentication.TrustedStoreLocation"); Assert.AreEqual("CustomCertificateValidatorType", element.IssuedTokenAuthentication.CustomCertificateValidatorType, "IssuedTokenAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509CertificateValidationMode.PeerOrChainTrust, element.IssuedTokenAuthentication.CertificateValidationMode, "IssuedTokenAuthentication.CustomCertificateValidatorType"); Assert.AreEqual(X509RevocationMode.Offline, element.IssuedTokenAuthentication.RevocationMode, "IssuedTokenAuthentication.RevocationMode"); Assert.AreEqual(StoreLocation.CurrentUser, element.IssuedTokenAuthentication.TrustedStoreLocation, "IssuedTokenAuthentication.TrustedStoreLocation"); Assert.AreEqual("SalmSerializerType", element.IssuedTokenAuthentication.SamlSerializerType, "IssuedTokenAuthentication.SamlSerializerType"); Assert.AreEqual(true, element.IssuedTokenAuthentication.AllowUntrustedRsaIssuers, "IssuedTokenAuthentication.AllowUntrustedRsaIssuers"); Assert.AreEqual("FindValue", element.IssuedTokenAuthentication.KnownCertificates [0].FindValue, "IssuedTokenAuthentication.KnownCertificates[0].FindValue"); Assert.AreEqual(StoreLocation.CurrentUser, element.IssuedTokenAuthentication.KnownCertificates [0].StoreLocation, "IssuedTokenAuthentication.KnownCertificates[0].StoreLocation"); Assert.AreEqual(StoreName.Root, element.IssuedTokenAuthentication.KnownCertificates [0].StoreName, "IssuedTokenAuthentication.KnownCertificates[0].StoreName"); Assert.AreEqual(X509FindType.FindByIssuerName, element.IssuedTokenAuthentication.KnownCertificates [0].X509FindType, "IssuedTokenAuthentication.KnownCertificates[0].X509FindType"); Assert.AreEqual("SecurityStateEncoderType", element.SecureConversationAuthentication.SecurityStateEncoderType, "SecureConversationAuthentication.SecurityStateEncoderType"); }