Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit 262c73a

Browse files
committed
Fix tests rebase to real packages
1 parent 7079673 commit 262c73a

7 files changed

+42
-19
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ internal class AuthenticationHandler : IAuthenticationHandler
1616
{
1717
private const string MSAspNetCoreWinAuthToken = "MS-ASPNETCORE-WINAUTHTOKEN";
1818
private WindowsPrincipal _user;
19+
private HttpContext _context;
1920

2021
internal AuthenticationScheme Scheme { get; private set; }
2122

22-
public Task<AuthenticateResult> AuthenticateAsync(AuthenticateContext context)
23+
public Task<AuthenticateResult> AuthenticateAsync()
2324
{
24-
var user = GetUser(context.HttpContext);
25+
var user = GetUser();
2526
if (user != null)
2627
{
2728
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(user, Scheme.Name)));
@@ -32,11 +33,11 @@ public Task<AuthenticateResult> AuthenticateAsync(AuthenticateContext context)
3233
}
3334
}
3435

35-
private WindowsPrincipal GetUser(HttpContext httpContext)
36+
private WindowsPrincipal GetUser()
3637
{
3738
if (_user == null)
3839
{
39-
var tokenHeader = httpContext.Request.Headers[MSAspNetCoreWinAuthToken];
40+
var tokenHeader = _context.Request.Headers[MSAspNetCoreWinAuthToken];
4041

4142
int hexHandle;
4243
if (!StringValues.IsNullOrEmpty(tokenHeader)
@@ -49,7 +50,7 @@ private WindowsPrincipal GetUser(HttpContext httpContext)
4950
// WindowsIdentity just duplicated the handle so we need to close the original.
5051
NativeMethods.CloseHandle(handle);
5152

52-
httpContext.Response.RegisterForDispose(winIdentity);
53+
_context.Response.RegisterForDispose(winIdentity);
5354
_user = new WindowsPrincipal(winIdentity);
5455
}
5556
}
@@ -64,7 +65,7 @@ public Task ChallengeAsync(ChallengeContext context)
6465
{
6566
case ChallengeBehavior.Automatic:
6667
// If there is a principal already, invoke the forbidden code path
67-
if (GetUser(context.HttpContext) == null)
68+
if (GetUser() == null)
6869
{
6970
goto case ChallengeBehavior.Unauthorized;
7071
}
@@ -86,6 +87,7 @@ public Task ChallengeAsync(ChallengeContext context)
8687
public Task InitializeAsync(AuthenticationScheme scheme, HttpContext context)
8788
{
8889
Scheme = scheme;
90+
_context = context;
8991
return TaskCache.CompletedTask;
9092
}
9193

src/Microsoft.AspNetCore.Server.IISIntegration/IISMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public IISMiddleware(RequestDelegate next, ILoggerFactory loggerFactory, IOption
5656
throw new InvalidOperationException("IServiceCollection.AddAuthentication() is required to use Authentication.");
5757
}
5858

59-
auth.AddScheme(new AuthenticationScheme("NTLM", typeof(AuthenticationHandler)));
60-
auth.AddScheme(new AuthenticationScheme("Negotiate", typeof(AuthenticationHandler)));
59+
auth.AddScheme(new AuthenticationScheme("NTLM", /*displayName*/ null,typeof(AuthenticationHandler)));
60+
auth.AddScheme(new AuthenticationScheme("Negotiate", /*displayName*/ null, typeof(AuthenticationHandler)));
6161
}
6262

6363
_pairingToken = pairingToken;

src/Microsoft.AspNetCore.Server.IISIntegration/Microsoft.AspNetCore.Server.IISIntegration.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="$(AspNetCoreVersion)" />
1415
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="$(AspNetCoreVersion)" />
1516
<PackageReference Include="Microsoft.AspNetCore.Http" Version="$(AspNetCoreVersion)" />
1617
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="$(AspNetCoreVersion)" />
1718
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="$(AspNetCoreVersion)" />
1819
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
19-
<ProjectReference Include="..\..\..\HttpAbstractions\src\Microsoft.AspNetCore.Authentication.Abstractions\Microsoft.AspNetCore.Authentication.Abstractions.csproj" />
20-
<ProjectReference Include="..\..\..\Options\src\Microsoft.Extensions.Options\Microsoft.Extensions.Options.csproj" />
20+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(AspNetCoreVersion)" />
21+
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
2122
<PackageReference Include="Microsoft.Extensions.SecurityHelper.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All"/>
2223
<PackageReference Include="Microsoft.Extensions.TaskCache.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All"/>
2324
<PackageReference Include="System.Security.Principal.Windows" Version="$(CoreFxVersion)" />

test/TestSites/StartupHelloWorld.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Builder;
55
using Microsoft.AspNetCore.Http;
6+
using Microsoft.Extensions.DependencyInjection;
67
using Microsoft.Extensions.Logging;
78

89
namespace TestSites
910
{
1011
public class StartupHelloWorld
1112
{
13+
public void ConfigureServices(IServiceCollection services)
14+
{
15+
services.AddAuthenticationCore();
16+
}
17+
1218
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
1319
{
1420
loggerFactory.AddConsole();

test/TestSites/StartupHttpsHelloWorld.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using Microsoft.AspNetCore.Authentication;
45
using Microsoft.AspNetCore.Builder;
56
using Microsoft.AspNetCore.Http;
7+
using Microsoft.Extensions.DependencyInjection;
68
using Microsoft.Extensions.Logging;
79

810
namespace TestSites
911
{
1012
public class StartupHttpsHelloWorld
1113
{
14+
public void ConfigureServices(IServiceCollection services)
15+
{
16+
services.AddAuthenticationCore();
17+
}
18+
1219
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
1320
{
1421
loggerFactory.AddConsole();

test/TestSites/StartupNtlmAuthentication.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Security.Principal;
6+
using Microsoft.AspNetCore.Authentication;
67
using Microsoft.AspNetCore.Builder;
78
using Microsoft.AspNetCore.Http;
8-
using Microsoft.AspNetCore.Http.Authentication;
9+
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Logging;
1011
using Xunit;
1112

1213
namespace TestSites
1314
{
1415
public class StartupNtlmAuthentication
1516
{
17+
public void ConfigureServices(IServiceCollection services)
18+
{
19+
services.AddAuthenticationCore(o => o.DefaultChallengeScheme = "NTLM");
20+
}
21+
1622
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
1723
{
1824
loggerFactory.AddConsole();
@@ -53,18 +59,18 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
5359
}
5460
else
5561
{
56-
return context.Authentication.ChallengeAsync();
62+
return context.ChallengeAsync();
5763
}
5864
}
5965

6066
if (context.Request.Path.Equals("/Forbidden"))
6167
{
62-
return context.Authentication.ForbidAsync(AuthenticationManager.AutomaticScheme);
68+
return context.ForbidAsync();
6369
}
6470

6571
if (context.Request.Path.Equals("/AutoForbid"))
6672
{
67-
return context.Authentication.ChallengeAsync();
73+
return context.ChallengeAsync();
6874
}
6975

7076
if (context.Request.Path.Equals("/RestrictedNegotiate"))
@@ -75,7 +81,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
7581
}
7682
else
7783
{
78-
return context.Authentication.ChallengeAsync("Negotiate");
84+
return context.ChallengeAsync("Negotiate");
7985
}
8086
}
8187

@@ -87,7 +93,7 @@ public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
8793
}
8894
else
8995
{
90-
return context.Authentication.ChallengeAsync("NTLM");
96+
return context.ChallengeAsync("NTLM");
9197
}
9298
}
9399

test/TestSites/TestSites.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="Microsoft.AspNetCore.AspNetCoreModule" Version="$(AspNetCoreModuleVersion)" />
16+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="$(AspNetCoreVersion)" />
1617
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(AspNetCoreVersion)" />
1718
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(AspNetCoreVersion)" />
1819
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(AspNetCoreVersion)" />

0 commit comments

Comments
 (0)