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)
|
||||
{
|
||||
var info = (ServerInformation)app.Server;
|
||||
info.Listener.AuthenticationManager.AuthenticationTypes = AuthenticationTypes.AllowAnonymous;
|
||||
info.Listener.AuthenticationManager.AuthenticationSchemes = AuthenticationSchemes.AllowAnonymous;
|
||||
|
||||
loggerfactory.AddConsole(LogLevel.Verbose);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<string, object> GetDescription(string authenticationType)
|
||||
private IDictionary<string, object> GetDescription(string authenticationScheme)
|
||||
{
|
||||
return new Dictionary<string, object>()
|
||||
{
|
||||
{ "AuthenticationType", authenticationType },
|
||||
{ "Caption", "Windows:" + authenticationType },
|
||||
{ "AuthenticationScheme", authenticationScheme },
|
||||
{ "Caption", "Windows:" + authenticationScheme },
|
||||
};
|
||||
}
|
||||
|
||||
private IEnumerable<AuthenticationTypes> ListEnabledAuthTypes()
|
||||
private IEnumerable<AuthenticationSchemes> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<string> GenerateChallenges(AuthenticationTypes authTypes)
|
||||
internal static IList<string> GenerateChallenges(AuthenticationSchemes authSchemes)
|
||||
{
|
||||
IList<string> challenges = new List<string>();
|
||||
|
||||
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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
@ -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
|
|||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
public AuthenticationTypes AuthenticationChallenges { get; set; }
|
||||
public AuthenticationSchemes AuthenticationChallenges { get; set; }
|
||||
|
||||
public bool IsUpgradableRequest
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<HttpResponseMessage> 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<HttpResponseMessage> 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<HttpResponseMessage> 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<HttpResponseMessage> 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))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue