Update tests to use test fixture (#571)

This commit is contained in:
Justin Kotalik 2018-01-29 17:48:11 -08:00 committed by GitHub
parent 011cf720e6
commit babac2c795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 360 additions and 869 deletions

View File

@ -3,120 +3,62 @@
#if NET461
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IIS.FunctionalTests;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace IISIntegration.IISServerFunctionalTests
{
public class AuthenticationTests : LoggedTest
[Collection(IISTestSiteCollection.Name)]
public class AuthenticationTests
{
public AuthenticationTests(ITestOutputHelper output) : base(output)
private readonly IISTestSiteFixture _fixture;
public AuthenticationTests(IISTestSiteFixture fixture)
{
_fixture = fixture;
}
[ConditionalFact]
public Task Authentication_InProcess_IISExpress()
public async Task Authentication_InProcess_IISExpressAsync()
{
return Authentication();
}
var response = await _fixture.Client.GetAsync("/AuthenticationAnonymous");
private async Task Authentication()
{
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"Authentication_{RuntimeFlavor.CoreClr}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("AuthenticationTest");
var responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Anonymous?True", responseText);
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, RuntimeFlavor.CoreClr, architecture)
{
ApplicationBaseUriHint = $"http://localhost:5051",
EnvironmentName = "Authentication", // Will pick the Start class named 'StartupAuthentication',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = "netcoreapp2.0",
ApplicationType = ApplicationType.Portable,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
response = await _fixture.Client.GetAsync("/AuthenticationRestricted");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString());
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
var httpClient = deploymentResult.HttpClient;
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
response = await _fixture.Client.GetAsync("/AuthenticationRestrictedNTLM");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
// Note we can't restrict a challenge to a specific auth type, the native auth modules always add themselves.
Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString());
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync(string.Empty);
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
response = await _fixture.Client.GetAsync("/AuthenticationForbidden");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Hello World", responseText);
var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
var httpClient = _fixture.DeploymentResult.CreateHttpClient(httpClientHandler);
response = await httpClient.GetAsync("/Anonymous");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Anonymous?True", responseText);
response = await httpClient.GetAsync("/AuthenticationAnonymous");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Anonymous?True", responseText);
response = await httpClient.GetAsync("/Restricted");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString());
response = await httpClient.GetAsync("/RestrictedNTLM");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.Contains("NTLM", response.Headers.WwwAuthenticate.ToString());
// Note we can't restrict a challenge to a specific auth type, the native auth modules always add themselves.
Assert.Contains("Negotiate", response.Headers.WwwAuthenticate.ToString());
response = await httpClient.GetAsync("/Forbidden");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
httpClient = deploymentResult.CreateHttpClient(httpClientHandler);
response = await httpClient.GetAsync("/Anonymous");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Anonymous?True", responseText);
response = await httpClient.GetAsync("/Restricted");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotEmpty(responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
response = await httpClient.GetAsync("/AuthenticationRestricted");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotEmpty(responseText);
}
}
}

View File

