diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index 29e35139b9..5f258bcb87 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -5,6 +5,7 @@ using AutoFixture; using AutoFixture.AutoMoq; using AutoFixture.Kernel; using AutoFixture.NUnit3; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using Moq; @@ -21,7 +22,7 @@ using Umbraco.Web.WebApi; namespace Umbraco.Tests.UnitTests.AutoFixture { - + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = true)] public class InlineAutoMoqDataAttribute : InlineAutoDataAttribute { @@ -83,18 +84,20 @@ namespace Umbraco.Tests.UnitTests.AutoFixture Mock.Of(x => x.ToAbsolute(It.IsAny()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty), Mock.Of(x => x.Level == RuntimeLevel.Run), new UmbracoApiControllerTypeCollection(Array.Empty())))); - + fixture.Customize(u => u.FromFactory( () => new PreviewRoutes( Options.Create(new GlobalSettings()), Mock.Of(x => x.ToAbsolute(It.IsAny()) == "/umbraco" && x.ApplicationVirtualPath == string.Empty), Mock.Of(x => x.Level == RuntimeLevel.Run)))); - + var connectionStrings = new ConnectionStrings(); fixture.Customize(x => x.FromFactory(() => connectionStrings )); - + var httpContextAccessor = new HttpContextAccessor { HttpContext = new DefaultHttpContext() }; + fixture.Customize(x => x.FromFactory(() => httpContextAccessor.HttpContext)); + fixture.Customize(x => x.FromFactory(() => httpContextAccessor)); } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 749c1c6f07..8384012ca2 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -31,6 +31,7 @@ using Umbraco.Web.WebAssets; using Constants = Umbraco.Core.Constants; using Microsoft.AspNetCore.Identity; using System.Security.Claims; +using Microsoft.AspNetCore.Http; using Umbraco.Web.Security; namespace Umbraco.Web.BackOffice.Controllers @@ -52,6 +53,7 @@ namespace Umbraco.Web.BackOffice.Controllers private readonly ILogger _logger; private readonly IJsonSerializer _jsonSerializer; private readonly IBackOfficeExternalLoginProviders _externalLogins; + private readonly IHttpContextAccessor _httpContextAccessor; public BackOfficeController( IBackOfficeUserManager userManager, @@ -66,7 +68,8 @@ namespace Umbraco.Web.BackOffice.Controllers IBackOfficeSecurityAccessor backofficeSecurityAccessor, ILogger logger, IJsonSerializer jsonSerializer, - IBackOfficeExternalLoginProviders externalLogins) + IBackOfficeExternalLoginProviders externalLogins, + IHttpContextAccessor httpContextAccessor) { _userManager = userManager; _runtimeMinifier = runtimeMinifier; @@ -81,6 +84,7 @@ namespace Umbraco.Web.BackOffice.Controllers _logger = logger; _jsonSerializer = jsonSerializer; _externalLogins = externalLogins; + _httpContextAccessor = httpContextAccessor; } [HttpGet] @@ -365,7 +369,7 @@ namespace Umbraco.Web.BackOffice.Controllers ViewData.SetUmbracoPath(_globalSettings.GetUmbracoMvcArea(_hostingEnvironment)); //check if there is the TempData or cookies with the any token name specified, if so, assign to view bag and render the view - if (ViewData.FromBase64CookieData(HttpContext, ViewDataExtensions.TokenExternalSignInError, _jsonSerializer) || + if (ViewData.FromBase64CookieData(_httpContextAccessor.HttpContext, ViewDataExtensions.TokenExternalSignInError, _jsonSerializer) || ViewData.FromTempData(TempData, ViewDataExtensions.TokenExternalSignInError) || ViewData.FromTempData(TempData, ViewDataExtensions.TokenPasswordResetCode)) return defaultResponse();