React to AuthN renames
This commit is contained in:
parent
fc6b855f42
commit
c08721c7b3
|
|
@ -33,7 +33,7 @@ namespace SelfHostServer
|
||||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
|
public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
|
||||||
{
|
{
|
||||||
var info = (ServerInformation)app.Server;
|
var info = (ServerInformation)app.Server;
|
||||||
info.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationTypes.AllowAnonymous;
|
info.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous;
|
||||||
|
|
||||||
loggerfactory.AddConsole(LogLevel.Verbose);
|
loggerfactory.AddConsole(LogLevel.Verbose);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Http.Interfaces.Security;
|
using Microsoft.AspNet.Http.Interfaces.Authentication;
|
||||||
using Microsoft.Net.Http.Server;
|
using Microsoft.Net.Http.Server;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.WebListener
|
namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
@ -34,14 +34,14 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
internal class AuthenticationHandler : IAuthenticationHandler
|
internal class AuthenticationHandler : IAuthenticationHandler
|
||||||
{
|
{
|
||||||
private RequestContext _requestContext;
|
private RequestContext _requestContext;
|
||||||
private AuthenticationTypes _authTypes;
|
private AuthenticationSchemes _authSchemes;
|
||||||
private AuthenticationTypes _customChallenges;
|
private AuthenticationSchemes _customChallenges;
|
||||||
|
|
||||||
internal AuthenticationHandler(RequestContext requestContext)
|
internal AuthenticationHandler(RequestContext requestContext)
|
||||||
{
|
{
|
||||||
_requestContext = requestContext;
|
_requestContext = requestContext;
|
||||||
_authTypes = requestContext.AuthenticationChallenges;
|
_authSchemes = requestContext.AuthenticationChallenges;
|
||||||
_customChallenges = AuthenticationTypes.None;
|
_customChallenges = AuthenticationSchemes.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Authenticate(IAuthenticateContext context)
|
public void Authenticate(IAuthenticateContext context)
|
||||||
|
|
@ -49,19 +49,19 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
var user = _requestContext.User;
|
var user = _requestContext.User;
|
||||||
var identity = user == null ? null : (ClaimsIdentity)user.Identity;
|
var identity = user == null ? null : (ClaimsIdentity)user.Identity;
|
||||||
|
|
||||||
foreach (var authType in ListEnabledAuthTypes())
|
foreach (var authType in ListEnabledAuthSchemes())
|
||||||
{
|
{
|
||||||
string authString = authType.ToString();
|
string authScheme = authType.ToString();
|
||||||
if (context.AuthenticationTypes.Contains(authString, StringComparer.Ordinal))
|
if (context.AuthenticationSchemes.Contains(authScheme, StringComparer.Ordinal))
|
||||||
{
|
{
|
||||||
if (identity != null && identity.IsAuthenticated
|
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
|
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)
|
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.
|
// Not including any auth types means it's a blanket challenge for any auth type.
|
||||||
if (context.AuthenticationTypes == null || !context.AuthenticationTypes.Any()
|
if (context.AuthenticationSchemes == null || !context.AuthenticationSchemes.Any()
|
||||||
|| context.AuthenticationTypes.Contains(authString, StringComparer.Ordinal))
|
|| context.AuthenticationSchemes.Contains(authScheme, StringComparer.Ordinal))
|
||||||
{
|
{
|
||||||
_customChallenges |= authType;
|
_customChallenges |= scheme;
|
||||||
context.Accept(authString, GetDescription(authType.ToString()));
|
context.Accept(authScheme, GetDescription(authScheme));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// A challenge was issued, it overrides any pre-set auth types.
|
// A challenge was issued, it overrides any pre-set auth types.
|
||||||
_requestContext.AuthenticationChallenges = _customChallenges;
|
_requestContext.AuthenticationChallenges = _customChallenges;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetDescriptions(IAuthTypeContext context)
|
public void GetDescriptions(IDescribeSchemesContext context)
|
||||||
{
|
{
|
||||||
// TODO: Caching, this data doesn't change per request.
|
// 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
|
// Not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
private IDictionary<string, object> GetDescription(string authenticationType)
|
private IDictionary<string, object> GetDescription(string authenticationScheme)
|
||||||
{
|
{
|
||||||
return new Dictionary<string, object>()
|
return new Dictionary<string, object>()
|
||||||
{
|
{
|
||||||
{ "AuthenticationType", authenticationType },
|
{ "AuthenticationScheme", authenticationScheme },
|
||||||
{ "Caption", "Windows:" + authenticationType },
|
{ "Caption", "Windows:" + authenticationScheme },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<AuthenticationTypes> ListEnabledAuthTypes()
|
private IEnumerable<AuthenticationSchemes> ListEnabledAuthSchemes()
|
||||||
{
|
{
|
||||||
// Order by strength.
|
// 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:
|
// TODO:
|
||||||
throw new NotImplementedException("Digest challenge generation has not been implemented.");
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.FeatureModel;
|
using Microsoft.AspNet.FeatureModel;
|
||||||
using Microsoft.AspNet.Http.Interfaces;
|
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.Http.Server;
|
||||||
using Microsoft.Net.WebSockets;
|
using Microsoft.Net.WebSockets;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
|
|
@ -48,29 +47,29 @@ namespace Microsoft.Net.Http.Server
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private WebListener _server;
|
private WebListener _server;
|
||||||
private AuthenticationTypes _authTypes;
|
private AuthenticationSchemes _authSchemes;
|
||||||
|
|
||||||
internal AuthenticationManager(WebListener listener)
|
internal AuthenticationManager(WebListener listener)
|
||||||
{
|
{
|
||||||
_server = listener;
|
_server = listener;
|
||||||
_authTypes = AuthenticationTypes.AllowAnonymous;
|
_authSchemes = AuthenticationSchemes.AllowAnonymous;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
public AuthenticationTypes AuthenticationTypes
|
public AuthenticationSchemes AuthenticationSchemes
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _authTypes;
|
return _authSchemes;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_authTypes == AuthenticationTypes.None)
|
if (_authSchemes == AuthenticationSchemes.None)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("value", "'None' is not a valid authentication type. Use 'AllowAnonymous' instead.");
|
throw new ArgumentException("value", "'None' is not a valid authentication type. Use 'AllowAnonymous' instead.");
|
||||||
}
|
}
|
||||||
_authTypes = value;
|
_authSchemes = value;
|
||||||
SetServerSecurity();
|
SetServerSecurity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +78,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
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();
|
new UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_AUTHENTICATION_INFO();
|
||||||
|
|
||||||
authInfo.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
authInfo.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
||||||
var authTypes = (UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES)(_authTypes & ~AuthenticationTypes.AllowAnonymous);
|
var authSchemes = (UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES)(_authSchemes & ~AuthenticationSchemes.AllowAnonymous);
|
||||||
if (authTypes != UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES.NONE)
|
if (authSchemes != UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES.NONE)
|
||||||
{
|
{
|
||||||
authInfo.AuthSchemes = authTypes;
|
authInfo.AuthSchemes = authSchemes;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// NTLM auth sharing (on by default?) DisableNTLMCredentialCaching
|
// NTLM auth sharing (on by default?) DisableNTLMCredentialCaching
|
||||||
|
|
@ -111,35 +110,35 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static IList<string> GenerateChallenges(AuthenticationTypes authTypes)
|
internal static IList<string> GenerateChallenges(AuthenticationSchemes authSchemes)
|
||||||
{
|
{
|
||||||
IList<string> challenges = new List<string>();
|
IList<string> challenges = new List<string>();
|
||||||
|
|
||||||
if (authTypes == AuthenticationTypes.None)
|
if (authSchemes == AuthenticationSchemes.None)
|
||||||
{
|
{
|
||||||
return challenges;
|
return challenges;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order by strength.
|
// Order by strength.
|
||||||
if ((authTypes & AuthenticationTypes.Kerberos) == AuthenticationTypes.Kerberos)
|
if ((authSchemes & AuthenticationSchemes.Kerberos) == AuthenticationSchemes.Kerberos)
|
||||||
{
|
{
|
||||||
challenges.Add("Kerberos");
|
challenges.Add("Kerberos");
|
||||||
}
|
}
|
||||||
if ((authTypes & AuthenticationTypes.Negotiate) == AuthenticationTypes.Negotiate)
|
if ((authSchemes & AuthenticationSchemes.Negotiate) == AuthenticationSchemes.Negotiate)
|
||||||
{
|
{
|
||||||
challenges.Add("Negotiate");
|
challenges.Add("Negotiate");
|
||||||
}
|
}
|
||||||
if ((authTypes & AuthenticationTypes.NTLM) == AuthenticationTypes.NTLM)
|
if ((authSchemes & AuthenticationSchemes.NTLM) == AuthenticationSchemes.NTLM)
|
||||||
{
|
{
|
||||||
challenges.Add("NTLM");
|
challenges.Add("NTLM");
|
||||||
}
|
}
|
||||||
/*if ((_authTypes & AuthenticationTypes.Digest) == AuthenticationTypes.Digest)
|
/*if ((_authSchemes & AuthenticationSchemes.Digest) == AuthenticationSchemes.Digest)
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
throw new NotImplementedException("Digest challenge generation has not been implemented.");
|
throw new NotImplementedException("Digest challenge generation has not been implemented.");
|
||||||
// challenges.Add("Digest");
|
// challenges.Add("Digest");
|
||||||
}*/
|
}*/
|
||||||
if ((authTypes & AuthenticationTypes.Basic) == AuthenticationTypes.Basic)
|
if ((authSchemes & AuthenticationSchemes.Basic) == AuthenticationSchemes.Basic)
|
||||||
{
|
{
|
||||||
// TODO: Realm
|
// TODO: Realm
|
||||||
challenges.Add("Basic");
|
challenges.Add("Basic");
|
||||||
|
|
@ -180,20 +179,20 @@ namespace Microsoft.Net.Http.Server
|
||||||
return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated
|
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)
|
switch (input)
|
||||||
{
|
{
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeBasic:
|
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeBasic:
|
||||||
return AuthenticationTypes.Basic;
|
return AuthenticationSchemes.Basic;
|
||||||
// case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeDigest:
|
// case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeDigest:
|
||||||
// return AuthenticationTypes.Digest;
|
// return AuthenticationSchemes.Digest;
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNTLM:
|
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNTLM:
|
||||||
return AuthenticationTypes.NTLM;
|
return AuthenticationSchemes.NTLM;
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNegotiate:
|
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNegotiate:
|
||||||
return AuthenticationTypes.Negotiate;
|
return AuthenticationSchemes.Negotiate;
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeKerberos:
|
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeKerberos:
|
||||||
return AuthenticationTypes.Kerberos;
|
return AuthenticationSchemes.Kerberos;
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException(input.ToString());
|
throw new NotImplementedException(input.ToString());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ using System;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Server
|
namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
|
// REVIEW: this appears to be very similar to System.Net.AuthenticationSchemes
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum AuthenticationTypes
|
public enum AuthenticationSchemes
|
||||||
{
|
{
|
||||||
None = 0x0,
|
None = 0x0,
|
||||||
Basic = 0x1,
|
Basic = 0x1,
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
_request = new Request(this, _memoryBlob);
|
_request = new Request(this, _memoryBlob);
|
||||||
_response = new Response(this);
|
_response = new Response(this);
|
||||||
_request.ReleasePins();
|
_request.ReleasePins();
|
||||||
AuthenticationChallenges = server.AuthenticationManager.AuthenticationTypes & ~AuthenticationTypes.AllowAnonymous;
|
AuthenticationChallenges = server.AuthenticationManager.AuthenticationSchemes & ~AuthenticationSchemes.AllowAnonymous;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request Request
|
public Request Request
|
||||||
|
|
@ -134,9 +134,9 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The authentication challengest that will be added to the response if the status code is 401.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthenticationTypes AuthenticationChallenges { get; set; }
|
public AuthenticationSchemes AuthenticationChallenges { get; set; }
|
||||||
|
|
||||||
public bool IsUpgradableRequest
|
public bool IsUpgradableRequest
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -592,7 +592,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
if (!AuthenticationManager.AllowAnonymous && !AuthenticationManager.CheckAuthenticated(requestV2->pRequestInfo))
|
if (!AuthenticationManager.AllowAnonymous && !AuthenticationManager.CheckAuthenticated(requestV2->pRequestInfo))
|
||||||
{
|
{
|
||||||
SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.Unauthorized,
|
SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.Unauthorized,
|
||||||
AuthenticationManager.GenerateChallenges(AuthenticationManager.AuthenticationTypes));
|
AuthenticationManager.GenerateChallenges(AuthenticationManager.AuthenticationSchemes));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -24,23 +24,24 @@ using Microsoft.AspNet.FeatureModel;
|
||||||
using Microsoft.AspNet.Http.Core;
|
using Microsoft.AspNet.Http.Core;
|
||||||
using Microsoft.Net.Http.Server;
|
using Microsoft.Net.Http.Server;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using AuthenticationSchemes = Microsoft.Net.Http.Server.AuthenticationSchemes;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Server.WebListener
|
namespace Microsoft.AspNet.Server.WebListener
|
||||||
{
|
{
|
||||||
public class AuthenticationTests
|
public class AuthenticationTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.AllowAnonymous)]
|
[InlineData(AuthenticationSchemes.AllowAnonymous)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationTypes authType)
|
public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
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 context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -55,12 +56,12 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationTypes authType)
|
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (Utilities.CreateHttpAuthServer(authType, out address, env =>
|
using (Utilities.CreateHttpAuthServer(authType, out address, env =>
|
||||||
|
|
@ -75,15 +76,15 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationTypes authType)
|
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
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 context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -103,12 +104,12 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (Utilities.CreateHttpAuthServer(
|
using (Utilities.CreateHttpAuthServer(
|
||||||
AuthenticationTypes.Kerberos
|
AuthenticationSchemes.Kerberos
|
||||||
| AuthenticationTypes.Negotiate
|
| AuthenticationSchemes.Negotiate
|
||||||
| AuthenticationTypes.NTLM
|
| AuthenticationSchemes.NTLM
|
||||||
/* | AuthenticationTypes.Digest TODO: Not implemented */
|
/* | AuthenticationSchemes.Digest TODO: Not implemented */
|
||||||
| AuthenticationTypes.Basic
|
| AuthenticationSchemes.Basic
|
||||||
| AuthenticationTypes.AllowAnonymous,
|
| AuthenticationSchemes.AllowAnonymous,
|
||||||
out address,
|
out address,
|
||||||
env =>
|
env =>
|
||||||
{
|
{
|
||||||
|
|
@ -126,17 +127,17 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
// [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds
|
// [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /* AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /* AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationTypes authType)
|
public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
int requestId = 0;
|
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);
|
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -163,13 +164,13 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
// [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds
|
// [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /* AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /* AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_RequireAuth_Success(AuthenticationTypes authType)
|
public async Task AuthTypes_RequireAuth_Success(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (Utilities.CreateHttpAuthServer(authType, out address, env =>
|
using (Utilities.CreateHttpAuthServer(authType, out address, env =>
|
||||||
|
|
@ -186,21 +187,21 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.AllowAnonymous)]
|
[InlineData(AuthenticationSchemes.AllowAnonymous)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
// [InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
// [InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_GetSingleDescriptions(AuthenticationTypes authType)
|
public async Task AuthTypes_GetSingleDescriptions(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
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 context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
var resultList = context.GetAuthenticationTypes();
|
var resultList = context.GetAuthenticationSchemes();
|
||||||
if (authType == AuthenticationTypes.AllowAnonymous)
|
if (authType == AuthenticationSchemes.AllowAnonymous)
|
||||||
{
|
{
|
||||||
Assert.Equal(0, resultList.Count());
|
Assert.Equal(0, resultList.Count());
|
||||||
}
|
}
|
||||||
|
|
@ -208,7 +209,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
{
|
{
|
||||||
Assert.Equal(1, resultList.Count());
|
Assert.Equal(1, resultList.Count());
|
||||||
var result = resultList.First();
|
var result = resultList.First();
|
||||||
Assert.Equal(authType.ToString(), result.AuthenticationType);
|
Assert.Equal(authType.ToString(), result.AuthenticationScheme);
|
||||||
Assert.Equal("Windows:" + authType.ToString(), result.Caption);
|
Assert.Equal("Windows:" + authType.ToString(), result.Caption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,16 +226,16 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
public async Task AuthTypes_GetMultipleDescriptions()
|
public async Task AuthTypes_GetMultipleDescriptions()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
AuthenticationTypes authType =
|
AuthenticationSchemes authType =
|
||||||
AuthenticationTypes.Kerberos
|
AuthenticationSchemes.Kerberos
|
||||||
| AuthenticationTypes.Negotiate
|
| AuthenticationSchemes.Negotiate
|
||||||
| AuthenticationTypes.NTLM
|
| AuthenticationSchemes.NTLM
|
||||||
| /*AuthenticationTypes.Digest
|
| /*AuthenticationSchemes.Digest
|
||||||
|*/ AuthenticationTypes.Basic;
|
|*/ AuthenticationSchemes.Basic;
|
||||||
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 context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
var resultList = context.GetAuthenticationTypes();
|
var resultList = context.GetAuthenticationSchemes();
|
||||||
Assert.Equal(4, resultList.Count());
|
Assert.Equal(4, resultList.Count());
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}))
|
}))
|
||||||
|
|
@ -246,17 +247,17 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_AuthenticateWithNoUser_NoResults(AuthenticationTypes authType)
|
public async Task AuthTypes_AuthenticateWithNoUser_NoResults(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
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);
|
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -273,13 +274,13 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
// [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds
|
// [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_AuthenticateWithUser_OneResult(AuthenticationTypes authType)
|
public async Task AuthTypes_AuthenticateWithUser_OneResult(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
@ -299,17 +300,17 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(AuthenticationTypes authType)
|
public async Task AuthTypes_ChallengeWithoutAuthTypes_AllChallengesSent(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
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);
|
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -325,17 +326,17 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(AuthenticationTypes authType)
|
public async Task AuthTypes_ChallengeWithAllAuthTypes_AllChallengesSent(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
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);
|
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -351,16 +352,16 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationTypes authType)
|
public async Task AuthTypes_ChallengeOneAuthType_OneChallengeSent(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
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;
|
||||||
using (Utilities.CreateHttpAuthServer(authTypes | AuthenticationTypes.AllowAnonymous, out address, env =>
|
using (Utilities.CreateHttpAuthServer(authTypes | AuthenticationSchemes.AllowAnonymous, out address, env =>
|
||||||
{
|
{
|
||||||
var context = new DefaultHttpContext((IFeatureCollection)env);
|
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
@ -377,18 +378,18 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_ChallengeDisabledAuthType_Error(AuthenticationTypes authType)
|
public async Task AuthTypes_ChallengeDisabledAuthType_Error(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
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;
|
authTypes = authTypes & ~authType;
|
||||||
var authTypeList = authType.ToString().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
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);
|
var context = new DefaultHttpContext((IFeatureCollection)env);
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
|
|
|
||||||
|
|
@ -33,22 +33,22 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
internal static IDisposable CreateHttpServer(out string baseAddress, AppFunc app)
|
internal static IDisposable CreateHttpServer(out string baseAddress, AppFunc app)
|
||||||
{
|
{
|
||||||
string root;
|
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)
|
internal static IDisposable CreateHttpServerReturnRoot(string path, out string root, AppFunc app)
|
||||||
{
|
{
|
||||||
string baseAddress;
|
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;
|
string root;
|
||||||
return CreateDynamicHttpServer(string.Empty, authType, out root, out baseAddress, app);
|
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);
|
var factory = new ServerFactory(loggerFactory: null);
|
||||||
lock (PortLock)
|
lock (PortLock)
|
||||||
|
|
@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Server.WebListener
|
||||||
|
|
||||||
var serverInfo = (ServerInformation)factory.Initialize(configuration: null);
|
var serverInfo = (ServerInformation)factory.Initialize(configuration: null);
|
||||||
serverInfo.Listener.UrlPrefixes.Add(prefix);
|
serverInfo.Listener.UrlPrefixes.Add(prefix);
|
||||||
serverInfo.Listener.AuthenticationManager.AuthenticationTypes = authType;
|
serverInfo.Listener.AuthenticationManager.AuthenticationSchemes = authType;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return factory.Start(serverInfo, app);
|
return factory.Start(serverInfo, app);
|
||||||
|
|
|
||||||
|
|
@ -11,26 +11,26 @@ namespace Microsoft.Net.Http.Server
|
||||||
public class AuthenticationTests
|
public class AuthenticationTests
|
||||||
{
|
{
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.AllowAnonymous)]
|
[InlineData(AuthenticationSchemes.AllowAnonymous)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)]
|
// [InlineData(AuthenticationSchemes.Digest)]
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationTypes.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationSchemes.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationTypes authType)
|
public async Task AuthTypes_AllowAnonymous_NoChallenge(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address))
|
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address))
|
||||||
{
|
{
|
||||||
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
||||||
|
|
||||||
var context = await server.GetContextAsync();
|
var context = await server.GetContextAsync();
|
||||||
Assert.NotNull(context.User);
|
Assert.NotNull(context.User);
|
||||||
Assert.False(context.User.Identity.IsAuthenticated);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -45,12 +45,12 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationType.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationType.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationTypes authType)
|
public async Task AuthType_RequireAuth_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (var server = Utilities.CreateHttpAuthServer(authType, out address))
|
using (var server = Utilities.CreateHttpAuthServer(authType, out address))
|
||||||
|
|
@ -66,15 +66,15 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
[InlineData(AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationTypes authType)
|
public async Task AuthType_AllowAnonymousButSpecify401_ChallengesAdded(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address))
|
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address))
|
||||||
{
|
{
|
||||||
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
||||||
|
|
||||||
|
|
@ -95,13 +95,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded()
|
public async Task MultipleAuthTypes_AllowAnonymousButSpecify401_ChallengesAdded()
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
AuthenticationTypes authType =
|
AuthenticationSchemes authType =
|
||||||
AuthenticationTypes.Kerberos
|
AuthenticationSchemes.Kerberos
|
||||||
| AuthenticationTypes.Negotiate
|
| AuthenticationSchemes.Negotiate
|
||||||
| AuthenticationTypes.NTLM
|
| AuthenticationSchemes.NTLM
|
||||||
/* | AuthenticationTypes.Digest TODO: Not implemented */
|
/* | AuthenticationSchemes.Digest TODO: Not implemented */
|
||||||
| AuthenticationTypes.Basic;
|
| AuthenticationSchemes.Basic;
|
||||||
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address))
|
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address))
|
||||||
{
|
{
|
||||||
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
Task<HttpResponseMessage> responseTask = SendRequestAsync(address);
|
||||||
|
|
||||||
|
|
@ -119,16 +119,16 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
// [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds
|
// [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationTypes authType)
|
public async Task AuthTypes_AllowAnonymousButSpecify401_Success(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationTypes.AllowAnonymous, out address))
|
using (var server = Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address))
|
||||||
{
|
{
|
||||||
Task<HttpResponseMessage> responseTask = SendRequestAsync(address, useDefaultCredentials: true);
|
Task<HttpResponseMessage> responseTask = SendRequestAsync(address, useDefaultCredentials: true);
|
||||||
|
|
||||||
|
|
@ -151,13 +151,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(AuthenticationTypes.Kerberos)]
|
[InlineData(AuthenticationSchemes.Kerberos)]
|
||||||
[InlineData(AuthenticationTypes.Negotiate)]
|
[InlineData(AuthenticationSchemes.Negotiate)]
|
||||||
[InlineData(AuthenticationTypes.NTLM)]
|
[InlineData(AuthenticationSchemes.NTLM)]
|
||||||
// [InlineData(AuthenticationTypes.Digest)] // TODO: Not implemented
|
// [InlineData(AuthenticationSchemes.Digest)] // TODO: Not implemented
|
||||||
// [InlineData(AuthenticationTypes.Basic)] // Doesn't work with default creds
|
// [InlineData(AuthenticationSchemes.Basic)] // Doesn't work with default creds
|
||||||
[InlineData(AuthenticationTypes.Kerberos | AuthenticationTypes.Negotiate | AuthenticationTypes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationTypes.Basic)]
|
[InlineData(AuthenticationSchemes.Kerberos | AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | /*AuthenticationType.Digest |*/ AuthenticationSchemes.Basic)]
|
||||||
public async Task AuthTypes_RequireAuth_Success(AuthenticationTypes authType)
|
public async Task AuthTypes_RequireAuth_Success(AuthenticationSchemes authType)
|
||||||
{
|
{
|
||||||
string address;
|
string address;
|
||||||
using (var server = Utilities.CreateHttpAuthServer(authType, out address))
|
using (var server = Utilities.CreateHttpAuthServer(authType, out address))
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ namespace Microsoft.Net.Http.Server
|
||||||
private static int NextPort = BasePort;
|
private static int NextPort = BasePort;
|
||||||
private static object PortLock = new object();
|
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);
|
var listener = CreateHttpServer(out baseAddress);
|
||||||
listener.AuthenticationManager.AuthenticationTypes = authType;
|
listener.AuthenticationManager.AuthenticationSchemes = authScheme;
|
||||||
return listener;
|
return listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue