Skip to content

Propagate all relevant properties from HttpTransportSecurity to HttpTransportBindingElement #3818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}