@ -1,86 +1,30 @@
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IIS.FunctionalTests;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{
public class FeatureCollectionTest : LoggedTest
[Collection(IISTestSiteCollection.Name)]
public class FeatureCollectionTest
{
public FeatureCollectionTest(ITestOutputHelper output) : base(output)
private readonly IISTestSiteFixture _fixture;
public FeatureCollectionTest(IISTestSiteFixture fixture)
{
_fixture = fixture;
}
[ConditionalTheory]
[InlineData("SetRequestFeatures")]
[InlineData("SetResponseFeatures")]
[InlineData("SetConnectionFeatures")]
public Task FeatureCollectionTest_SetHttpContextFeatures(string path)
[InlineData("FeatureCollectionSetRequestFeatures")]
[InlineData("FeatureCollectionSetResponseFeatures")]
[InlineData("FeatureCollectionSetConnectionFeatures")]
public async Task FeatureCollectionTest_SetHttpContextFeatures(string path)
{
return SetFeatures(RuntimeFlavor.CoreClr, ApplicationType.Portable, path);
Assert.Equal("Success", await _fixture.Client.GetStringAsync(path + "/path" + "?query"));
}
private async Task SetFeatures(RuntimeFlavor runtimeFlavor, ApplicationType applicationType, string path)
{
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"SetFeatures_{runtimeFlavor}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("SetFeaturesTest");
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, runtimeFlavor, architecture)
{
EnvironmentName = "FeatureCollection", // Will pick the Start class named 'StartupFeatureCollection',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync(path + "?query");
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal("Success", responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
}
}
}

View File

@ -1,87 +1,31 @@
// 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.
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{
public class HelloWorldTests : LoggedTest
[Collection(IISTestSiteCollection.Name)]
public class HelloWorldTests
{
public HelloWorldTests(ITestOutputHelper output) : base(output)
private readonly IISTestSiteFixture _fixture;
public HelloWorldTests(IISTestSiteFixture fixture)
{
_fixture = fixture;
}
[ConditionalFact]
public Task HelloWorld_InProcess_IISExpress_CoreClr_X64_Portable()
public async Task HelloWorld_InProcess_IISExpress_CoreClr_X64_Portable()
{
return HelloWorld(RuntimeFlavor.CoreClr, ApplicationType.Portable);
}
Assert.Equal("Hello World", await _fixture.Client.GetStringAsync("/HelloWorld"));
private async Task HelloWorld(RuntimeFlavor runtimeFlavor, ApplicationType applicationType)
{
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"HelloWorld_{runtimeFlavor}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("HelloWorldTest");
Assert.Equal("/Path??", await _fixture.Client.GetStringAsync("/HelloWorld/Path%3F%3F?query"));
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, runtimeFlavor, architecture)
{
EnvironmentName = "HelloWorld", // Will pick the Start class named 'StartupHelloWorld',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync(string.Empty);
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal("Hello World", responseText);
response = await deploymentResult.HttpClient.GetAsync("/Path%3F%3F?query");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal("/Path??", responseText);
response = await deploymentResult.HttpClient.GetAsync("/Query%3FPath?query?");
responseText = await response.Content.ReadAsStringAsync();
Assert.Equal("?query?", responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
Assert.Equal("?query", await _fixture.Client.GetStringAsync("/HelloWorld/Query%3F%3F?query"));
}
}
}

View File

@ -1,141 +1,28 @@
// 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.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{
public class LargeResponseBodyTests : LoggedTest
[Collection(IISTestSiteCollection.Name)]
public class LargeResponseBodyTests
{
private readonly IISTestSiteFixture _fixture;
public LargeResponseBodyTests(ITestOutputHelper output) : base(output)
public LargeResponseBodyTests(IISTestSiteFixture fixture)
{
_fixture = fixture;
}
[ConditionalTheory]
[InlineData(10000)]
[InlineData(100000)]
[InlineData(1000000)]
[InlineData(10000000)]
public Task LargeResponseBodyTestCheckAllResponseBodyBytesWritten(int query)
public async Task LargeResponseBodyTestCheckAllResponseBodyBytesWritten(int query)
{
return LargeResponseBody(RuntimeFlavor.CoreClr, ApplicationType.Portable, query);
}
private async Task LargeResponseBody(RuntimeFlavor runtimeFlavor, ApplicationType applicationType, int query)
{
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"SetFeatures_{runtimeFlavor}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("SetFeaturesTest");
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, runtimeFlavor, architecture)
{
EnvironmentName = "LargeResponseBody", // Will pick the Start class named 'StartupLargeResponseBody',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync("LargeResponseBody?length=" + query);
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal(new string('a', query), responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
}
[ConditionalFact]
public Task LargeFileResponseBodyInternalCheck()
{
return LargeResponseBodyFromFile(RuntimeFlavor.CoreClr, ApplicationType.Portable);
}
private async Task LargeResponseBodyFromFile(RuntimeFlavor runtimeFlavor, ApplicationType applicationType)
{
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"SetFeatures_{runtimeFlavor}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("SetFeaturesTest");
var expected = File.ReadAllText("Http.config");
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, runtimeFlavor, architecture)
{
EnvironmentName = "LargeResponseBody", // Will pick the Start class named 'StartupLargeResponseBody',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? expected : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync("LargeResponseBodyFromFile");
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal(expected, responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
Assert.Equal(new string('a', query), await _fixture.Client.GetStringAsync($"/LargeResponseBody?length={query}"));
}
}
}

View File

@ -1,95 +1,44 @@
// 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.
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Microsoft.Net.Http.Headers;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{
public class ResponseHeaders : LoggedTest
[Collection(IISTestSiteCollection.Name)]
public class ResponseHeaders
{
public ResponseHeaders(ITestOutputHelper output) : base(output)
private readonly IISTestSiteFixture _fixture;
public ResponseHeaders(IISTestSiteFixture fixture)
{
_fixture = fixture;
}
[ConditionalFact]
public Task AddResponseHeaders_HeaderValuesAreSetCorrectly()
public async Task AddResponseHeaders_HeaderValuesAreSetCorrectly()
{
return RunResponseHeaders(ApplicationType.Portable);
}
var response = await _fixture.Client.GetAsync("ResponseHeaders");
var responseText = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Request Complete", responseText);
private async Task RunResponseHeaders(ApplicationType applicationType)
{
var runtimeFlavor = RuntimeFlavor.CoreClr;
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"ResponseHeaders_{runtimeFlavor}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("HelloWorldTest");
Assert.True(response.Headers.TryGetValues("UnknownHeader", out var headerValues));
Assert.Equal("test123=foo", headerValues.First());
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, runtimeFlavor, architecture)
{
EnvironmentName = "ResponseHeaders", // Will pick the Start class named 'StartupHelloWorld',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
Assert.True(response.Content.Headers.TryGetValues(HeaderNames.ContentType, out headerValues));
Assert.Equal("text/plain", headerValues.First());
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync("/ResponseHeaders");
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Request Complete", responseText);
Assert.True(response.Headers.TryGetValues("UnknownHeader", out var headerValues));
Assert.Equal("test123=foo", headerValues.First());
Assert.True(response.Content.Headers.TryGetValues(HeaderNames.ContentType, out headerValues));
Assert.Equal("text/plain", headerValues.First());
Assert.True(response.Headers.TryGetValues("MultiHeader", out headerValues));
Assert.Equal(2, headerValues.Count());
Assert.Equal("1", headerValues.First());
Assert.Equal("2", headerValues.Last());
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
Assert.True(response.Headers.TryGetValues("MultiHeader", out headerValues));
Assert.Equal(2, headerValues.Count());
Assert.Equal("1", headerValues.First());
Assert.Equal("2", headerValues.Last());
}
}
}

View File

@ -1,81 +1,28 @@
// 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.
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{
public class ResponseInvalidOrderingTests : LoggedTest
[Collection(IISTestSiteCollection.Name)]
public class ResponseInvalidOrderingTest
{
public ResponseInvalidOrderingTests(ITestOutputHelper output) : base(output)
private readonly IISTestSiteFixture _fixture;
public ResponseInvalidOrderingTest(IISTestSiteFixture fixture)
{
_fixture = fixture;
}
[ConditionalTheory]
[InlineData("SetStatusCodeAfterWrite")]
[InlineData("SetHeaderAfterWrite")]
public Task ResponseInvalidOrderingTests_ExpectFailure(string path)
public async Task ResponseInvalidOrderingTests_ExpectFailure(string path)
{
return SetResponseInvalidOperations(RuntimeFlavor.CoreClr, ApplicationType.Portable, path);
}
private async Task SetResponseInvalidOperations(RuntimeFlavor runtimeFlavor, ApplicationType applicationType, string path)
{
var serverType = ServerType.IISExpress;
var architecture = RuntimeArchitecture.x64;
var testName = $"SetResponseInvalidOperations_{runtimeFlavor}";
using (StartLog(out var loggerFactory, testName))
{
var logger = loggerFactory.CreateLogger("SetFeaturesTest");
var deploymentParameters = new DeploymentParameters(Helpers.GetTestSitesPath(), serverType, runtimeFlavor, architecture)
{
EnvironmentName = "ResponseInvalidOrdering", // Will pick the Start class named 'StartupInvalidOrdering',
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{
var deploymentResult = await deployer.DeployAsync();
deploymentResult.HttpClient.Timeout = TimeSpan.FromSeconds(5);
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
var response = await RetryHelper.RetryRequest(() =>
{
return deploymentResult.HttpClient.GetAsync(path);
}, logger, deploymentResult.HostShutdownToken, retryCount: 30);
var responseText = await response.Content.ReadAsStringAsync();
try
{
Assert.Equal($"Started_{path}Threw_Finished", responseText);
}
catch (XunitException)
{
logger.LogWarning(response.ToString());
logger.LogWarning(responseText);
throw;
}
}
}
Assert.Equal($"Started_{path}Threw_Finished", await _fixture.Client.GetStringAsync("/ResponseInvalidOrdering/" + path));
}
}
}

View File

@ -34,15 +34,16 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
};
_deployer = ApplicationDeployerFactory.Create(deploymentParameters, NullLoggerFactory.Instance);
var deploymentResult = _deployer.DeployAsync().Result;
Client = deploymentResult.HttpClient;
BaseUri = deploymentResult.ApplicationBaseUri;
ShutdownToken = deploymentResult.HostShutdownToken;
DeploymentResult = _deployer.DeployAsync().Result;
Client = DeploymentResult.HttpClient;
BaseUri = DeploymentResult.ApplicationBaseUri;
ShutdownToken = DeploymentResult.HostShutdownToken;
}
public string BaseUri { get; }
public HttpClient Client { get; }
public CancellationToken ShutdownToken { get; }
public DeploymentResult DeploymentResult { get; }
public void Dispose()
{

View File

@ -1,9 +1,17 @@
// 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.
using System;
using System.IO;
using System.Net;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Server.IIS;
using Microsoft.AspNetCore.Server.IISIntegration;
using Microsoft.Extensions.Primitives;
using Xunit;
namespace IISTestSite
{
@ -12,6 +20,17 @@ namespace IISTestSite
public void Configure(IApplicationBuilder app)
{
app.Map("/ServerVariable", ServerVariable);
app.Map("/AuthenticationAnonymous", AuthenticationAnonymous);
app.Map("/AuthenticationRestricted", AuthenticationRestricted);
app.Map("/AuthenticationForbidden", AuthenticationForbidden);
app.Map("/AuthenticationRestrictedNTLM", AuthenticationRestrictedNTLM);
app.Map("/FeatureCollectionSetRequestFeatures", FeatureCollectionSetRequestFeatures);
app.Map("/FeatureCollectionSetResponseFeatures", FeatureCollectionSetResponseFeatures);
app.Map("/FeatureCollectionSetConnectionFeatures", FeatureCollectionSetConnectionFeatures);
app.Map("/HelloWorld", HelloWorld);
app.Map("/LargeResponseBody", LargeResponseBody);
app.Map("/ResponseHeaders", ResponseHeaders);
app.Map("/ResponseInvalidOrdering", ResponseInvalidOrdering);
}
private void ServerVariable(IApplicationBuilder app)
@ -22,5 +41,249 @@ namespace IISTestSite
await ctx.Response.WriteAsync($"{varName}: {ctx.GetIISServerVariable(varName) ?? "(null)"}");
});
}
public void AuthenticationAnonymous(IApplicationBuilder app)
{
app.Run(async ctx =>
{
await ctx.Response.WriteAsync("Anonymous?" + !ctx.User.Identity.IsAuthenticated);
});
}
private void AuthenticationRestricted(IApplicationBuilder app)
{
app.Run(async ctx =>
{
if (ctx.User.Identity.IsAuthenticated)
{
await ctx.Response.WriteAsync(ctx.User.Identity.AuthenticationType);
}
else
{
await ctx.ChallengeAsync(IISDefaults.AuthenticationScheme);
}
});
}
public void AuthenticationForbidden(IApplicationBuilder app)
{
app.Run(async ctx =>
{
await ctx.ForbidAsync(IISDefaults.AuthenticationScheme);
});
}
public void AuthenticationRestrictedNTLM(IApplicationBuilder app)
{
app.Run(async ctx =>
{
if (string.Equals("NTLM", ctx.User.Identity.AuthenticationType, StringComparison.Ordinal))
{
await ctx.Response.WriteAsync("NTLM");
}
else
{
await ctx.ChallengeAsync(IISDefaults.AuthenticationScheme);
}
});
}
private void FeatureCollectionSetRequestFeatures(IApplicationBuilder app)
{
app.Run(async context =>
{
try
{
Assert.Equal("GET", context.Request.Method);
context.Request.Method = "test";
Assert.Equal("test", context.Request.Method);
Assert.Equal("http", context.Request.Scheme);
context.Request.Scheme = "test";
Assert.Equal("test", context.Request.Scheme);
Assert.Equal("/FeatureCollectionSetRequestFeatures", context.Request.PathBase);
context.Request.PathBase = "/base";
Assert.Equal("/base", context.Request.PathBase);
Assert.Equal("/path", context.Request.Path);
context.Request.Path = "/path";
Assert.Equal("/path", context.Request.Path);
Assert.Equal("?query", context.Request.QueryString.Value);
context.Request.QueryString = QueryString.Empty;
Assert.Equal("", context.Request.QueryString.Value);
Assert.Equal("HTTP/1.1", context.Request.Protocol);
context.Request.Protocol = "HTTP/1.0";
Assert.Equal("HTTP/1.0", context.Request.Protocol);
Assert.NotNull(context.Request.Headers);
var headers = new HeaderDictionary();
context.Features.Get<IHttpRequestFeature>().Headers = headers;
Assert.Same(headers, context.Features.Get<IHttpRequestFeature>().Headers);
Assert.NotNull(context.Request.Body);
var body = new MemoryStream();
context.Request.Body = body;
Assert.Same(body, context.Request.Body);
//Assert.NotNull(context.Features.Get<IHttpRequestIdentifierFeature>().TraceIdentifier);
//Assert.NotEqual(CancellationToken.None, context.RequestAborted);
//var token = new CancellationTokenSource().Token;
//context.RequestAborted = token;
//Assert.Equal(token, context.RequestAborted);
await context.Response.WriteAsync("Success");
return;
}
catch (Exception exception)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync(exception.ToString());
}
await context.Response.WriteAsync("_Failure");
});
}
private void FeatureCollectionSetResponseFeatures(IApplicationBuilder app)
{
app.Run(async context =>
{
try
{
Assert.Equal(200, context.Response.StatusCode);
context.Response.StatusCode = 404;
Assert.Equal(404, context.Response.StatusCode);
context.Response.StatusCode = 200;
Assert.Null(context.Features.Get<IHttpResponseFeature>().ReasonPhrase);
context.Features.Get<IHttpResponseFeature>().ReasonPhrase = "Set Response";
Assert.Equal("Set Response", context.Features.Get<IHttpResponseFeature>().ReasonPhrase);
Assert.NotNull(context.Response.Headers);
var headers = new HeaderDictionary();
context.Features.Get<IHttpResponseFeature>().Headers = headers;
Assert.Same(headers, context.Features.Get<IHttpResponseFeature>().Headers);
var originalBody = context.Response.Body;
Assert.NotNull(originalBody);
var body = new MemoryStream();
context.Response.Body = body;
Assert.Same(body, context.Response.Body);
context.Response.Body = originalBody;
await context.Response.WriteAsync("Success");
return;
}
catch (Exception exception)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync(exception.ToString());
}
await context.Response.WriteAsync("_Failure");
});
}
private void FeatureCollectionSetConnectionFeatures(IApplicationBuilder app)
{
app.Run(async context =>
{
try
{
Assert.True(IPAddress.IsLoopback(context.Connection.LocalIpAddress));
context.Connection.LocalIpAddress = IPAddress.IPv6Any;
Assert.Equal(IPAddress.IPv6Any, context.Connection.LocalIpAddress);
Assert.True(IPAddress.IsLoopback(context.Connection.RemoteIpAddress));
context.Connection.RemoteIpAddress = IPAddress.IPv6Any;
Assert.Equal(IPAddress.IPv6Any, context.Connection.RemoteIpAddress);
await context.Response.WriteAsync("Success");
return;
}
catch (Exception exception)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync(exception.ToString());
}
await context.Response.WriteAsync("_Failure");
});
}
private void HelloWorld(IApplicationBuilder app)
{
app.Run(async ctx =>
{
if (ctx.Request.Path.Value.StartsWith("/Path"))
{
await ctx.Response.WriteAsync(ctx.Request.Path.Value);
return;
}
if (ctx.Request.Path.Value.StartsWith("/Query"))
{
await ctx.Response.WriteAsync(ctx.Request.QueryString.Value);
return;
}
await ctx.Response.WriteAsync("Hello World");
});
}
private void LargeResponseBody(IApplicationBuilder app)
{
app.Run(async context =>
{
if (int.TryParse(context.Request.Query["length"], out var length))
{
await context.Response.WriteAsync(new string('a', length));
}
});
}
private void ResponseHeaders(IApplicationBuilder app)
{
app.Run(async context =>
{
context.Response.Headers["UnknownHeader"] = "test123=foo";
context.Response.ContentType = "text/plain";
context.Response.Headers["MultiHeader"] = new StringValues(new string[] { "1", "2" });
await context.Response.WriteAsync("Request Complete");
});
}
private void ResponseInvalidOrdering(IApplicationBuilder app)
{
app.Run(async context =>
{
if (context.Request.Path.Equals("/SetStatusCodeAfterWrite"))
{
await context.Response.WriteAsync("Started_");
try
{
context.Response.StatusCode = 200;
}
catch (InvalidOperationException)
{
await context.Response.WriteAsync("SetStatusCodeAfterWriteThrew_");
}
await context.Response.WriteAsync("Finished");
return;
}
else if (context.Request.Path.Equals("/SetHeaderAfterWrite"))
{
await context.Response.WriteAsync("Started_");
try
{
context.Response.Headers["This will fail"] = "some value";
}
catch (InvalidOperationException)
{
await context.Response.WriteAsync("SetHeaderAfterWriteThrew_");
}
await context.Response.WriteAsync("Finished");
return;
}
});
}
}
}

