Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit b3f6351

Browse files
committed
Fix tests
1 parent 17418f6 commit b3f6351

File tree

3 files changed

+20
-37
lines changed

3 files changed

+20
-37
lines changed

src/Microsoft.AspNetCore.Server.HttpSys/AuthenticationHandler.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ internal class AuthenticationHandler : IAuthenticationHandler
1616
private RequestContext _requestContext;
1717
private AuthenticationSchemes _authSchemes;
1818
private AuthenticationSchemes _customChallenges;
19+
private AuthenticationScheme _scheme;
1920

20-
public Task<AuthenticateResult> AuthenticateAsync(AuthenticateContext context)
21+
public Task<AuthenticateResult> AuthenticateAsync()
2122
{
2223
var identity = _requestContext.User?.Identity;
2324
if (identity != null && identity.IsAuthenticated)
2425
{
2526
foreach (var scheme in ListEnabledAuthSchemes())
2627
{
27-
if (string.Equals(context.AuthenticationScheme, identity.AuthenticationType, StringComparison.Ordinal))
28+
if (string.Equals(scheme.ToString(), identity.AuthenticationType, StringComparison.Ordinal))
2829
{
29-
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(_requestContext.User, properties: null, authenticationScheme: context.AuthenticationScheme)));
30+
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(_requestContext.User, properties: null, authenticationScheme: _scheme.Name)));
3031
}
3132
}
3233
}
@@ -49,10 +50,16 @@ public Task ChallengeAsync(ChallengeContext context)
4950
break;
5051
case ChallengeBehavior.Automatic:
5152
var identity = (ClaimsIdentity)_requestContext.User?.Identity;
52-
if (identity != null && identity.IsAuthenticated
53-
&& (string.Equals(identity.AuthenticationType, context.AuthenticationScheme, StringComparison.Ordinal)))
53+
if (identity != null && identity.IsAuthenticated)
5454
{
55-
_requestContext.Response.StatusCode = 403;
55+
foreach (var scheme in ListEnabledAuthSchemes())
56+
{
57+
if (string.Equals(identity.AuthenticationType, scheme.ToString(), StringComparison.Ordinal))
58+
{
59+
_requestContext.Response.StatusCode = 403;
60+
break;
61+
}
62+
}
5663
}
5764
else
5865
{
@@ -74,6 +81,7 @@ public Task ChallengeAsync(ChallengeContext context)
7481

7582
public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
7683
{
84+
_scheme = scheme;
7785
_requestContext = context.Features.Get<RequestContext>();
7886

7987
if (_requestContext == null)

src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Diagnostics.Contracts;
67
using System.Linq;
78
using System.Threading;
89
using System.Threading.Tasks;
910
using Microsoft.AspNetCore.Authentication;
10-
using Microsoft.AspNetCore.Hosting;
1111
using Microsoft.AspNetCore.Hosting.Server;
1212
using Microsoft.AspNetCore.Hosting.Server.Features;
1313
using Microsoft.AspNetCore.Http.Features;
@@ -55,7 +55,7 @@ public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactor
5555
throw new InvalidOperationException("AddAuthentication() is required to use Authentication.");
5656
}
5757

58-
auth.AddScheme(new AuthenticationScheme("Windows", typeof(AuthenticationHandler)));
58+
auth.AddScheme(new AuthenticationScheme("Windows", displayName: null, handlerType: typeof(AuthenticationHandler)));
5959
}
6060

6161
Features = new FeatureCollection();
@@ -74,32 +74,7 @@ public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactor
7474

7575
public IFeatureCollection Features { get; }
7676

77-
private void AddScheme(IAuthenticationSchemeProvider authentication, string scheme)
78-
{
79-
authentication.AddScheme(new AuthenticationScheme(scheme, typeof(AuthenticationHandler)));
80-
}
81-
82-
private void AddSchemes(IAuthenticationSchemeProvider authentication, AuthenticationSchemes schemes)
83-
{
84-
if ((schemes & AuthenticationSchemes.Kerberos) == AuthenticationSchemes.Kerberos)
85-
{
86-
AddScheme(authentication, "Kerberos");
87-
}
88-
if ((schemes & AuthenticationSchemes.Negotiate) == AuthenticationSchemes.Negotiate)
89-
{
90-
AddScheme(authentication, "Negotiate");
91-
}
92-
if ((schemes & AuthenticationSchemes.NTLM) == AuthenticationSchemes.NTLM)
93-
{
94-
AddScheme(authentication, "NTLM");
95-
}
96-
if ((schemes & AuthenticationSchemes.Basic) == AuthenticationSchemes.Basic)
97-
{
98-
AddScheme(authentication, "Basic");
99-
}
100-
}
101-
102-
public void Start<TContext>(IHttpApplication<TContext> application)
77+
public Task StartAsync<TContext>(IHttpApplication<TContext> application, CancellationToken cancellationToken)
10378
{
10479
if (application == null)
10580
{

test/Microsoft.AspNetCore.Server.HttpSys.FunctionalTests/MessagePumpTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void OverridingDirectConfigurationWithIServerAddressesFeatureSucceeds()
2020
var serverAddress = "http://localhost:11001/";
2121
var overrideAddress = "http://localhost:11002/";
2222

23-
using (var server = new MessagePump(Options.Create(new HttpSysOptions()), new LoggerFactory()))
23+
using (var server = new MessagePump(Options.Create(new HttpSysOptions()), new LoggerFactory(), new AuthenticationSchemeProvider[0]))
2424
{
2525
var serverAddressesFeature = server.Features.Get<IServerAddressesFeature>();
2626
serverAddressesFeature.Addresses.Add(overrideAddress);
@@ -42,7 +42,7 @@ public void DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfPref
4242
{
4343
var serverAddress = "http://localhost:11002/";
4444

45-
using (var server = new MessagePump(Options.Create(new HttpSysOptions()), new LoggerFactory()))
45+
using (var server = new MessagePump(Options.Create(new HttpSysOptions()), new LoggerFactory(), new AuthenticationSchemeProvider[0]))
4646
{
4747
var serverAddressesFeature = server.Features.Get<IServerAddressesFeature>();
4848
serverAddressesFeature.Addresses.Add(overrideAddress);
@@ -59,7 +59,7 @@ public void DoesNotOverrideDirectConfigurationWithIServerAddressesFeature_IfAddr
5959
{
6060
var serverAddress = "http://localhost:11002/";
6161

62-
using (var server = new MessagePump(Options.Create(new HttpSysOptions()), new LoggerFactory()))
62+
using (var server = new MessagePump(Options.Create(new HttpSysOptions()), new LoggerFactory(), new AuthenticationSchemeProvider[0]))
6363
{
6464
var serverAddressesFeature = server.Features.Get<IServerAddressesFeature>();
6565
serverAddressesFeature.PreferHostingUrls = true;

0 commit comments

Comments
 (0)