From 750b6f6a1805245b89607dda6f51b61a87bae659 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 19 Feb 2020 09:26:51 +0100 Subject: [PATCH] Move more files and fixed circular dependency --- .../Cookie/ICookieManager.cs | 5 +++- .../Install/IFilePermissionHelper.cs | 5 ---- .../IPublishedSnapshotService.cs | 2 +- .../Routing/DomainUtilities.cs | 2 +- .../Templates/ITemplateRenderer.cs | 0 .../Routing/ContentFinderByConfigured404.cs | 0 .../Routing/NotFoundHandlerHelper.cs | 2 +- .../Search/ExamineFinalComponent.cs | 0 .../Search/ExamineFinalComposer.cs | 0 .../Search/ExamineIndexModel.cs | 0 .../Search/ExamineSearcherModel.cs | 0 .../Search/ExamineUserComponent.cs | 0 .../Search/UmbracoTreeSearcher.cs | 0 .../Search/UmbracoTreeSearcherFields.cs | 0 .../TagQuery.cs | 0 .../Umbraco.Infrastructure.csproj | 4 --- .../PublishedSnapshotService.cs | 10 +++++--- .../Umbraco.PublishedCache.NuCache.csproj | 1 + .../Cache/DistributedCacheBinderTests.cs | 3 ++- .../PublishedContentCacheTests.cs | 3 ++- .../PublishedContent/NuCacheChildrenTests.cs | 6 ++--- .../PublishedContent/NuCacheTests.cs | 4 +-- .../PublishedContentSnapshotTestBase.cs | 3 ++- .../Scoping/ScopedNuCacheTests.cs | 6 ++--- .../Security/BackOfficeCookieManagerTests.cs | 6 +++-- .../ContentTypeServiceVariantsTests.cs | 3 +-- .../TestControllerActivatorBase.cs | 3 ++- .../TestHelpers/TestObjects-Mocks.cs | 3 ++- .../TestHelpers/TestWithDatabaseBase.cs | 3 ++- .../Objects/TestUmbracoContextFactory.cs | 3 ++- ...RenderIndexActionSelectorAttributeTests.cs | 12 ++++++--- .../Web/Mvc/SurfaceControllerTests.cs | 12 ++++++--- .../Web/Mvc/UmbracoViewPageTests.cs | 3 ++- .../Web/WebExtensionMethodTests.cs | 9 ++++--- src/Umbraco.Web/AspNet/AspNetCookieManager.cs | 16 ++++++++++++ src/Umbraco.Web/Editors/PreviewController.cs | 8 ++++-- src/Umbraco.Web/HttpCookieExtensions.cs | 25 ++++--------------- .../Install/FilePermissionHelper.cs | 8 +++--- src/Umbraco.Web/Install/InstallHelper.cs | 10 +++++--- src/Umbraco.Web/Macros/MacroRenderer.cs | 7 ++++-- src/Umbraco.Web/Umbraco.Web.csproj | 11 -------- src/Umbraco.Web/UmbracoContext.cs | 8 ++++-- src/Umbraco.Web/UmbracoContextFactory.cs | 8 ++++-- 43 files changed, 119 insertions(+), 95 deletions(-) rename src/{Umbraco.Web => Umbraco.Abstractions}/Templates/ITemplateRenderer.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Routing/ContentFinderByConfigured404.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Routing/NotFoundHandlerHelper.cs (99%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineFinalComponent.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineFinalComposer.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineIndexModel.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineSearcherModel.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/ExamineUserComponent.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/UmbracoTreeSearcher.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/Search/UmbracoTreeSearcherFields.cs (100%) rename src/{Umbraco.Web => Umbraco.Infrastructure}/TagQuery.cs (100%) diff --git a/src/Umbraco.Abstractions/Cookie/ICookieManager.cs b/src/Umbraco.Abstractions/Cookie/ICookieManager.cs index 4822d8ce74..af0ee7b1f6 100644 --- a/src/Umbraco.Abstractions/Cookie/ICookieManager.cs +++ b/src/Umbraco.Abstractions/Cookie/ICookieManager.cs @@ -2,6 +2,9 @@ namespace Umbraco.Core.Cookie { public interface ICookieManager { - void ExpireCookie(string angularCookieName); + void ExpireCookie(string cookieName); + string GetCookieValue(string cookieName); + void SetCookieValue(string cookieName, string value); + bool HasCookie(string cookieName); } } diff --git a/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs b/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs index 90f550f2c9..b60839cb00 100644 --- a/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs +++ b/src/Umbraco.Abstractions/Install/IFilePermissionHelper.cs @@ -7,10 +7,5 @@ namespace Umbraco.Core.Install bool RunFilePermissionTestSuite(out Dictionary> report); bool EnsureDirectories(string[] dirs, out IEnumerable errors, bool writeCausesRestart = false); bool EnsureFiles(string[] files, out IEnumerable errors); - bool EnsureCanCreateSubDirectory(string dir, out IEnumerable errors); - bool EnsureCanCreateSubDirectories(IEnumerable dirs, out IEnumerable errors); - bool TestPublishedSnapshotService(out IEnumerable errors); - bool TryCreateDirectory(string dir); - bool TryAccessDirectory(string dir, bool canWrite); } } diff --git a/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs index a1894c902c..b23c8ae10f 100644 --- a/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs +++ b/src/Umbraco.Abstractions/PublishedCache/IPublishedSnapshotService.cs @@ -167,7 +167,7 @@ namespace Umbraco.Web.PublishedCache string StatusUrl { get; } - #endregion + #endregion void Collect(); } diff --git a/src/Umbraco.Abstractions/Routing/DomainUtilities.cs b/src/Umbraco.Abstractions/Routing/DomainUtilities.cs index 26801cfd27..c459ae4d14 100644 --- a/src/Umbraco.Abstractions/Routing/DomainUtilities.cs +++ b/src/Umbraco.Abstractions/Routing/DomainUtilities.cs @@ -344,7 +344,7 @@ namespace Umbraco.Web.Routing /// The current domain root node identifier, or null. /// The deepest wildcard Domain in the path, or null. /// Looks _under_ rootNodeId but not _at_ rootNodeId. - internal static Domain FindWildcardDomainInPath(IEnumerable domains, string path, int? rootNodeId) + public static Domain FindWildcardDomainInPath(IEnumerable domains, string path, int? rootNodeId) { var stopNodeId = rootNodeId ?? -1; diff --git a/src/Umbraco.Web/Templates/ITemplateRenderer.cs b/src/Umbraco.Abstractions/Templates/ITemplateRenderer.cs similarity index 100% rename from src/Umbraco.Web/Templates/ITemplateRenderer.cs rename to src/Umbraco.Abstractions/Templates/ITemplateRenderer.cs diff --git a/src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs b/src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs similarity index 100% rename from src/Umbraco.Web/Routing/ContentFinderByConfigured404.cs rename to src/Umbraco.Infrastructure/Routing/ContentFinderByConfigured404.cs diff --git a/src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs similarity index 99% rename from src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs rename to src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs index 38ecb09b2b..335e1f868a 100644 --- a/src/Umbraco.Web/Routing/NotFoundHandlerHelper.cs +++ b/src/Umbraco.Infrastructure/Routing/NotFoundHandlerHelper.cs @@ -1,13 +1,13 @@ using System; using System.Globalization; using System.Linq; +using Umbraco.Composing; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; using Umbraco.Core.Xml; -using Umbraco.Web.Composing; namespace Umbraco.Web.Routing { diff --git a/src/Umbraco.Web/Search/ExamineFinalComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineFinalComponent.cs rename to src/Umbraco.Infrastructure/Search/ExamineFinalComponent.cs diff --git a/src/Umbraco.Web/Search/ExamineFinalComposer.cs b/src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineFinalComposer.cs rename to src/Umbraco.Infrastructure/Search/ExamineFinalComposer.cs diff --git a/src/Umbraco.Web/Search/ExamineIndexModel.cs b/src/Umbraco.Infrastructure/Search/ExamineIndexModel.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineIndexModel.cs rename to src/Umbraco.Infrastructure/Search/ExamineIndexModel.cs diff --git a/src/Umbraco.Web/Search/ExamineSearcherModel.cs b/src/Umbraco.Infrastructure/Search/ExamineSearcherModel.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineSearcherModel.cs rename to src/Umbraco.Infrastructure/Search/ExamineSearcherModel.cs diff --git a/src/Umbraco.Web/Search/ExamineUserComponent.cs b/src/Umbraco.Infrastructure/Search/ExamineUserComponent.cs similarity index 100% rename from src/Umbraco.Web/Search/ExamineUserComponent.cs rename to src/Umbraco.Infrastructure/Search/ExamineUserComponent.cs diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs similarity index 100% rename from src/Umbraco.Web/Search/UmbracoTreeSearcher.cs rename to src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs diff --git a/src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcherFields.cs similarity index 100% rename from src/Umbraco.Web/Search/UmbracoTreeSearcherFields.cs rename to src/Umbraco.Infrastructure/Search/UmbracoTreeSearcherFields.cs diff --git a/src/Umbraco.Web/TagQuery.cs b/src/Umbraco.Infrastructure/TagQuery.cs similarity index 100% rename from src/Umbraco.Web/TagQuery.cs rename to src/Umbraco.Infrastructure/TagQuery.cs diff --git a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj index 2421711773..92601f9ddd 100644 --- a/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj +++ b/src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj @@ -64,8 +64,4 @@ - - - - diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs index 5d99aa6aaa..e383eb0223 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotService.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Hosting; using Umbraco.Core.Install; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; @@ -26,6 +27,7 @@ using Umbraco.Core.Services.Changes; using Umbraco.Core.Services.Implement; using Umbraco.Core.Strings; using Umbraco.Web.Cache; +using Umbraco.Web.Install; using Umbraco.Web.PublishedCache.NuCache.DataSource; using Umbraco.Web.Routing; using File = System.IO.File; @@ -50,7 +52,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private readonly ITypeFinder _typeFinder; private readonly IHostingEnvironment _hostingEnvironment; private readonly IShortStringHelper _shortStringHelper; - private readonly IFilePermissionHelper _filePermissionHelper; + private readonly IIOHelper _ioHelper; // volatile because we read it with no lock private volatile bool _isReady; @@ -88,7 +90,7 @@ namespace Umbraco.Web.PublishedCache.NuCache ITypeFinder typeFinder, IHostingEnvironment hostingEnvironment, IShortStringHelper shortStringHelper, - IFilePermissionHelper filePermissionHelper) + IIOHelper ioHelper) : base(publishedSnapshotAccessor, variationContextAccessor) { //if (Interlocked.Increment(ref _singletonCheck) > 1) @@ -108,7 +110,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _typeFinder = typeFinder; _hostingEnvironment = hostingEnvironment; _shortStringHelper = shortStringHelper; - _filePermissionHelper = filePermissionHelper; + _ioHelper = ioHelper; // we need an Xml serializer here so that the member cache can support XPath, // for members this is done by navigating the serialized-to-xml member @@ -362,7 +364,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override bool EnsureEnvironment(out IEnumerable errors) { // must have app_data and be able to write files into it - var ok = _filePermissionHelper.TryCreateDirectory(GetLocalFilesPath()); + var ok = FilePermissionHelper.TryCreateDirectory(GetLocalFilesPath(), _ioHelper); errors = ok ? Enumerable.Empty() : new[] { "NuCache local files." }; return ok; } diff --git a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj index 4c369ec2fa..2001309138 100644 --- a/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj +++ b/src/Umbraco.PublishedCache.NuCache/Umbraco.PublishedCache.NuCache.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs index 8db6b970bc..5f5fdaacc1 100644 --- a/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs +++ b/src/Umbraco.Tests/Cache/DistributedCacheBinderTests.cs @@ -165,7 +165,8 @@ namespace Umbraco.Tests.Cache Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); // just assert it does not throw var refreshers = new DistributedCacheBinder(null, umbracoContextFactory, null); diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index a7ef0ff721..b096235708 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -83,7 +83,8 @@ namespace Umbraco.Tests.Cache.PublishedCache globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); _cache = _umbracoContext.Content; } diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs index 42e446c4d3..1f153a0a5e 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheChildrenTests.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Events; using Umbraco.Core.Hosting; using Umbraco.Core.Install; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; @@ -144,7 +145,6 @@ namespace Umbraco.Tests.PublishedContent var typeFinder = new TypeFinder(Mock.Of()); - var filePermissionHelper = Mock.Of(); // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; @@ -169,7 +169,7 @@ namespace Umbraco.Tests.PublishedContent typeFinder, hostingEnvironment, new MockShortStringHelper(), - filePermissionHelper); + TestHelper.IOHelper); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); @@ -971,7 +971,7 @@ namespace Umbraco.Tests.PublishedContent documents = snapshot.Content.GetById(2).Children(_variationAccesor).ToArray(); AssertDocuments(documents, "N9", "N8", "N7"); - + } [Test] diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 08e68ce652..b0f0eb7722 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -186,8 +186,6 @@ namespace Umbraco.Tests.PublishedContent var typeFinder = new TypeFinder(Mock.Of()); - var filePermissionHelper = Mock.Of(); - // at last, create the complete NuCache snapshot service! var options = new PublishedSnapshotServiceOptions { IgnoreLocalDb = true }; _snapshotService = new PublishedSnapshotService(options, @@ -211,7 +209,7 @@ namespace Umbraco.Tests.PublishedContent typeFinder, TestHelper.GetHostingEnvironment(), new MockShortStringHelper(), - filePermissionHelper); + TestHelper.IOHelper); // invariant is the current default _variationAccesor.VariationContext = new VariationContext(); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs index 9281db2d29..d36eb0013a 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentSnapshotTestBase.cs @@ -77,7 +77,8 @@ namespace Umbraco.Tests.PublishedContent globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); return umbracoContext; } diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index d0b63f8492..1e148d33c6 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -84,7 +84,6 @@ namespace Umbraco.Tests.Scoping var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); var hostingEnvironment = TestHelper.GetHostingEnvironment(); - var filePermissionHelper = Mock.Of(); var typeFinder = new TypeFinder(Mock.Of()); @@ -108,7 +107,7 @@ namespace Umbraco.Tests.Scoping typeFinder, hostingEnvironment, new MockShortStringHelper(), - filePermissionHelper); + IOHelper); } protected IUmbracoContext GetUmbracoContextNu(string url, int templateId = 1234, RouteData routeData = null, bool setSingleton = false, IUmbracoSettingsSection umbracoSettings = null, IEnumerable urlProviders = null) @@ -126,7 +125,8 @@ namespace Umbraco.Tests.Scoping globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); if (setSingleton) Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext; diff --git a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs index 30c61350b9..eeff707618 100644 --- a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs @@ -37,7 +37,8 @@ namespace Umbraco.Tests.Security new WebSecurity(httpContextAccessor, Current.Services.UserService, globalSettings, IOHelper), globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Install); var mgr = new BackOfficeCookieManager( @@ -60,7 +61,8 @@ namespace Umbraco.Tests.Security globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var runtime = Mock.Of(x => x.Level == RuntimeLevel.Run); var mgr = new BackOfficeCookieManager(Mock.Of(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings(), IOHelper, AppCaches.RequestCache); diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index 2c22b98262..1a485ec546 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -57,7 +57,6 @@ namespace Umbraco.Tests.Services var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); var hostingEnvironment = Mock.Of(); - var filePermissionHelper = Mock.Of(); var typeFinder = new TypeFinder(Mock.Of()); @@ -81,7 +80,7 @@ namespace Umbraco.Tests.Services typeFinder, hostingEnvironment, new MockShortStringHelper(), - filePermissionHelper); + IOHelper); } public class LocalServerMessenger : ServerMessengerBase diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs index 2eb8decd1c..9ab9cc8640 100644 --- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs +++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs @@ -144,7 +144,8 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting globalSettings, new TestVariationContextAccessor(), TestHelper.IOHelper, - TestHelper.UriUtility); + TestHelper.UriUtility, + new AspNetCookieManager(httpContextAccessor)); //replace it umbracoContextAccessor.UmbracoContext = umbCtx; diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs index 25588bed62..5dabb7ed06 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs @@ -134,7 +134,8 @@ namespace Umbraco.Tests.TestHelpers Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); return umbracoContextFactory.EnsureUmbracoContext().UmbracoContext; } diff --git a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs index c2a44026d6..6172c63650 100644 --- a/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs +++ b/src/Umbraco.Tests/TestHelpers/TestWithDatabaseBase.cs @@ -382,7 +382,8 @@ namespace Umbraco.Tests.TestHelpers globalSettings ?? Factory.GetInstance(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); if (setSingleton) Umbraco.Web.Composing.Current.UmbracoContextAccessor.UmbracoContext = umbracoContext; diff --git a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs index 26bed55cbc..20b18fa728 100644 --- a/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs +++ b/src/Umbraco.Tests/Testing/Objects/TestUmbracoContextFactory.cs @@ -45,7 +45,8 @@ namespace Umbraco.Tests.Testing.Objects Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); return umbracoContextFactory; } diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index 98301076ef..bdd7c6eb93 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -74,7 +74,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -105,7 +106,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -136,7 +138,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -167,7 +170,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), TestHelper.IOHelper, TestHelper.UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index 089dfea592..652a95ed2b 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -47,7 +47,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; @@ -76,7 +77,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbCtx = umbracoContextReference.UmbracoContext; @@ -108,7 +110,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; @@ -146,7 +149,8 @@ namespace Umbraco.Tests.Web.Mvc Mock.Of(), IOHelper, UriUtility, - httpContextAccessor); + httpContextAccessor, + new AspNetCookieManager(httpContextAccessor)); var umbracoContextReference = umbracoContextFactory.EnsureUmbracoContext(); var umbracoContext = umbracoContextReference.UmbracoContext; diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index a03c84f0b0..9b11feb170 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -445,7 +445,8 @@ namespace Umbraco.Tests.Web.Mvc globalSettings, new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); //if (setSingleton) //{ diff --git a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs index 76edcd4152..b126c823cd 100644 --- a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs +++ b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs @@ -36,7 +36,8 @@ namespace Umbraco.Tests.Web TestObjects.GetGlobalSettings(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var r1 = new RouteData(); r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); @@ -56,7 +57,8 @@ namespace Umbraco.Tests.Web TestObjects.GetGlobalSettings(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var r1 = new RouteData(); r1.DataTokens.Add(Core.Constants.Web.UmbracoContextDataToken, umbCtx); @@ -86,7 +88,8 @@ namespace Umbraco.Tests.Web TestObjects.GetGlobalSettings(), new TestVariationContextAccessor(), IOHelper, - UriUtility); + UriUtility, + new AspNetCookieManager(httpContextAccessor)); var httpContext = Mock.Of(); diff --git a/src/Umbraco.Web/AspNet/AspNetCookieManager.cs b/src/Umbraco.Web/AspNet/AspNetCookieManager.cs index 2b5318110d..d8fcefa0e1 100644 --- a/src/Umbraco.Web/AspNet/AspNetCookieManager.cs +++ b/src/Umbraco.Web/AspNet/AspNetCookieManager.cs @@ -1,3 +1,4 @@ +using System.Web; using Umbraco.Core.Cookie; namespace Umbraco.Web @@ -15,5 +16,20 @@ namespace Umbraco.Web { _httpContextAccessor.HttpContext?.ExpireCookie(cookieName); } + + public string GetCookieValue(string cookieName) + { + return _httpContextAccessor.HttpContext?.Request.GetCookieValue(cookieName); + } + + public void SetCookieValue(string cookieName, string value) + { + _httpContextAccessor.HttpContext?.Response.Cookies.Set(new HttpCookie(cookieName, value)); + } + + public bool HasCookie(string cookieName) + { + return !(GetCookieValue(cookieName) is null); + } } } diff --git a/src/Umbraco.Web/Editors/PreviewController.cs b/src/Umbraco.Web/Editors/PreviewController.cs index 0b7b4e2b43..eedc134d36 100644 --- a/src/Umbraco.Web/Editors/PreviewController.cs +++ b/src/Umbraco.Web/Editors/PreviewController.cs @@ -6,6 +6,7 @@ using System.Web.UI; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Cookie; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Services; @@ -34,6 +35,7 @@ namespace Umbraco.Web.Editors private readonly TreeCollection _treeCollection; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHostingEnvironment _hostingEnvironment; + private readonly ICookieManager _cookieManager; public PreviewController( UmbracoFeatures features, @@ -46,7 +48,8 @@ namespace Umbraco.Web.Editors IIOHelper ioHelper, TreeCollection treeCollection, IHttpContextAccessor httpContextAccessor, - IHostingEnvironment hostingEnvironment) + IHostingEnvironment hostingEnvironment, + ICookieManager cookieManager) { _features = features; _globalSettings = globalSettings; @@ -59,6 +62,7 @@ namespace Umbraco.Web.Editors _treeCollection = treeCollection; _httpContextAccessor = httpContextAccessor; _hostingEnvironment = hostingEnvironment; + _cookieManager = cookieManager; } [UmbracoAuthorize(redirectToUmbracoLogin: true)] @@ -117,7 +121,7 @@ namespace Umbraco.Web.Editors public ActionResult End(string redir = null) { - var previewToken = Request.GetPreviewCookieValue(); + var previewToken = _cookieManager.GetPreviewCookieValue(); var service = Current.PublishedSnapshotService; service.ExitPreview(previewToken); diff --git a/src/Umbraco.Web/HttpCookieExtensions.cs b/src/Umbraco.Web/HttpCookieExtensions.cs index 5f520653f5..26490771cd 100644 --- a/src/Umbraco.Web/HttpCookieExtensions.cs +++ b/src/Umbraco.Web/HttpCookieExtensions.cs @@ -5,6 +5,7 @@ using System.Net.Http.Headers; using System.Web; using Microsoft.Owin; using Umbraco.Core; +using Umbraco.Core.Cookie; namespace Umbraco.Web { @@ -97,34 +98,18 @@ namespace Umbraco.Web return null; } - public static string GetPreviewCookieValue(this HttpRequestBase request) + public static string GetPreviewCookieValue(this ICookieManager cookieManager) { - return request.GetCookieValue(Constants.Web.PreviewCookieName); + return cookieManager.GetCookieValue(Constants.Web.PreviewCookieName); } - - public static string GetPreviewCookieValue(this HttpRequest request) - { - return new HttpRequestWrapper(request).GetPreviewCookieValue(); - } - /// /// Does a preview cookie exist ? /// /// /// - public static bool HasPreviewCookie(this HttpRequestBase request) + public static bool HasPreviewCookie(this ICookieManager cookieManager) { - return request.Cookies[Constants.Web.PreviewCookieName] != null; - } - - /// - /// Does a preview cookie exist ? - /// - /// - /// - public static bool HasPreviewCookie(this HttpRequest request) - { - return new HttpRequestWrapper(request).HasPreviewCookie(); + return cookieManager.HasCookie(Constants.Web.PreviewCookieName); } /// diff --git a/src/Umbraco.Web/Install/FilePermissionHelper.cs b/src/Umbraco.Web/Install/FilePermissionHelper.cs index 16de66554f..be7c88729a 100644 --- a/src/Umbraco.Web/Install/FilePermissionHelper.cs +++ b/src/Umbraco.Web/Install/FilePermissionHelper.cs @@ -11,7 +11,7 @@ using Umbraco.Web.PublishedCache; namespace Umbraco.Web.Install { - internal class FilePermissionHelper : IFilePermissionHelper + public class FilePermissionHelper : IFilePermissionHelper { // ensure that these directories exist and Umbraco can write to them private readonly string[] _permissionDirs; @@ -155,11 +155,11 @@ namespace Umbraco.Web.Install // tries to create a file // if successful, the file is deleted // creates the directory if needed - does not delete it - public bool TryCreateDirectory(string dir) + public static bool TryCreateDirectory(string dir, IIOHelper ioHelper) { try { - var dirPath = _ioHelper.MapPath(dir); + var dirPath = ioHelper.MapPath(dir); if (Directory.Exists(dirPath) == false) Directory.CreateDirectory(dirPath); @@ -262,7 +262,7 @@ namespace Umbraco.Web.Install } } - private string CreateRandomName() + private static string CreateRandomName() { return "umbraco-test." + Guid.NewGuid().ToString("N").Substring(0, 8); } diff --git a/src/Umbraco.Web/Install/InstallHelper.cs b/src/Umbraco.Web/Install/InstallHelper.cs index 8be0af629e..fb37246a21 100644 --- a/src/Umbraco.Web/Install/InstallHelper.cs +++ b/src/Umbraco.Web/Install/InstallHelper.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Cookie; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Core.Persistence; @@ -23,11 +24,12 @@ namespace Umbraco.Web.Install private readonly IGlobalSettings _globalSettings; private readonly IUmbracoVersion _umbracoVersion; private readonly IConnectionStrings _connectionStrings; + private readonly ICookieManager _cookieManager; private InstallationType? _installationType; public InstallHelper(IHttpContextAccessor httpContextAccessor, DatabaseBuilder databaseBuilder, - ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IConnectionStrings connectionStrings) + ILogger logger, IGlobalSettings globalSettings, IUmbracoVersion umbracoVersion, IConnectionStrings connectionStrings, ICookieManager cookieManager) { _httpContextAccessor = httpContextAccessor; _logger = logger; @@ -35,6 +37,7 @@ namespace Umbraco.Web.Install _umbracoVersion = umbracoVersion; _databaseBuilder = databaseBuilder; _connectionStrings = connectionStrings ?? throw new ArgumentNullException(nameof(connectionStrings)); + _cookieManager = cookieManager; } public InstallationType GetInstallationType() @@ -53,7 +56,7 @@ namespace Umbraco.Web.Install // Check for current install Id var installId = Guid.NewGuid(); - var installCookie = httpContext.Request.GetCookieValue(Constants.Web.InstallerCookieName); + var installCookie = _cookieManager.GetCookieValue(Constants.Web.InstallerCookieName); if (string.IsNullOrEmpty(installCookie) == false) { if (Guid.TryParse(installCookie, out installId)) @@ -63,7 +66,8 @@ namespace Umbraco.Web.Install installId = Guid.NewGuid(); } } - httpContext.Response.Cookies.Set(new HttpCookie(Constants.Web.InstallerCookieName, "1")); + + _cookieManager.SetCookieValue(Constants.Web.InstallerCookieName, "1"); var dbProvider = string.Empty; if (IsBrandNewInstall == false) diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index a776c4f65e..013f54c5fc 100755 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -7,6 +7,7 @@ using System.Text; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Cookie; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -27,10 +28,11 @@ namespace Umbraco.Web.Macros private readonly AppCaches _appCaches; private readonly IMacroService _macroService; private readonly IIOHelper _ioHelper; + private readonly ICookieManager _cookieManager; private readonly IUserService _userService; private readonly IHttpContextAccessor _httpContextAccessor; - public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService, IHttpContextAccessor httpContextAccessor, IIOHelper ioHelper) + public MacroRenderer(IProfilingLogger plogger, IUmbracoContextAccessor umbracoContextAccessor, IContentSection contentSection, ILocalizedTextService textService, AppCaches appCaches, IMacroService macroService, IUserService userService, IHttpContextAccessor httpContextAccessor, IIOHelper ioHelper, ICookieManager cookieManager) { _plogger = plogger ?? throw new ArgumentNullException(nameof(plogger)); _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); @@ -39,6 +41,7 @@ namespace Umbraco.Web.Macros _appCaches = appCaches ?? throw new ArgumentNullException(nameof(appCaches)); _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); + _cookieManager = cookieManager; _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _httpContextAccessor = httpContextAccessor; } @@ -419,7 +422,7 @@ namespace Umbraco.Web.Macros case '%': attributeValue = context?.Session[name]?.ToString(); if (string.IsNullOrEmpty(attributeValue)) - attributeValue = context?.Request.GetCookieValue(name); + attributeValue = _cookieManager.GetCookieValue(name); break; case '#': attributeValue = pageElements[name]?.ToString(); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index cb4c3cf69a..fdb00827b8 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -192,9 +192,6 @@ - - - @@ -209,7 +206,6 @@ - @@ -219,7 +215,6 @@ - @@ -302,7 +297,6 @@ - @@ -334,7 +328,6 @@ - @@ -416,7 +409,6 @@ - @@ -490,7 +482,6 @@ - True @@ -553,10 +544,8 @@ - - diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 2dacc60e73..6a51157285 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -2,6 +2,7 @@ using System; using System.Web; using Umbraco.Core; using Umbraco.Core.Configuration; +using Umbraco.Core.Cookie; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Web.Composing; @@ -20,6 +21,7 @@ namespace Umbraco.Web private readonly IGlobalSettings _globalSettings; private readonly IIOHelper _ioHelper; private readonly UriUtility _uriUtility; + private readonly ICookieManager _cookieManager; private readonly Lazy _publishedSnapshot; private string _previewToken; private bool? _previewing; @@ -34,7 +36,8 @@ namespace Umbraco.Web IGlobalSettings globalSettings, IVariationContextAccessor variationContextAccessor, IIOHelper ioHelper, - UriUtility uriUtility) + UriUtility uriUtility, + ICookieManager cookieManager) { if (httpContextAccessor == null) throw new ArgumentNullException(nameof(httpContextAccessor)); if (publishedSnapshotService == null) throw new ArgumentNullException(nameof(publishedSnapshotService)); @@ -44,6 +47,7 @@ namespace Umbraco.Web _globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); _uriUtility = uriUtility; + _cookieManager = cookieManager; // ensure that this instance is disposed when the request terminates, though we *also* ensure // this happens in the Umbraco module since the UmbracoCOntext is added to the HttpContext items. @@ -183,7 +187,7 @@ namespace Umbraco.Web && request.Url.IsBackOfficeRequest(HttpRuntime.AppDomainAppVirtualPath, _globalSettings, _ioHelper) == false && Security.CurrentUser != null) { - var previewToken = request.GetPreviewCookieValue(); // may be null or empty + var previewToken = _cookieManager.GetPreviewCookieValue(); // may be null or empty _previewToken = previewToken.IsNullOrWhiteSpace() ? null : previewToken; } diff --git a/src/Umbraco.Web/UmbracoContextFactory.cs b/src/Umbraco.Web/UmbracoContextFactory.cs index d627d9e823..edbf7d1196 100644 --- a/src/Umbraco.Web/UmbracoContextFactory.cs +++ b/src/Umbraco.Web/UmbracoContextFactory.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using Umbraco.Core.Configuration; +using Umbraco.Core.Cookie; using Umbraco.Core.IO; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Services; @@ -26,6 +27,7 @@ namespace Umbraco.Web private readonly IUserService _userService; private readonly IIOHelper _ioHelper; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly ICookieManager _cookieManager; private readonly UriUtility _uriUtility; /// @@ -40,7 +42,8 @@ namespace Umbraco.Web IUserService userService, IIOHelper ioHelper, UriUtility uriUtility, - IHttpContextAccessor httpContextAccessor) + IHttpContextAccessor httpContextAccessor, + ICookieManager cookieManager) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService)); @@ -51,6 +54,7 @@ namespace Umbraco.Web _ioHelper = ioHelper; _uriUtility = uriUtility; _httpContextAccessor = httpContextAccessor; + _cookieManager = cookieManager; } private IUmbracoContext CreateUmbracoContext() @@ -69,7 +73,7 @@ namespace Umbraco.Web var webSecurity = new WebSecurity(_httpContextAccessor, _userService, _globalSettings, _ioHelper); - return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility); + return new UmbracoContext(_httpContextAccessor, _publishedSnapshotService, webSecurity, _globalSettings, _variationContextAccessor, _ioHelper, _uriUtility, _cookieManager); } ///