From 3b45ea5c270a23a19fa4a9bb9b35ffbdb8f7a91c Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 12 Sep 2016 14:56:09 -0700 Subject: [PATCH] Add a test that verifies strong name signing works for precompiled views Fixes #16 --- TestApps.sln | 6 +++ .../ApplicationConsumingPrecompiledViews.cs | 8 +-- .../ApplicationWithConfigureMvcTest.cs | 8 +-- .../Infrastructure/RuntimeFlavors.cs | 15 ++++++ .../PublishWithEmbedViewSourcesTest.cs | 8 +-- .../Resources/StrongNamedApp.Home.Index.txt | 1 + .../SimpleAppTest.cs | 8 +-- .../StrongNamedAppTest.cs | 50 +++++++++++++++++++ .../Controllers/HomeController.cs | 9 ++++ testapps/StrongNamedApp/Program.cs | 26 ++++++++++ testapps/StrongNamedApp/Startup.cs | 26 ++++++++++ testapps/StrongNamedApp/StrongNamedApp.xproj | 18 +++++++ .../StrongNamedApp/Views/Home/Index.cshtml | 1 + testapps/StrongNamedApp/project.json | 46 +++++++++++++++++ 14 files changed, 202 insertions(+), 28 deletions(-) create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Resources/StrongNamedApp.Home.Index.txt create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/StrongNamedAppTest.cs create mode 100644 testapps/StrongNamedApp/Controllers/HomeController.cs create mode 100644 testapps/StrongNamedApp/Program.cs create mode 100644 testapps/StrongNamedApp/Startup.cs create mode 100644 testapps/StrongNamedApp/StrongNamedApp.xproj create mode 100644 testapps/StrongNamedApp/Views/Home/Index.cshtml create mode 100644 testapps/StrongNamedApp/project.json diff --git a/TestApps.sln b/TestApps.sln index 9cfeb8f1b1..7b40d9f475 100644 --- a/TestApps.sln +++ b/TestApps.sln @@ -21,6 +21,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ClassLibraryWithPrecompiled EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PublishWIthEmbedViewSources", "testapps\PublishWIthEmbedViewSources\PublishWIthEmbedViewSources.xproj", "{E3462190-3068-40F0-9AA5-34779FE252AC}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "StrongNamedApp", "testapps\StrongNamedApp\StrongNamedApp.xproj", "{88903BE5-0676-4667-8160-B24646E0B76E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {E3462190-3068-40F0-9AA5-34779FE252AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {E3462190-3068-40F0-9AA5-34779FE252AC}.Release|Any CPU.ActiveCfg = Release|Any CPU {E3462190-3068-40F0-9AA5-34779FE252AC}.Release|Any CPU.Build.0 = Release|Any CPU + {88903BE5-0676-4667-8160-B24646E0B76E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88903BE5-0676-4667-8160-B24646E0B76E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88903BE5-0676-4667-8160-B24646E0B76E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88903BE5-0676-4667-8160-B24646E0B76E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationConsumingPrecompiledViews.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationConsumingPrecompiledViews.cs index cd589745cc..db0b63a017 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationConsumingPrecompiledViews.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationConsumingPrecompiledViews.cs @@ -23,13 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation public ApplicationTestFixture Fixture { get; } - public static IEnumerable SupportedFlavorsTheoryData - { - get - { - return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f }); - } - } + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; [Theory] [MemberData(nameof(SupportedFlavorsTheoryData))] diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationWithConfigureMvcTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationWithConfigureMvcTest.cs index 4265905f6a..762faba4f1 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationWithConfigureMvcTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/ApplicationWithConfigureMvcTest.cs @@ -19,13 +19,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation public ApplicationTestFixture Fixture { get; } - public static IEnumerable SupportedFlavorsTheoryData - { - get - { - return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f }); - } - } + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; [Theory] [MemberData(nameof(SupportedFlavorsTheoryData))] diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Infrastructure/RuntimeFlavors.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Infrastructure/RuntimeFlavors.cs index e4781e38db..f75324015f 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Infrastructure/RuntimeFlavors.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Infrastructure/RuntimeFlavors.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using Microsoft.AspNetCore.Server.IntegrationTesting; +using Xunit; namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation { @@ -20,5 +21,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation } } } + + public static TheoryData SupportedFlavorsTheoryData + { + get + { + var theory = new TheoryData(); + foreach (var item in SupportedFlavors) + { + theory.Add(item); + } + + return theory; + } + } } } diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs index a408edaefa..b945947a54 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/PublishWithEmbedViewSourcesTest.cs @@ -23,13 +23,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests public ApplicationTestFixture Fixture { get; } - public static IEnumerable SupportedFlavorsTheoryData - { - get - { - return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f }); - } - } + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; [Theory] [MemberData(nameof(SupportedFlavorsTheoryData))] diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Resources/StrongNamedApp.Home.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Resources/StrongNamedApp.Home.Index.txt new file mode 100644 index 0000000000..6ae2a2651a --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/Resources/StrongNamedApp.Home.Index.txt @@ -0,0 +1 @@ +Hello from view in AspNetCore.Views_Home_Index_cshtml, StrongNamedApp.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/SimpleAppTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/SimpleAppTest.cs index f6b97c2ce3..b1a7a8120d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/SimpleAppTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/SimpleAppTest.cs @@ -18,13 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation public ApplicationTestFixture Fixture { get; } - public static IEnumerable SupportedFlavorsTheoryData - { - get - { - return RuntimeFlavors.SupportedFlavors.Select(f => new object[] { f }); - } - } + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; [Theory] [MemberData(nameof(SupportedFlavorsTheoryData))] diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/StrongNamedAppTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/StrongNamedAppTest.cs new file mode 100644 index 0000000000..3c9b5629ae --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Precompilation.FunctionalTests/StrongNamedAppTest.cs @@ -0,0 +1,50 @@ +// 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.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Precompilation +{ + public class StrongNamedAppTest : IClassFixture + { + public StrongNamedAppTest(StrongNamedAppFixture fixture) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + public static TheoryData SupportedFlavorsTheoryData => RuntimeFlavors.SupportedFlavorsTheoryData; + + [Theory] + [MemberData(nameof(SupportedFlavorsTheoryData))] + public async Task PrecompiledAssembliesUseSameStrongNameAsApplication(RuntimeFlavor flavor) + { + // Arrange + using (var deployer = Fixture.CreateDeployment(flavor)) + { + var deploymentResult = deployer.Deploy(); + + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + deploymentResult.ApplicationBaseUri, + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("StrongNamedApp.Home.Index.txt", response); + } + } + + public class StrongNamedAppFixture : ApplicationTestFixture + { + public StrongNamedAppFixture() + : base("StrongNamedApp") + { + } + } + } +} diff --git a/testapps/StrongNamedApp/Controllers/HomeController.cs b/testapps/StrongNamedApp/Controllers/HomeController.cs new file mode 100644 index 0000000000..8877a4cc81 --- /dev/null +++ b/testapps/StrongNamedApp/Controllers/HomeController.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Mvc; + +namespace StrongNamedApp.Controllers +{ + public class HomeController : Controller + { + public IActionResult Index() => View(); + } +} diff --git a/testapps/StrongNamedApp/Program.cs b/testapps/StrongNamedApp/Program.cs new file mode 100644 index 0000000000..52868ba38a --- /dev/null +++ b/testapps/StrongNamedApp/Program.cs @@ -0,0 +1,26 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace StrongNamedApp +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/testapps/StrongNamedApp/Startup.cs b/testapps/StrongNamedApp/Startup.cs new file mode 100644 index 0000000000..a75f450846 --- /dev/null +++ b/testapps/StrongNamedApp/Startup.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace StrongNamedApp +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + // Add framework services. + services.AddMvc(); + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(); + app.UseMvc(routes => + { + routes.MapRoute( + name: "default", + template: "{controller=Home}/{action=Index}/{id?}"); + }); + } + } +} diff --git a/testapps/StrongNamedApp/StrongNamedApp.xproj b/testapps/StrongNamedApp/StrongNamedApp.xproj new file mode 100644 index 0000000000..3cc9e35815 --- /dev/null +++ b/testapps/StrongNamedApp/StrongNamedApp.xproj @@ -0,0 +1,18 @@ + + + + 14.0.25420 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 88903be5-0676-4667-8160-b24646e0b76e + .\obj + .\bin\ + + + + 2.0 + + + \ No newline at end of file diff --git a/testapps/StrongNamedApp/Views/Home/Index.cshtml b/testapps/StrongNamedApp/Views/Home/Index.cshtml new file mode 100644 index 0000000000..ac68ee5f45 --- /dev/null +++ b/testapps/StrongNamedApp/Views/Home/Index.cshtml @@ -0,0 +1 @@ +Hello from view in @GetType().AssemblyQualifiedName diff --git a/testapps/StrongNamedApp/project.json b/testapps/StrongNamedApp/project.json new file mode 100644 index 0000000000..4ab5dcc974 --- /dev/null +++ b/testapps/StrongNamedApp/project.json @@ -0,0 +1,46 @@ +{ + "buildOptions": { + "emitEntryPoint": true, + "preserveCompilationContext": true, + "keyFile": "../../tools/Key.snk", + }, + "dependencies": { + "Microsoft.AspNetCore.Mvc": "1.1.0-*", + "Microsoft.AspNetCore.Mvc.Razor.Precompilation.Design": { + "version": "1.0.0-*", + "target": "package", + "type": "build" + }, + "Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*", + "Microsoft.Extensions.Configuration.CommandLine": "1.1.0-*", + "Microsoft.Extensions.Logging.Console": "1.1.0-*" + }, + + "tools": { + "Microsoft.AspNetCore.Mvc.Razor.Precompilation.Tools": "1.0.0-*" + }, + + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0", + "type": "platform" + } + } + }, + "net451": {} + }, + + "publishOptions": { + "include": [ + "wwwroot", + "appsettings.json", + "web.config" + ] + }, + + "scripts": { + "postpublish": "dotnet razor-precompile --configuration %publish:Configuration% --framework %publish:TargetFramework% --output-path %publish:OutputPath% %publish:ProjectPath%" + } +}