From c08721c7b39c976bb205468dcbd7fc15151d5077 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Mon, 2 Mar 2015 15:37:35 -0800 Subject: [PATCH] React to AuthN renames --- samples/SelfHostServer/Startup.cs | 2 +- .../AuthenticationHandler.cs | 68 +++--- .../FeatureContext.cs | 2 +- .../AuthenticationManager.cs | 47 ++-- ...ationTypes.cs => AuthenticationSchemes.cs} | 3 +- .../RequestProcessing/RequestContext.cs | 6 +- src/Microsoft.Net.Http.Server/WebListener.cs | 2 +- .../AuthenticationTests.cs | 221 +++++++++--------- .../Utilities.cs | 10 +- .../AuthenticationTests.cs | 90 +++---- .../Utilities.cs | 4 +- 11 files changed, 228 insertions(+), 227 deletions(-) rename src/Microsoft.Net.Http.Server/{AuthenticationTypes.cs => AuthenticationSchemes.cs} (89%) diff --git a/samples/SelfHostServer/Startup.cs b/samples/SelfHostServer/Startup.cs index fae50ab407..1597e5628b 100644 --- a/samples/SelfHostServer/Startup.cs +++ b/samples/SelfHostServer/Startup.cs @@ -33,7 +33,7 @@ namespace SelfHostServer public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory) { var info = (ServerInformation)app.Server; - info.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationTypes.AllowAnonymous; + info.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous; loggerfactory.AddConsole(LogLevel.Verbose); diff --git a/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs b/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs index d565b3f401..7d2f8cd4e5 100644 --- a/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Server.WebListener/AuthenticationHandler.cs @@ -26,7 +26,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; -using Microsoft.AspNet.Http.Interfaces.Security; +using Microsoft.AspNet.Http.Interfaces.Authentication; using Microsoft.Net.Http.Server; namespace Microsoft.AspNet.Server.WebListener @@ -34,14 +34,14 @@ namespace Microsoft.AspNet.Server.WebListener internal class AuthenticationHandler : IAuthenticationHandler { private RequestContext _requestContext; - private AuthenticationTypes _authTypes; - private AuthenticationTypes _customChallenges; + private AuthenticationSchemes _authSchemes; + private AuthenticationSchemes _customChallenges; internal AuthenticationHandler(RequestContext requestContext) { _requestContext = requestContext; - _authTypes = requestContext.AuthenticationChallenges; - _customChallenges = AuthenticationTypes.None; + _authSchemes = requestContext.AuthenticationChallenges; + _customChallenges = AuthenticationSchemes.None; } public void Authenticate(IAuthenticateContext context) @@ -49,19 +49,19 @@ namespace Microsoft.AspNet.Server.WebListener var user = _requestContext.User; var identity = user == null ? null : (ClaimsIdentity)user.Identity; - foreach (var authType in ListEnabledAuthTypes()) + foreach (var authType in ListEnabledAuthSchemes()) { - string authString = authType.ToString(); - if (context.AuthenticationTypes.Contains(authString, StringComparer.Ordinal)) + string authScheme = authType.ToString(); + if (context.AuthenticationSchemes.Contains(authScheme, StringComparer.Ordinal)) { if (identity != null && identity.IsAuthenticated - && string.Equals(authString, identity.AuthenticationType, StringComparison.Ordinal)) + && string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal)) { - context.Authenticated((ClaimsIdentity)user.Identity, properties: null, description: GetDescription(user.Identity.AuthenticationType)); + context.Authenticated(new ClaimsPrincipal(user.Identity), properties: null, description: GetDescription(authScheme)); } else { - context.NotAuthenticated(authString, properties: null, description: GetDescription(user.Identity.AuthenticationType)); + context.NotAuthenticated(authScheme, properties: null, description: GetDescription(authScheme)); } } } @@ -75,27 +75,27 @@ namespace Microsoft.AspNet.Server.WebListener public void Challenge(IChallengeContext context) { - foreach (var authType in ListEnabledAuthTypes()) + foreach (var scheme in ListEnabledAuthSchemes()) { - var authString = authType.ToString(); + var authScheme = scheme.ToString(); // Not including any auth types means it's a blanket challenge for any auth type. - if (context.AuthenticationTypes == null || !context.AuthenticationTypes.Any() - || context.AuthenticationTypes.Contains(authString, StringComparer.Ordinal)) + if (context.AuthenticationSchemes == null || !context.AuthenticationSchemes.Any() + || context.AuthenticationSchemes.Contains(authScheme, StringComparer.Ordinal)) { - _customChallenges |= authType; - context.Accept(authString, GetDescription(authType.ToString())); + _customChallenges |= scheme; + context.Accept(authScheme, GetDescription(authScheme)); } } // A challenge was issued, it overrides any pre-set auth types. _requestContext.AuthenticationChallenges = _customChallenges; } - public void GetDescriptions(IAuthTypeContext context) + public void GetDescriptions(IDescribeSchemesContext context) { // TODO: Caching, this data doesn't change per request. - foreach (var authType in ListEnabledAuthTypes()) + foreach (var scheme in ListEnabledAuthSchemes()) { - context.Accept(GetDescription(authType.ToString())); + context.Accept(GetDescription(scheme.ToString())); } } @@ -109,39 +109,39 @@ namespace Microsoft.AspNet.Server.WebListener // Not supported } - private IDictionary GetDescription(string authenticationType) + private IDictionary GetDescription(string authenticationScheme) { return new Dictionary() { - { "AuthenticationType", authenticationType }, - { "Caption", "Windows:" + authenticationType }, + { "AuthenticationScheme", authenticationScheme }, + { "Caption", "Windows:" + authenticationScheme }, }; } - private IEnumerable ListEnabledAuthTypes() + private IEnumerable ListEnabledAuthSchemes() { // Order by strength. - if ((_authTypes & AuthenticationTypes.Kerberos) == AuthenticationTypes.Kerberos) + if ((_authSchemes & AuthenticationSchemes.Kerberos) == AuthenticationSchemes.Kerberos) { - yield return AuthenticationTypes.Kerberos; + yield return AuthenticationSchemes.Kerberos; } - if ((_authTypes & AuthenticationTypes.Negotiate) == AuthenticationTypes.Negotiate) + if ((_authSchemes & AuthenticationSchemes.Negotiate) == AuthenticationSchemes.Negotiate) { - yield return AuthenticationTypes.Negotiate; + yield return AuthenticationSchemes.Negotiate; } - if ((_authTypes & AuthenticationTypes.NTLM) == AuthenticationTypes.NTLM) + if ((_authSchemes & AuthenticationSchemes.NTLM) == AuthenticationSchemes.NTLM) { - yield return AuthenticationTypes.NTLM; + yield return AuthenticationSchemes.NTLM; } - /*if ((_authTypes & AuthenticationTypes.Digest) == AuthenticationTypes.Digest) + /*if ((_authSchemes & AuthenticationSchemes.Digest) == AuthenticationSchemes.Digest) { // TODO: throw new NotImplementedException("Digest challenge generation has not been implemented."); - yield return AuthenticationTypes.Digest; + yield return AuthenticationSchemes.Digest; }*/ - if ((_authTypes & AuthenticationTypes.Basic) == AuthenticationTypes.Basic) + if ((_authSchemes & AuthenticationSchemes.Basic) == AuthenticationSchemes.Basic) { - yield return AuthenticationTypes.Basic; + yield return AuthenticationSchemes.Basic; } } } diff --git a/src/Microsoft.AspNet.Server.WebListener/FeatureContext.cs b/src/Microsoft.AspNet.Server.WebListener/FeatureContext.cs index ae7c7a482f..8a2e919c6a 100644 --- a/src/Microsoft.AspNet.Server.WebListener/FeatureContext.cs +++ b/src/Microsoft.AspNet.Server.WebListener/FeatureContext.cs @@ -27,7 +27,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http.Interfaces; -using Microsoft.AspNet.Http.Interfaces.Security; +using Microsoft.AspNet.Http.Interfaces.Authentication; using Microsoft.Net.Http.Server; using Microsoft.Net.WebSockets; diff --git a/src/Microsoft.Net.Http.Server/AuthenticationManager.cs b/src/Microsoft.Net.Http.Server/AuthenticationManager.cs index 9be0a01897..adb806c0af 100644 --- a/src/Microsoft.Net.Http.Server/AuthenticationManager.cs +++ b/src/Microsoft.Net.Http.Server/AuthenticationManager.cs @@ -23,7 +23,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Security.Claims; @@ -48,29 +47,29 @@ namespace Microsoft.Net.Http.Server #endif private WebListener _server; - private AuthenticationTypes _authTypes; + private AuthenticationSchemes _authSchemes; internal AuthenticationManager(WebListener listener) { _server = listener; - _authTypes = AuthenticationTypes.AllowAnonymous; + _authSchemes = AuthenticationSchemes.AllowAnonymous; } #region Properties - public AuthenticationTypes AuthenticationTypes + public AuthenticationSchemes AuthenticationSchemes { get { - return _authTypes; + return _authSchemes; } set { - if (_authTypes == AuthenticationTypes.None) + if (_authSchemes == AuthenticationSchemes.None) { throw new ArgumentException("value", "'None' is not a valid authentication type. Use 'AllowAnonymous' instead."); } - _authTypes = value; + _authSchemes = value; SetServerSecurity(); } } @@ -79,7 +78,7 @@ namespace Microsoft.Net.Http.Server { get { - return ((_authTypes & AuthenticationTypes.AllowAnonymous) == AuthenticationTypes.AllowAnonymous); + return ((_authSchemes & AuthenticationSchemes.AllowAnonymous) == AuthenticationSchemes.AllowAnonymous); } } @@ -91,10 +90,10 @@ namespace Microsoft.Net.Http.Server new UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_AUTHENTICATION_INFO(); authInfo.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT; - var authTypes = (UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES)(_authTypes & ~AuthenticationTypes.AllowAnonymous); - if (authTypes != UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES.NONE) + var authSchemes = (UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES)(_authSchemes & ~AuthenticationSchemes.AllowAnonymous); + if (authSchemes != UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES.NONE) { - authInfo.AuthSchemes = authTypes; + authInfo.AuthSchemes = authSchemes; // TODO: // NTLM auth sharing (on by default?) DisableNTLMCredentialCaching @@ -111,35 +110,35 @@ namespace Microsoft.Net.Http.Server } } - internal static IList GenerateChallenges(AuthenticationTypes authTypes) + internal static IList GenerateChallenges(AuthenticationSchemes authSchemes) { IList challenges = new List(); - if (authTypes == AuthenticationTypes.None) + if (authSchemes == AuthenticationSchemes.None) { return challenges; } // Order by strength. - if ((authTypes & AuthenticationTypes.Kerberos) == AuthenticationTypes.Kerberos) + if ((authSchemes & AuthenticationSchemes.Kerberos) == AuthenticationSchemes.Kerberos) { challenges.Add("Kerberos"); } - if ((authTypes & AuthenticationTypes.Negotiate) == AuthenticationTypes.Negotiate) + if ((authSchemes & AuthenticationSchemes.Negotiate) == AuthenticationSchemes.Negotiate) { challenges.Add("Negotiate"); } - if ((authTypes & AuthenticationTypes.NTLM) == AuthenticationTypes.NTLM) + if ((authSchemes & AuthenticationSchemes.NTLM) == AuthenticationSchemes.NTLM) { challenges.Add("NTLM"); } - /*if ((_authTypes & AuthenticationTypes.Digest) == AuthenticationTypes.Digest) + /*if ((_authSchemes & AuthenticationSchemes.Digest) == AuthenticationSchemes.Digest) { // TODO: throw new NotImplementedException("Digest challenge generation has not been implemented."); // challenges.Add("Digest"); }*/ - if ((authTypes & AuthenticationTypes.Basic) == AuthenticationTypes.Basic) + if ((authSchemes & AuthenticationSchemes.Basic) == AuthenticationSchemes.Basic) { // TODO: Realm challenges.Add("Basic"); @@ -180,20 +179,20 @@ namespace Microsoft.Net.Http.Server return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated } - private static AuthenticationTypes GetAuthTypeFromRequest(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE input) + private static AuthenticationSchemes GetAuthTypeFromRequest(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE input) { switch (input) { case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeBasic: - return AuthenticationTypes.Basic; + return AuthenticationSchemes.Basic; // case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeDigest: - // return AuthenticationTypes.Digest; + // return AuthenticationSchemes.Digest; case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNTLM: - return AuthenticationTypes.NTLM; + return AuthenticationSchemes.NTLM; case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNegotiate: - return AuthenticationTypes.Negotiate; + return AuthenticationSchemes.Negotiate; case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeKerberos: - return AuthenticationTypes.Kerberos; + return AuthenticationSchemes.Kerberos; default: throw new NotImplementedException(input.ToString()); } diff --git a/src/Microsoft.Net.Http.Server/AuthenticationTypes.cs b/src/Microsoft.Net.Http.Server/AuthenticationSchemes.cs similarity index 89% rename from src/Microsoft.Net.Http.Server/AuthenticationTypes.cs rename to src/Microsoft.Net.Http.Server/AuthenticationSchemes.cs index a7c39ab7c2..d8ee617c16 100644 --- a/src/Microsoft.Net.Http.Server/AuthenticationTypes.cs +++ b/src/Microsoft.Net.Http.Server/AuthenticationSchemes.cs @@ -19,8 +19,9 @@ using System; namespace Microsoft.Net.Http.Server { + // REVIEW: this appears to be very similar to System.Net.AuthenticationSchemes [Flags] - public enum AuthenticationTypes + public enum AuthenticationSchemes { None = 0x0, Basic = 0x1, diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs index 37862cc392..4a5d7058a4 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs @@ -55,7 +55,7 @@ namespace Microsoft.Net.Http.Server _request = new Request(this, _memoryBlob); _response = new Response(this); _request.ReleasePins(); - AuthenticationChallenges = server.AuthenticationManager.AuthenticationTypes & ~AuthenticationTypes.AllowAnonymous; + AuthenticationChallenges = server.AuthenticationManager.AuthenticationSchemes & ~AuthenticationSchemes.AllowAnonymous; } public Request Request @@ -134,9 +134,9 @@ namespace Microsoft.Net.Http.Server /// /// The authentication challengest that will be added to the response if the status code is 401. - /// This must be a subset of the AuthenticationTypes enabled on the server. + /// This must be a subset of the AuthenticationSchemes enabled on the server. /// - public AuthenticationTypes AuthenticationChallenges { get; set; } + public AuthenticationSchemes AuthenticationChallenges { get; set; } public bool IsUpgradableRequest { diff --git a/src/Microsoft.Net.Http.Server/WebListener.cs b/src/Microsoft.Net.Http.Server/WebListener.cs index e31e158314..3185a414db 100644 --- a/src/Microsoft.Net.Http.Server/WebListener.cs +++ b/src/Microsoft.Net.Http.Server/WebListener.cs @@ -592,7 +592,7 @@ namespace Microsoft.Net.Http.Server if (!AuthenticationManager.AllowAnonymous && !AuthenticationManager.CheckAuthenticated(requestV2->pRequestInfo)) { SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.Unauthorized, - AuthenticationManager.GenerateChallenges(AuthenticationManager.AuthenticationTypes)); + AuthenticationManager.GenerateChallenges(AuthenticationManager.AuthenticationSchemes)); return false; } return true; diff --git a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs index 6e65b638e5..e96b810101 100644 --- a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs +++ b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/AuthenticationTests.cs @@ -24,23 +24,24 @@ using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http.Core; using Microsoft.Net.Http.Server; using Xunit; +using AuthenticationSchemes = Microsoft.Net.Http.Server.AuthenticationSchemes; namespace Microsoft.AspNet.Server.WebListener { public class AuthenticationTests { [Theory] - [InlineData(AuthenticationTypes.AllowAnonymous)] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.AllowAnonymous)] + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationSchemes authType) { string address; - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -55,12 +56,12 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - [InlineData(AuthenticationTypes.Basic)] - public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + [InlineData(AuthenticationSchemes.Basic)] + public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType) { string address; using (Utilities.CreateHttpAuthServer(authType, out address, env => @@ -75,15 +76,15 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - [InlineData(AuthenticationTypes.Basic)] - public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + [InlineData(AuthenticationSchemes.Basic)] + public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType) { string address; - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -103,12 +104,12 @@ namespace Microsoft.AspNet.Server.WebListener { string address; using (Utilities.CreateHttpAuthServer( - AuthenticationTypes.Kerberos - | AuthenticationTypes.Negotiate - | AuthenticationTypes.NTLM - /* | AuthenticationTypes.Digest TODO: Not implemented */ - | AuthenticationTypes.Basic - | AuthenticationTypes.AllowAnonymous, + AuthenticationSchemes.Kerberos + | AuthenticationSchemes.Negotiate + | AuthenticationSchemes.NTLM + /* | AuthenticationSchemes.Digest TODO: Not implemented */ + | AuthenticationSchemes.Basic + | AuthenticationSchemes.AllowAnonymous, out address, env => { @@ -126,17 +127,17 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - // [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /* AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + // [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /* AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationSchemes authType) { string address; int requestId = 0; - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -163,13 +164,13 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - // [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /* AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_RequireAuth_Success(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + // [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /* AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_RequireAuth_Success(AuthenticationSchemes authType) { string address; using (Utilities.CreateHttpAuthServer(authType, out address, env => @@ -186,21 +187,21 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.AllowAnonymous)] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - // [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_GetSingleDescriptions(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.AllowAnonymous)] + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + // [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_GetSingleDescriptions(AuthenticationSchemes authType) { string address; - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); - var resultList = context.GetAuthenticationTypes(); - if (authType == AuthenticationTypes.AllowAnonymous) + var resultList = context.GetAuthenticationSchemes(); + if (authType == AuthenticationSchemes.AllowAnonymous) { Assert.Equal(0, resultList.Count()); } @@ -208,7 +209,7 @@ namespace Microsoft.AspNet.Server.WebListener { Assert.Equal(1, resultList.Count()); var result = resultList.First(); - Assert.Equal(authType.ToString(), result.AuthenticationType); + Assert.Equal(authType.ToString(), result.AuthenticationScheme); Assert.Equal("Windows:" + authType.ToString(), result.Caption); } @@ -225,16 +226,16 @@ namespace Microsoft.AspNet.Server.WebListener public async Task AuthTypes_GetMultipleDescriptions() { string address; - AuthenticationTypes authType = - AuthenticationTypes.Kerberos - | AuthenticationTypes.Negotiate - | AuthenticationTypes.NTLM - | /*AuthenticationTypes.Digest - |*/ AuthenticationTypes.Basic; - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + AuthenticationSchemes authType = + AuthenticationSchemes.Kerberos + | AuthenticationSchemes.Negotiate + | AuthenticationSchemes.NTLM + | /*AuthenticationSchemes.Digest + |*/ AuthenticationSchemes.Basic; + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); - var resultList = context.GetAuthenticationTypes(); + var resultList = context.GetAuthenticationSchemes(); Assert.Equal(4, resultList.Count()); return Task.FromResult(0); })) @@ -246,17 +247,17 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_AuthenticateWithNoUser_NoResults(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_AuthenticateWithNoUser_NoResults(AuthenticationSchemes authType) { string address; var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -273,13 +274,13 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - // [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_AuthenticateWithUser_OneResult(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + // [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_AuthenticateWithUser_OneResult(AuthenticationSchemes authType) { string address; var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); @@ -299,17 +300,17 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(AuthenticationSchemes authType) { string address; var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -325,17 +326,17 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(AuthenticationSchemes authType) { string address; var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); - using (Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -351,16 +352,16 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationSchemes authType) { string address; - var authTypes = AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic; - using (Utilities.CreateHttpAuthServer(authTypes | AuthenticationTypes.AllowAnonymous, out address, env => + var authTypes = AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic; + using (Utilities.CreateHttpAuthServer(authTypes | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); @@ -377,18 +378,18 @@ namespace Microsoft.AspNet.Server.WebListener } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - public async Task AuthTypes_ChallengeDisabledAuthType_Error(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + public async Task AuthTypes_ChallengeDisabledAuthType_Error(AuthenticationSchemes authType) { string address; - var authTypes = AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic; + var authTypes = AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic; authTypes = authTypes & ~authType; var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); - using (Utilities.CreateHttpAuthServer(authTypes | AuthenticationTypes.AllowAnonymous, out address, env => + using (Utilities.CreateHttpAuthServer(authTypes | AuthenticationSchemes.AllowAnonymous, out address, env => { var context = new DefaultHttpContext((IFeatureCollection)env); Assert.NotNull(context.User); diff --git a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs index 5315a6952f..5e70a77b50 100644 --- a/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs +++ b/test/Microsoft.AspNet.Server.WebListener.FunctionalTests/Utilities.cs @@ -33,22 +33,22 @@ namespace Microsoft.AspNet.Server.WebListener internal static IDisposable CreateHttpServer(out string baseAddress, AppFunc app) { string root; - return CreateDynamicHttpServer(string.Empty, AuthenticationTypes.AllowAnonymous, out root, out baseAddress, app); + return CreateDynamicHttpServer(string.Empty, AuthenticationSchemes.AllowAnonymous, out root, out baseAddress, app); } internal static IDisposable CreateHttpServerReturnRoot(string path, out string root, AppFunc app) { string baseAddress; - return CreateDynamicHttpServer(path, AuthenticationTypes.AllowAnonymous, out root, out baseAddress, app); + return CreateDynamicHttpServer(path, AuthenticationSchemes.AllowAnonymous, out root, out baseAddress, app); } - internal static IDisposable CreateHttpAuthServer(AuthenticationTypes authType, out string baseAddress, AppFunc app) + internal static IDisposable CreateHttpAuthServer(AuthenticationSchemes authType, out string baseAddress, AppFunc app) { string root; return CreateDynamicHttpServer(string.Empty, authType, out root, out baseAddress, app); } - internal static IDisposable CreateDynamicHttpServer(string basePath, AuthenticationTypes authType, out string root, out string baseAddress, AppFunc app) + internal static IDisposable CreateDynamicHttpServer(string basePath, AuthenticationSchemes authType, out string root, out string baseAddress, AppFunc app) { var factory = new ServerFactory(loggerFactory: null); lock (PortLock) @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Server.WebListener var serverInfo = (ServerInformation)factory.Initialize(configuration: null); serverInfo.Listener.UrlPrefixes.Add(prefix); - serverInfo.Listener.AuthenticationManager.AuthenticationTypes = authType; + serverInfo.Listener.AuthenticationManager.AuthenticationSchemes = authType; try { return factory.Start(serverInfo, app); diff --git a/test/Microsoft.Net.Http.Server.FunctionalTests/AuthenticationTests.cs b/test/Microsoft.Net.Http.Server.FunctionalTests/AuthenticationTests.cs index 09f501fa24..f9e9316dc8 100644 --- a/test/Microsoft.Net.Http.Server.FunctionalTests/AuthenticationTests.cs +++ b/test/Microsoft.Net.Http.Server.FunctionalTests/AuthenticationTests.cs @@ -11,26 +11,26 @@ namespace Microsoft.Net.Http.Server public class AuthenticationTests { [Theory] - [InlineData(AuthenticationTypes.AllowAnonymous)] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] - [InlineData(AuthenticationTypes.Basic)] - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.AllowAnonymous)] + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] + [InlineData(AuthenticationSchemes.Basic)] + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationSchemes authType) { string address; - using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address)) + using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address)) { Task responseTask = SendRequestAsync(address); var context = await server.GetContextAsync(); Assert.NotNull(context.User); Assert.False(context.User.Identity.IsAuthenticated); - if (authType == AuthenticationTypes.AllowAnonymous) + if (authType == AuthenticationSchemes.AllowAnonymous) { - Assert.Equal(AuthenticationTypes.None, context.AuthenticationChallenges); + Assert.Equal(AuthenticationSchemes.None, context.AuthenticationChallenges); } else { @@ -45,12 +45,12 @@ namespace Microsoft.Net.Http.Server } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] // [InlineData(AuthenticationType.Digest)] // TODO: Not implemented - [InlineData(AuthenticationTypes.Basic)] - public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Basic)] + public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType) { string address; using (var server = Utilities.CreateHttpAuthServer(authType, out address)) @@ -66,15 +66,15 @@ namespace Microsoft.Net.Http.Server } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - [InlineData(AuthenticationTypes.Basic)] - public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + [InlineData(AuthenticationSchemes.Basic)] + public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType) { string address; - using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address)) + using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address)) { Task responseTask = SendRequestAsync(address); @@ -95,13 +95,13 @@ namespace Microsoft.Net.Http.Server public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded() { string address; - AuthenticationTypes authType = - AuthenticationTypes.Kerberos - | AuthenticationTypes.Negotiate - | AuthenticationTypes.NTLM - /* | AuthenticationTypes.Digest TODO: Not implemented */ - | AuthenticationTypes.Basic; - using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address)) + AuthenticationSchemes authType = + AuthenticationSchemes.Kerberos + | AuthenticationSchemes.Negotiate + | AuthenticationSchemes.NTLM + /* | AuthenticationSchemes.Digest TODO: Not implemented */ + | AuthenticationSchemes.Basic; + using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address)) { Task responseTask = SendRequestAsync(address); @@ -119,16 +119,16 @@ namespace Microsoft.Net.Http.Server } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - // [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + // [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationSchemes authType) { string address; - using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address)) + using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address)) { Task responseTask = SendRequestAsync(address, useDefaultCredentials: true); @@ -151,13 +151,13 @@ namespace Microsoft.Net.Http.Server } [Theory] - [InlineData(AuthenticationTypes.Kerberos)] - [InlineData(AuthenticationTypes.Negotiate)] - [InlineData(AuthenticationTypes.NTLM)] - // [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented - // [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds - [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationTypes.Basic)] - public async Task AuthTypes_RequireAuth_Success(AuthenticationTypes authType) + [InlineData(AuthenticationSchemes.Kerberos)] + [InlineData(AuthenticationSchemes.Negotiate)] + [InlineData(AuthenticationSchemes.NTLM)] + // [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented + // [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds + [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationSchemes.Basic)] + public async Task AuthTypes_RequireAuth_Success(AuthenticationSchemes authType) { string address; using (var server = Utilities.CreateHttpAuthServer(authType, out address)) diff --git a/test/Microsoft.Net.Http.Server.FunctionalTests/Utilities.cs b/test/Microsoft.Net.Http.Server.FunctionalTests/Utilities.cs index 8e8fdf16d7..fd732e11a4 100644 --- a/test/Microsoft.Net.Http.Server.FunctionalTests/Utilities.cs +++ b/test/Microsoft.Net.Http.Server.FunctionalTests/Utilities.cs @@ -11,10 +11,10 @@ namespace Microsoft.Net.Http.Server private static int NextPort = BasePort; private static object PortLock = new object(); - internal static WebListener CreateHttpAuthServer(AuthenticationTypes authType, out string baseAddress) + internal static WebListener CreateHttpAuthServer(AuthenticationSchemes authScheme, out string baseAddress) { var listener = CreateHttpServer(out baseAddress); - listener.AuthenticationManager.AuthenticationTypes = authType; + listener.AuthenticationManager.AuthenticationSchemes = authScheme; return listener; }