Skip to content

Commit

Permalink
Propagate all relevant properties from HttpTransportSecurity to HttpT…
Browse files Browse the repository at this point in the history
…ransportBindingElement
  • Loading branch information
mconnew committed Aug 14, 2019
1 parent 2b96bbf commit f65cfd4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ internal static bool IsDefined(HttpProxyCredentialType value)
value == HttpProxyCredentialType.Windows);
}

internal static AuthenticationSchemes MapToAuthenticationScheme(HttpProxyCredentialType proxyCredentialType)
{
AuthenticationSchemes result;
switch (proxyCredentialType)
{
case HttpProxyCredentialType.None:
result = AuthenticationSchemes.Anonymous;
break;
case HttpProxyCredentialType.Basic:
result = AuthenticationSchemes.Basic;
break;
case HttpProxyCredentialType.Digest:
result = AuthenticationSchemes.Digest;
break;
case HttpProxyCredentialType.Ntlm:
result = AuthenticationSchemes.Ntlm;
break;
case HttpProxyCredentialType.Windows:
result = AuthenticationSchemes.Negotiate;
break;
default:
Fx.Assert("unsupported proxy credential type");
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
}
return result;
}

internal static HttpProxyCredentialType MapToProxyCredentialType(AuthenticationSchemes authenticationSchemes)
{
HttpProxyCredentialType result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ internal void ConfigureTransportProtectionOnly(HttpsTransportBindingElement http
private void ConfigureAuthentication(HttpTransportBindingElement http)
{
http.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(_clientCredentialType);
http.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(_proxyCredentialType);
http.Realm = Realm;
http.ExtendedProtectionPolicy = ExtendedProtectionPolicy;
}

private static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


using System;
using System.Net;
using System.Security.Authentication.ExtendedProtection;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Tests.Common;
Expand Down Expand Up @@ -311,4 +313,30 @@ public static void TransferMode_Property_Sets(TransferMode transferMode)
binding.TransferMode = transferMode;
Assert.Equal<TransferMode>(transferMode, binding.TransferMode);
}

[WcfTheory]
[InlineData(HttpProxyCredentialType.Basic, AuthenticationSchemes.Basic)]
[InlineData(HttpProxyCredentialType.Digest, AuthenticationSchemes.Digest)]
[InlineData(HttpProxyCredentialType.None, AuthenticationSchemes.Anonymous)]
[InlineData(HttpProxyCredentialType.Ntlm, AuthenticationSchemes.Ntlm)]
[InlineData(HttpProxyCredentialType.Windows, AuthenticationSchemes.Negotiate)]
public static void ProxyCredentialType_Propagates_To_TransportBindingElement(HttpProxyCredentialType credentialType, AuthenticationSchemes mappedAuthScheme)
{
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.Security.Transport.ProxyCredentialType = credentialType;
var be = binding.CreateBindingElements();
var htbe = be.Find<HttpTransportBindingElement>();
Assert.Equal(mappedAuthScheme, htbe.ProxyAuthenticationScheme);
}

[WcfFact]
public static void ExtendedProtectionPolicy_Propagates_To_TransportBindingElement()
{
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
var epp = new ExtendedProtectionPolicy(PolicyEnforcement.Always);
binding.Security.Transport.ExtendedProtectionPolicy = epp;
var be = binding.CreateBindingElements();
var htbe = be.Find<HttpTransportBindingElement>();
Assert.Equal(epp, htbe.ExtendedProtectionPolicy);
}
}

0 comments on commit f65cfd4

Please sign in to comment.