Skip to content

Commit f65cfd4

Browse files
committed
Propagate all relevant properties from HttpTransportSecurity to HttpTransportBindingElement
1 parent 2b96bbf commit f65cfd4

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/System.Private.ServiceModel/src/System/ServiceModel/HttpProxyCredentialType.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ internal static bool IsDefined(HttpProxyCredentialType value)
2727
value == HttpProxyCredentialType.Windows);
2828
}
2929

30+
internal static AuthenticationSchemes MapToAuthenticationScheme(HttpProxyCredentialType proxyCredentialType)
31+
{
32+
AuthenticationSchemes result;
33+
switch (proxyCredentialType)
34+
{
35+
case HttpProxyCredentialType.None:
36+
result = AuthenticationSchemes.Anonymous;
37+
break;
38+
case HttpProxyCredentialType.Basic:
39+
result = AuthenticationSchemes.Basic;
40+
break;
41+
case HttpProxyCredentialType.Digest:
42+
result = AuthenticationSchemes.Digest;
43+
break;
44+
case HttpProxyCredentialType.Ntlm:
45+
result = AuthenticationSchemes.Ntlm;
46+
break;
47+
case HttpProxyCredentialType.Windows:
48+
result = AuthenticationSchemes.Negotiate;
49+
break;
50+
default:
51+
Fx.Assert("unsupported proxy credential type");
52+
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException());
53+
}
54+
return result;
55+
}
56+
3057
internal static HttpProxyCredentialType MapToProxyCredentialType(AuthenticationSchemes authenticationSchemes)
3158
{
3259
HttpProxyCredentialType result;

src/System.Private.ServiceModel/src/System/ServiceModel/HttpTransportSecurity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ internal void ConfigureTransportProtectionOnly(HttpsTransportBindingElement http
9090
private void ConfigureAuthentication(HttpTransportBindingElement http)
9191
{
9292
http.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(_clientCredentialType);
93+
http.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(_proxyCredentialType);
9394
http.Realm = Realm;
95+
http.ExtendedProtectionPolicy = ExtendedProtectionPolicy;
9496
}
9597

9698
private static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity)

src/System.ServiceModel.Http/tests/ServiceModel/BasicHttpBindingTest.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55

66
using System;
7+
using System.Net;
8+
using System.Security.Authentication.ExtendedProtection;
79
using System.ServiceModel;
810
using System.ServiceModel.Channels;
911
using System.ServiceModel.Tests.Common;
@@ -311,4 +313,30 @@ public static void TransferMode_Property_Sets(TransferMode transferMode)
311313
binding.TransferMode = transferMode;
312314
Assert.Equal<TransferMode>(transferMode, binding.TransferMode);
313315
}
316+
317+
[WcfTheory]
318+
[InlineData(HttpProxyCredentialType.Basic, AuthenticationSchemes.Basic)]
319+
[InlineData(HttpProxyCredentialType.Digest, AuthenticationSchemes.Digest)]
320+
[InlineData(HttpProxyCredentialType.None, AuthenticationSchemes.Anonymous)]
321+
[InlineData(HttpProxyCredentialType.Ntlm, AuthenticationSchemes.Ntlm)]
322+
[InlineData(HttpProxyCredentialType.Windows, AuthenticationSchemes.Negotiate)]
323+
public static void ProxyCredentialType_Propagates_To_TransportBindingElement(HttpProxyCredentialType credentialType, AuthenticationSchemes mappedAuthScheme)
324+
{
325+
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
326+
binding.Security.Transport.ProxyCredentialType = credentialType;
327+
var be = binding.CreateBindingElements();
328+
var htbe = be.Find<HttpTransportBindingElement>();
329+
Assert.Equal(mappedAuthScheme, htbe.ProxyAuthenticationScheme);
330+
}
331+
332+
[WcfFact]
333+
public static void ExtendedProtectionPolicy_Propagates_To_TransportBindingElement()
334+
{
335+
var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
336+
var epp = new ExtendedProtectionPolicy(PolicyEnforcement.Always);
337+
binding.Security.Transport.ExtendedProtectionPolicy = epp;
338+
var be = binding.CreateBindingElements();
339+
var htbe = be.Find<HttpTransportBindingElement>();
340+
Assert.Equal(epp, htbe.ExtendedProtectionPolicy);
341+
}
314342
}

0 commit comments

Comments
 (0)