View File

@ -1,80 +0,0 @@
// 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.
using System;
using System.Security.Principal;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IISIntegration;
using Microsoft.Extensions.Logging;
using Xunit;
namespace IISTestSite
{
public class StartupAuthentication
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
// Simple error page without depending on Diagnostics.
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());
}
});
app.Use((context, next) =>
{
if (context.Request.Path.Equals("/Anonymous"))
{
return context.Response.WriteAsync("Anonymous?" + !context.User.Identity.IsAuthenticated);
}
if (context.Request.Path.Equals("/Restricted"))
{
if (context.User.Identity.IsAuthenticated)
{
Assert.IsType<WindowsPrincipal>(context.User);
return context.Response.WriteAsync(context.User.Identity.AuthenticationType);
}
else
{
return context.ChallengeAsync(IISDefaults.AuthenticationScheme);
}
}
if (context.Request.Path.Equals("/Forbidden"))
{
return context.ForbidAsync(IISDefaults.AuthenticationScheme);
}
if (context.Request.Path.Equals("/RestrictedNTLM"))
{
if (string.Equals("NTLM", context.User.Identity.AuthenticationType, StringComparison.Ordinal))
{
return context.Response.WriteAsync("NTLM");
}
else
{
return context.ChallengeAsync(IISDefaults.AuthenticationScheme);
}
}
return context.Response.WriteAsync("Hello World");
});
}
}
}

View File

@ -1,119 +0,0 @@
// 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.
using System;
using System.IO;
using System.Net;
using System.Threading;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.Extensions.Logging;
using Xunit;
namespace IISTestSite
{
public class StartupFeatureCollection
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async context =>
{
try
{
// Verify setting and getting each feature/ portion of the httpcontext works
if (context.Request.Path.Equals("/SetRequestFeatures"))
{
Assert.Equal("GET", context.Request.Method);
context.Request.Method = "test";
Assert.Equal("test", context.Request.Method);
Assert.Equal("http", context.Request.Scheme);
context.Request.Scheme = "test";
Assert.Equal("test", context.Request.Scheme);
Assert.Equal("", context.Request.PathBase);
context.Request.PathBase = "/base";
Assert.Equal("/base", context.Request.PathBase);
Assert.Equal("/SetRequestFeatures", context.Request.Path);
context.Request.Path = "/path";
Assert.Equal("/path", context.Request.Path);
Assert.Equal("?query", context.Request.QueryString.Value);
context.Request.QueryString = QueryString.Empty;
Assert.Equal("", context.Request.QueryString.Value);
Assert.Equal("HTTP/1.1", context.Request.Protocol);
context.Request.Protocol = "HTTP/1.0";
Assert.Equal("HTTP/1.0", context.Request.Protocol);
Assert.NotNull(context.Request.Headers);
var headers = new HeaderDictionary();
context.Features.Get<IHttpRequestFeature>().Headers = headers;
Assert.Same(headers, context.Features.Get<IHttpRequestFeature>().Headers);
Assert.NotNull(context.Request.Body);
var body = new MemoryStream();
context.Request.Body = body;
Assert.Same(body, context.Request.Body);
//Assert.NotNull(context.Features.Get<IHttpRequestIdentifierFeature>().TraceIdentifier);
//Assert.NotEqual(CancellationToken.None, context.RequestAborted);
//var token = new CancellationTokenSource().Token;
//context.RequestAborted = token;
//Assert.Equal(token, context.RequestAborted);
await context.Response.WriteAsync("Success");
return;
}
else if (context.Request.Path.Equals("/SetResponseFeatures"))
{
Assert.Equal(200, context.Response.StatusCode);
context.Response.StatusCode = 404;
Assert.Equal(404, context.Response.StatusCode);
Assert.Null(context.Features.Get<IHttpResponseFeature>().ReasonPhrase);
context.Features.Get<IHttpResponseFeature>().ReasonPhrase = "Set Response";
Assert.Equal("Set Response", context.Features.Get<IHttpResponseFeature>().ReasonPhrase);
Assert.NotNull(context.Response.Headers);
var headers = new HeaderDictionary();
context.Features.Get<IHttpResponseFeature>().Headers = headers;
Assert.Same(headers, context.Features.Get<IHttpResponseFeature>().Headers);
var originalBody = context.Response.Body;
Assert.NotNull(originalBody);
var body = new MemoryStream();
context.Response.Body = body;
Assert.Same(body, context.Response.Body);
context.Response.Body = originalBody;
await context.Response.WriteAsync("Success");
return;
}
else if (context.Request.Path.Equals("/SetConnectionFeatures"))
{
Assert.True(IPAddress.IsLoopback(context.Connection.LocalIpAddress));
context.Connection.LocalIpAddress = IPAddress.IPv6Any;
Assert.Equal(IPAddress.IPv6Any, context.Connection.LocalIpAddress);
Assert.True(IPAddress.IsLoopback(context.Connection.RemoteIpAddress));
context.Connection.RemoteIpAddress = IPAddress.IPv6Any;
Assert.Equal(IPAddress.IPv6Any, context.Connection.RemoteIpAddress);
await context.Response.WriteAsync("Success");
return;
}
}
catch (Exception exception)
{
context.Response.StatusCode = 500;
await context.Response.WriteAsync(exception.ToString());
}
await context.Response.WriteAsync("_Failure");
});
}
}
}

View File

@ -1,39 +0,0 @@
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace IISTestSite
{
public class StartupHelloWorld
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async ctx =>
{
if (ctx.Request.Path.Value.StartsWith("/Path"))
{
await ctx.Response.WriteAsync(ctx.Request.Path.Value);
return;
}
if (ctx.Request.Path.Value.StartsWith("/Query"))
{
await ctx.Response.WriteAsync(ctx.Request.QueryString.Value);
return;
}
await ctx.Response.WriteAsync("Hello World");
});
}
}
}

View File

@ -1,31 +0,0 @@
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace IISTestSite
{
public class StartupHttpsHelloWorld
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async ctx =>
{
if (ctx.Request.Path.Value.StartsWith("/ClientCertificate"))
{
await ctx.Response.WriteAsync($"{ ctx.Request.Scheme }Hello World, Cert: {ctx.Connection.ClientCertificate != null}");
return;
}
await ctx.Response.WriteAsync(ctx.Request.Scheme + "Hello World");
});
}
}
}

View File

@ -1,36 +0,0 @@
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace IISTestSite
{
public class StartupLargeResponseBody
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async context =>
{
if (context.Request.Path.Equals("/LargeResponseBody"))
{
if (int.TryParse(context.Request.Query["length"], out var length))
{
await context.Response.WriteAsync(new string('a', length));
}
}
else if (context.Request.Path.Equals("/LargeResponseBodyFromFile"))
{
var fileString = File.ReadAllText("Http.config");
await context.Response.WriteAsync(fileString);
}
});
}
}
}

