React to Authentication changes.
This commit is contained in:
parent
661477a4bf
commit
08d17b2631
|
|
@ -59,15 +59,18 @@ namespace ServerComparison.FunctionalTests
|
||||||
{
|
{
|
||||||
Assert.Equal("Hello World", responseText);
|
Assert.Equal("Hello World", responseText);
|
||||||
|
|
||||||
responseText = await httpClient.GetStringAsync("/Anonymous");
|
response = await httpClient.GetAsync("/Anonymous");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
Assert.Equal("Anonymous?True", responseText);
|
Assert.Equal("Anonymous?True", responseText);
|
||||||
|
|
||||||
response = await httpClient.GetAsync("/Restricted");
|
response = await httpClient.GetAsync("/Restricted");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||||
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
|
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
|
||||||
Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString());
|
Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString());
|
||||||
|
|
||||||
response = await httpClient.GetAsync("/RestrictedNTLM");
|
response = await httpClient.GetAsync("/RestrictedNTLM");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||||
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
|
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
|
||||||
// Note IIS can't restrict a challenge to a specific auth type, the native auth modules always add themselves.
|
// Note IIS can't restrict a challenge to a specific auth type, the native auth modules always add themselves.
|
||||||
|
|
@ -88,22 +91,30 @@ namespace ServerComparison.FunctionalTests
|
||||||
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
|
httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(deploymentResult.ApplicationBaseUri) };
|
||||||
|
|
||||||
response = await httpClient.GetAsync("/AutoForbid");
|
response = await httpClient.GetAsync("/AutoForbid");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||||
|
|
||||||
responseText = await httpClient.GetStringAsync("/Restricted");
|
response = await httpClient.GetAsync("/Restricted");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.Equal("Negotiate", responseText);
|
Assert.Equal("Negotiate", responseText);
|
||||||
|
|
||||||
responseText = await httpClient.GetStringAsync("/RestrictedNegotiate");
|
response = await httpClient.GetAsync("/RestrictedNegotiate");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.Equal("Negotiate", responseText);
|
Assert.Equal("Negotiate", responseText);
|
||||||
|
|
||||||
if (serverType == ServerType.WebListener)
|
if (serverType == ServerType.WebListener)
|
||||||
{
|
{
|
||||||
responseText = await httpClient.GetStringAsync("/RestrictedNTLM");
|
response = await httpClient.GetAsync("/RestrictedNTLM");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
Assert.Equal("NTLM", responseText);
|
Assert.Equal("NTLM", responseText);
|
||||||
}
|
}
|
||||||
else if (serverType == ServerType.IISExpress)
|
else if (serverType == ServerType.IISExpress)
|
||||||
{
|
{
|
||||||
response = await httpClient.GetAsync("/RestrictedNTLM");
|
response = await httpClient.GetAsync("/RestrictedNTLM");
|
||||||
|
responseText = await response.Content.ReadAsStringAsync();
|
||||||
// This isn't a Forbidden because we authenticate with Negotiate and challenge for NTLM.
|
// This isn't a Forbidden because we authenticate with Negotiate and challenge for NTLM.
|
||||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||||
// Note IIS can't restrict a challenge to a specific auth type, the native auth modules always add themselves,
|
// Note IIS can't restrict a challenge to a specific auth type, the native auth modules always add themselves,
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace ServerComparison.FunctionalTests
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
// [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x86, "http://localhost:5075/")]
|
// [InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x86, "http://localhost:5075/")] // https://github.com/aspnet/IISIntegration/issues/7
|
||||||
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5076/")]
|
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5076/")]
|
||||||
public Task ResponseFormats_Windows_ConnectionClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
public Task ResponseFormats_Windows_ConnectionClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
||||||
{
|
{
|
||||||
|
|
@ -56,7 +56,7 @@ namespace ServerComparison.FunctionalTests
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
// [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5078/")]
|
// [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5078/")] // https://github.com/aspnet/IISIntegration/issues/7
|
||||||
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5079/")]
|
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5079/")]
|
||||||
public Task ResponseFormats_Windows_Chunked(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
public Task ResponseFormats_Windows_Chunked(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
||||||
{
|
{
|
||||||
|
|
@ -73,7 +73,7 @@ namespace ServerComparison.FunctionalTests
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
// [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5081/")]
|
// [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5081/")] // https://github.com/aspnet/IISIntegration/issues/7
|
||||||
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5082/")]
|
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5082/")]
|
||||||
public Task ResponseFormats_Windows_ManuallyChunk(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
public Task ResponseFormats_Windows_ManuallyChunk(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
||||||
{
|
{
|
||||||
|
|
@ -90,7 +90,7 @@ namespace ServerComparison.FunctionalTests
|
||||||
[ConditionalTheory]
|
[ConditionalTheory]
|
||||||
[OSSkipCondition(OperatingSystems.Linux)]
|
[OSSkipCondition(OperatingSystems.Linux)]
|
||||||
[OSSkipCondition(OperatingSystems.MacOSX)]
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
||||||
// [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5084/")]
|
// [InlineData(ServerType.IISExpress, RuntimeFlavor.Clr, RuntimeArchitecture.x64, "http://localhost:5084/")] // https://github.com/aspnet/IISIntegration/issues/7
|
||||||
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5085/")]
|
[InlineData(ServerType.WebListener, RuntimeFlavor.Clr, RuntimeArchitecture.x86, "http://localhost:5085/")]
|
||||||
public Task ResponseFormats_Windows_ManuallyChunkAndClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
public Task ResponseFormats_Windows_ManuallyChunkAndClose(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, string applicationBaseUrl)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Features;
|
using Microsoft.AspNet.Http.Features;
|
||||||
|
|
@ -28,6 +29,24 @@ namespace ServerComparison.TestSites
|
||||||
{
|
{
|
||||||
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
|
loggerFactory.AddConsole(minLevel: LogLevel.Warning);
|
||||||
|
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (context.Response.HasStarted)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
context.Response.Clear();
|
||||||
|
context.Response.StatusCode = 500;
|
||||||
|
await context.Response.WriteAsync(ex.ToString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Set up NTLM authentication for WebListener like below.
|
// Set up NTLM authentication for WebListener like below.
|
||||||
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM.
|
// For IIS and IISExpress: Use inetmgr to setup NTLM authentication on the application vDir or modify the applicationHost.config to enable NTLM.
|
||||||
var listener = app.ServerFeatures.Get<WebListener>();
|
var listener = app.ServerFeatures.Get<WebListener>();
|
||||||
|
|
@ -36,6 +55,10 @@ namespace ServerComparison.TestSites
|
||||||
listener.AuthenticationManager.AuthenticationSchemes =
|
listener.AuthenticationManager.AuthenticationSchemes =
|
||||||
AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | AuthenticationSchemes.AllowAnonymous;
|
AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM | AuthenticationSchemes.AllowAnonymous;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.UseIISPlatformHandler();
|
||||||
|
}
|
||||||
|
|
||||||
app.Use((context, next) =>
|
app.Use((context, next) =>
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +81,7 @@ namespace ServerComparison.TestSites
|
||||||
|
|
||||||
if (context.Request.Path.Equals("/Forbidden"))
|
if (context.Request.Path.Equals("/Forbidden"))
|
||||||
{
|
{
|
||||||
return context.Authentication.ForbidAsync(string.Empty);
|
return context.Authentication.ForbidAsync(Microsoft.AspNet.Http.Authentication.AuthenticationManager.AutomaticScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.Request.Path.Equals("/AutoForbid"))
|
if (context.Request.Path.Equals("/AutoForbid"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue