From 55d849a0d0c085c1ebb82bdce10247329b9541fe Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Thu, 18 Oct 2018 12:17:32 -0700 Subject: [PATCH] Add compression pass through tests (#1525) --- build/dependencies.props | 3 +- .../CompressionTests.cs | 58 +++++++++++++++++++ .../Inprocess/CompressionTests.cs | 4 +- .../InProcessWebSite/InProcessWebSite.csproj | 1 + .../OutOfProcessWebSite.csproj | 1 + .../StressTestWebSite.csproj | 3 +- .../shared/SharedStartup/Startup.shared.cs | 18 ++++++ 7 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 test/Common.FunctionalTests/CompressionTests.cs diff --git a/build/dependencies.props b/build/dependencies.props index b4708cadc2..5c5ee5437f 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -1,4 +1,4 @@ - + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) @@ -15,6 +15,7 @@ 2.2.0-preview3-35496 2.2.0-preview3-35496 2.2.0-preview3-35496 + 2.2.0-preview3-35496 0.6.0-preview3-35496 2.2.0-preview3-35496 2.2.0-preview3-35496 diff --git a/test/Common.FunctionalTests/CompressionTests.cs b/test/Common.FunctionalTests/CompressionTests.cs new file mode 100644 index 0000000000..c2d0277c4c --- /dev/null +++ b/test/Common.FunctionalTests/CompressionTests.cs @@ -0,0 +1,58 @@ +// 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.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Testing.xunit; +using Xunit; + +namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests +{ + [Collection(IISCompressionSiteCollection.Name)] + public abstract class CompressionTests : FixtureLoggedTest + { + private readonly IISTestSiteFixture _fixture; + + [Collection(IISTestSiteCollection.Name)] + public class InProc: CompressionTests + { + public InProc(IISTestSiteFixture fixture) : base(fixture) { } + } + + [Collection(OutOfProcessTestSiteCollection.Name)] + public class OutOfProcess: CompressionTests + { + public OutOfProcess(OutOfProcessTestSiteFixture fixture) : base(fixture) { } + } + + [Collection(OutOfProcessV1TestSiteCollection.Name)] + public class OutOfProcessV1: CompressionTests + { + public OutOfProcessV1(OutOfProcessV1TestSiteFixture fixture) : base(fixture) { } + } + + protected CompressionTests(IISTestSiteFixture fixture) : base(fixture) + { + _fixture = fixture; + } + + [ConditionalFact] + public async Task PassesThroughCompression() + { + var request = new HttpRequestMessage(HttpMethod.Get, "/CompressedData"); + + request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); + + var response = await _fixture.Client.SendAsync(request); + Assert.Equal("gzip", response.Content.Headers.ContentEncoding.Single()); + Assert.Equal( + new byte[] { + 0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x0B, 0x63, 0x60, 0xA0, 0x3D, 0x00, 0x00, + 0xCA, 0xC6, 0x88, 0x99, 0x64, 0x00, 0x00, 0x00 }, + await response.Content.ReadAsByteArrayAsync()); + } + } +} diff --git a/test/Common.FunctionalTests/Inprocess/CompressionTests.cs b/test/Common.FunctionalTests/Inprocess/CompressionTests.cs index 1a1218a526..ce1c84e609 100644 --- a/test/Common.FunctionalTests/Inprocess/CompressionTests.cs +++ b/test/Common.FunctionalTests/Inprocess/CompressionTests.cs @@ -13,11 +13,11 @@ using Xunit; namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests { [Collection(IISCompressionSiteCollection.Name)] - public class CompressionTests : FixtureLoggedTest + public class CompressionModuleTests : FixtureLoggedTest { private readonly IISCompressionSiteFixture _fixture; - public CompressionTests(IISCompressionSiteFixture fixture): base(fixture) + public CompressionModuleTests(IISCompressionSiteFixture fixture): base(fixture) { _fixture = fixture; } diff --git a/test/WebSites/InProcessWebSite/InProcessWebSite.csproj b/test/WebSites/InProcessWebSite/InProcessWebSite.csproj index a8e89bf438..d007d2daa1 100644 --- a/test/WebSites/InProcessWebSite/InProcessWebSite.csproj +++ b/test/WebSites/InProcessWebSite/InProcessWebSite.csproj @@ -20,6 +20,7 @@ + diff --git a/test/WebSites/OutOfProcessWebSite/OutOfProcessWebSite.csproj b/test/WebSites/OutOfProcessWebSite/OutOfProcessWebSite.csproj index 36ca6e2b54..14beb7394e 100644 --- a/test/WebSites/OutOfProcessWebSite/OutOfProcessWebSite.csproj +++ b/test/WebSites/OutOfProcessWebSite/OutOfProcessWebSite.csproj @@ -19,6 +19,7 @@ + diff --git a/test/WebSites/StressTestWebSite/StressTestWebSite.csproj b/test/WebSites/StressTestWebSite/StressTestWebSite.csproj index 9a1ed0692f..25ae032221 100644 --- a/test/WebSites/StressTestWebSite/StressTestWebSite.csproj +++ b/test/WebSites/StressTestWebSite/StressTestWebSite.csproj @@ -1,4 +1,4 @@ - + @@ -16,6 +16,7 @@ + diff --git a/test/WebSites/shared/SharedStartup/Startup.shared.cs b/test/WebSites/shared/SharedStartup/Startup.shared.cs index 4035decb02..b5d7f0305f 100644 --- a/test/WebSites/shared/SharedStartup/Startup.shared.cs +++ b/test/WebSites/shared/SharedStartup/Startup.shared.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; @@ -15,6 +16,11 @@ namespace TestSite { public partial class Startup { + public void ConfigureServices(IServiceCollection serviceCollection) + { + serviceCollection.AddResponseCompression(); + } + private async Task HostingEnvironment(HttpContext ctx) { var hostingEnv = ctx.RequestServices.GetService(); @@ -95,5 +101,17 @@ namespace TestSite context.Response.Headers["Server"] = "MyServer/7.8"; return Task.CompletedTask; } + + public void CompressedData(IApplicationBuilder builder) + { + builder.UseResponseCompression(); + // write random bytes to check that compressed data is passed through + builder.Run( + async context => + { + context.Response.ContentType = "text/html"; + await context.Response.Body.WriteAsync(new byte[100], 0, 100); + }); + } } }