View File

@ -1,33 +0,0 @@
// 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.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;
namespace IISTestSite
{
public class StartupResponseHeaders
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async context =>
{
if (context.Request.Path.Equals("/ResponseHeaders"))
{
context.Response.Headers["UnknownHeader"] = "test123=foo";
context.Response.ContentType = "text/plain";
context.Response.Headers["MultiHeader"] = new StringValues(new string[] { "1", "2" });
await context.Response.WriteAsync("Request Complete");
}
});
}
}
}

View File

@ -1,48 +0,0 @@
// 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.
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace IISTestSite
{
public class StartupResponseInvalidOrdering
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async context =>
{
if (context.Request.Path.Equals("/SetStatusCodeAfterWrite"))
{
await context.Response.WriteAsync("Started_");
try
{
context.Response.StatusCode = 200;
}
catch (InvalidOperationException)
{
await context.Response.WriteAsync("SetStatusCodeAfterWriteThrew_");
}
await context.Response.WriteAsync("Finished");
return;
}
else if (context.Request.Path.Equals("/SetHeaderAfterWrite"))
{
await context.Response.WriteAsync("Started_");
try
{
context.Response.Headers["This will fail"] = "some value";
}
catch (InvalidOperationException)
{
await context.Response.WriteAsync("SetHeaderAfterWriteThrew_");
}
await context.Response.WriteAsync("Finished");
return;
}
});
}
}
}