From aa1fd5d89a81aff26eb623976bf392ba469f4ff8 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 15 Sep 2016 15:11:47 -0700 Subject: [PATCH] Move ChunkingCookieManager to a separate Sources project --- Security.sln | 30 ++++- .../Resources.resx | 126 ------------------ .../project.json | 7 +- .../ChunkingCookieManager.cs | 26 +++- ...etCore.ChunkingCookieManager.Sources.xproj | 18 +++ .../project.json | 12 ++ .../CookieChunkingTests.cs | 2 +- ...e.ChunkingCookieManager.Sources.Test.xproj | 21 +++ .../project.json | 26 ++++ 9 files changed, 135 insertions(+), 133 deletions(-) delete mode 100644 src/Microsoft.AspNetCore.Authentication.Cookies/Resources.resx rename src/{Microsoft.AspNetCore.Authentication.Cookies => Microsoft.AspNetCore.ChunkingCookieManager.Sources}/ChunkingCookieManager.cs (89%) create mode 100644 src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/Microsoft.AspNetCore.ChunkingCookieManager.Sources.xproj create mode 100644 src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/project.json rename test/{Microsoft.AspNetCore.Authentication.Test/Cookies/Infrastructure => Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test}/CookieChunkingTests.cs (98%) create mode 100644 test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test.xproj create mode 100644 test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/project.json diff --git a/Security.sln b/Security.sln index 2ed873270c..c84ec1bd96 100644 --- a/Security.sln +++ b/Security.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4D2B6A51-2F9F-44F5-8131-EA5CAC053652}" EndProject @@ -57,6 +57,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Owin.Security.Int EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "OpenIdConnect.AzureAdSample", "samples\OpenIdConnect.AzureAdSample\OpenIdConnect.AzureAdSample.xproj", "{3A7AD414-EBDE-4F92-B307-4E8F19B6117E}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.ChunkingCookieManager.Sources", "src\Microsoft.AspNetCore.ChunkingCookieManager.Sources\Microsoft.AspNetCore.ChunkingCookieManager.Sources.xproj", "{2690FBE6-9D27-4C84-B82C-11188B0BCDA3}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test", "test\Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test\Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test.xproj", "{51563775-C659-4907-9BAF-9995BAB87D01}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -325,6 +329,28 @@ Global {3A7AD414-EBDE-4F92-B307-4E8F19B6117E}.Release|Mixed Platforms.Build.0 = Release|Any CPU {3A7AD414-EBDE-4F92-B307-4E8F19B6117E}.Release|x86.ActiveCfg = Release|Any CPU {3A7AD414-EBDE-4F92-B307-4E8F19B6117E}.Release|x86.Build.0 = Release|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Debug|x86.ActiveCfg = Debug|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Debug|x86.Build.0 = Debug|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Release|Any CPU.Build.0 = Release|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Release|x86.ActiveCfg = Release|Any CPU + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3}.Release|x86.Build.0 = Release|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Debug|x86.ActiveCfg = Debug|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Debug|x86.Build.0 = Debug|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Release|Any CPU.Build.0 = Release|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Release|x86.ActiveCfg = Release|Any CPU + {51563775-C659-4907-9BAF-9995BAB87D01}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -352,5 +378,7 @@ Global {A7922DD8-09F1-43E4-938B-CC523EA08898} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652} {A2B5DC39-68D5-4145-A8CC-6AEAB7D33A24} = {7BF11F3A-60B6-4796-B504-579C67FFBA34} {3A7AD414-EBDE-4F92-B307-4E8F19B6117E} = {F8C0AA27-F3FB-4286-8E4C-47EF86B539FF} + {2690FBE6-9D27-4C84-B82C-11188B0BCDA3} = {4D2B6A51-2F9F-44F5-8131-EA5CAC053652} + {51563775-C659-4907-9BAF-9995BAB87D01} = {7BF11F3A-60B6-4796-B504-579C67FFBA34} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Authentication.Cookies/Resources.resx b/src/Microsoft.AspNetCore.Authentication.Cookies/Resources.resx deleted file mode 100644 index 71debecfa3..0000000000 --- a/src/Microsoft.AspNetCore.Authentication.Cookies/Resources.resx +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - The cookie key and options are larger than ChunksSize, leaving no room for data. - - - The chunked cookie is incomplete. Only {0} of the expected {1} chunks were found, totaling {2} characters. A client size limit may have been exceeded. - - \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Authentication.Cookies/project.json b/src/Microsoft.AspNetCore.Authentication.Cookies/project.json index 1317797b6a..331de199ac 100644 --- a/src/Microsoft.AspNetCore.Authentication.Cookies/project.json +++ b/src/Microsoft.AspNetCore.Authentication.Cookies/project.json @@ -18,10 +18,15 @@ "nowarn": [ "CS1591" ], - "xmlDoc": true + "xmlDoc": true, + "define": [ "SECURITY" ] }, "dependencies": { "Microsoft.AspNetCore.Authentication": "1.1.0-*", + "Microsoft.AspNetCore.ChunkingCookieManager.Sources": { + "version": "1.1.0-*", + "type": "build" + }, "Microsoft.Extensions.Options": "1.1.0-*", "Microsoft.Extensions.TaskCache.Sources": { "version": "1.1.0-*", diff --git a/src/Microsoft.AspNetCore.Authentication.Cookies/ChunkingCookieManager.cs b/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/ChunkingCookieManager.cs similarity index 89% rename from src/Microsoft.AspNetCore.Authentication.Cookies/ChunkingCookieManager.cs rename to src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/ChunkingCookieManager.cs index c7bff38d1f..26fe0809c5 100644 --- a/src/Microsoft.AspNetCore.Authentication.Cookies/ChunkingCookieManager.cs +++ b/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/ChunkingCookieManager.cs @@ -9,6 +9,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Primitives; using Microsoft.Net.Http.Headers; +// Keep the type public for Security repo as it would be a breaking change to change the accessor now. +// Make this type internal for other repos as it could be used by multiple projects and having it public causes type conflicts. +#if SECURITY namespace Microsoft.AspNetCore.Authentication.Cookies { /// @@ -17,6 +20,16 @@ namespace Microsoft.AspNetCore.Authentication.Cookies /// public class ChunkingCookieManager : ICookieManager { +#else +namespace Microsoft.AspNetCore.Internal +{ + /// + /// This handles cookies that are limited by per cookie length. It breaks down long cookies for responses, and reassembles them + /// from requests. + /// + internal class ChunkingCookieManager + { +#endif private const string ChunkKeySuffix = "C"; private const string ChunkCountPrefix = "chunks-"; @@ -96,7 +109,12 @@ namespace Microsoft.AspNetCore.Authentication.Cookies totalSize += chunks[i].Length; } throw new FormatException( - string.Format(CultureInfo.CurrentCulture, Resources.Exception_ImcompleteChunkedCookie, chunkId - 1, chunksCount, totalSize)); + string.Format( + CultureInfo.CurrentCulture, + "The chunked cookie is incomplete. Only {0} of the expected {1} chunks were found, totaling {2} characters. A client size limit may have been exceeded.", + chunkId - 1, + chunksCount, + totalSize)); } // Missing chunk, abort by returning the original cookie value. It may have been a false positive? return value; @@ -162,7 +180,7 @@ namespace Microsoft.AspNetCore.Authentication.Cookies { // 10 is the minimum data we want to put in an individual cookie, including the cookie chunk identifier "CXX". // No room for data, we can't chunk the options and name - throw new InvalidOperationException(Resources.Exception_CookieLimitTooSmall); + throw new InvalidOperationException("The cookie key and options are larger than ChunksSize, leaving no room for data."); } else { @@ -247,10 +265,10 @@ namespace Microsoft.AspNetCore.Authentication.Cookies } var responseHeaders = context.Response.Headers; - var existingValues = responseHeaders[Constants.Headers.SetCookie]; + var existingValues = responseHeaders[HeaderNames.SetCookie]; if (!StringValues.IsNullOrEmpty(existingValues)) { - responseHeaders[Constants.Headers.SetCookie] = existingValues.Where(value => !rejectPredicate(value)).ToArray(); + responseHeaders[HeaderNames.SetCookie] = existingValues.Where(value => !rejectPredicate(value)).ToArray(); } AppendResponseCookie( diff --git a/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/Microsoft.AspNetCore.ChunkingCookieManager.Sources.xproj b/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/Microsoft.AspNetCore.ChunkingCookieManager.Sources.xproj new file mode 100644 index 0000000000..593e5d6816 --- /dev/null +++ b/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/Microsoft.AspNetCore.ChunkingCookieManager.Sources.xproj @@ -0,0 +1,18 @@ + + + + 14.0.25420 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 2690fbe6-9d27-4c84-b82c-11188b0bcda3 + Microsoft.AspNetCore.ChunkingCookieManager.Sources + .\obj + .\bin\ + + + 2.0 + + + \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/project.json b/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/project.json new file mode 100644 index 0000000000..a1a4f21841 --- /dev/null +++ b/src/Microsoft.AspNetCore.ChunkingCookieManager.Sources/project.json @@ -0,0 +1,12 @@ +{ + "version": "1.1.0-*", + "shared": "*.cs", + "dependencies": { + "Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*", + "Microsoft.Net.Http.Headers": "1.1.0-*" + }, + "frameworks": { + "net451": {}, + "netstandard1.3": {} + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs b/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/CookieChunkingTests.cs similarity index 98% rename from test/Microsoft.AspNetCore.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs rename to test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/CookieChunkingTests.cs index 670baf5db4..c978d169e4 100644 --- a/test/Microsoft.AspNetCore.Authentication.Test/Cookies/Infrastructure/CookieChunkingTests.cs +++ b/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/CookieChunkingTests.cs @@ -5,7 +5,7 @@ using System; using Microsoft.AspNetCore.Http; using Xunit; -namespace Microsoft.AspNetCore.Authentication.Cookies.Infrastructure +namespace Microsoft.AspNetCore.Internal { public class CookieChunkingTests { diff --git a/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test.xproj b/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test.xproj new file mode 100644 index 0000000000..d95a6c1287 --- /dev/null +++ b/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test.xproj @@ -0,0 +1,21 @@ + + + + 14.0.25420 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 51563775-c659-4907-9baf-9995bab87d01 + Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test + .\obj + .\bin\ + + + 2.0 + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/project.json b/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/project.json new file mode 100644 index 0000000000..f5fab3f1e6 --- /dev/null +++ b/test/Microsoft.AspNetCore.ChunkingCookieManager.Sources.Test/project.json @@ -0,0 +1,26 @@ +{ + "buildOptions": { + "warningsAsErrors": true + }, + "dependencies": { + "dotnet-test-xunit": "2.2.0-*", + "Microsoft.AspNetCore.ChunkingCookieManager.Sources": { + "version": "1.1.0-*", + "type": "build" + }, + "Microsoft.AspNetCore.Http": "1.1.0-*", + "xunit": "2.2.0-*" + }, + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0-*", + "type": "platform" + } + } + }, + "net451": {} + }, + "testRunner": "xunit" +} \ No newline at end of file