From 51bbf7ceb53a34cfc9a65a2967ed9ed88ff4c175 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 16 Feb 2016 14:22:59 +0100 Subject: [PATCH 1/2] U4-7494 Installation Fails for 7.3.3 - Intermittent - Value cannot be null. Parameter name: sqlSyntax --- .../Security/Identity/BackOfficeCookieManager.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Umbraco.Web/Security/Identity/BackOfficeCookieManager.cs b/src/Umbraco.Web/Security/Identity/BackOfficeCookieManager.cs index 76bd80037c..598309161e 100644 --- a/src/Umbraco.Web/Security/Identity/BackOfficeCookieManager.cs +++ b/src/Umbraco.Web/Security/Identity/BackOfficeCookieManager.cs @@ -73,6 +73,16 @@ namespace Umbraco.Web.Security.Identity /// internal bool ShouldAuthenticateRequest(IOwinContext ctx, Uri originalRequestUrl, bool checkForceAuthTokens = true) { + if (_umbracoContextAccessor.Value.Application.IsConfigured == false + && _umbracoContextAccessor.Value.Application.DatabaseContext.IsDatabaseConfigured == false) + { + //Do not authenticate the request if we don't have a db and we are not configured - since we will never need + // to know a current user in this scenario - we treat it as a new install. Without this we can have some issues + // when people have older invalid cookies on the same domain since our user managers might attempt to lookup a user + // and we don't even have a db. + return false; + } + var request = ctx.Request; var httpCtx = ctx.TryGetHttpContext(); From 7002291c4170c848ab25dad85c92d17f7c122dd4 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 16 Feb 2016 14:51:15 +0100 Subject: [PATCH 2/2] adds tests for ShouldAuthenticateRequest for app configurations --- .../Security/BackOfficeCookieManagerTests.cs | 81 +++++++++++++++++++ .../UmbracoBackOfficeIdentityTests.cs | 2 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 9 +++ src/Umbraco.Tests/packages.config | 2 + 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs diff --git a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs new file mode 100644 index 0000000000..f93fd355ed --- /dev/null +++ b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Web; +using Microsoft.Owin; +using Moq; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Logging; +using Umbraco.Core.Persistence; +using Umbraco.Core.Persistence.SqlSyntax; +using Umbraco.Core.Profiling; +using Umbraco.Tests.TestHelpers; +using Umbraco.Web; +using Umbraco.Web.Routing; +using Umbraco.Web.Security; +using Umbraco.Web.Security.Identity; + +namespace Umbraco.Tests.Security +{ + [TestFixture] + public class BackOfficeCookieManagerTests + { + [Test] + public void ShouldAuthenticateRequest_When_Not_Configured() + { + var dbCtx = new Mock(Mock.Of(), Mock.Of(), Mock.Of(), "test"); + dbCtx.Setup(x => x.IsDatabaseConfigured).Returns(false); + + var appCtx = new ApplicationContext( + dbCtx.Object, + MockHelper.GetMockedServiceContext(), + CacheHelper.CreateDisabledCacheHelper(), + new ProfilingLogger(Mock.Of(), Mock.Of())); + + var umbCtx = UmbracoContext.CreateContext( + Mock.Of(), + appCtx, + new WebSecurity(Mock.Of(), appCtx), + Mock.Of(), new List(), false); + + var mgr = new BackOfficeCookieManager(Mock.Of(accessor => accessor.Value == umbCtx)); + + var result = mgr.ShouldAuthenticateRequest(Mock.Of(), new Uri("http://localhost/umbraco")); + + Assert.IsFalse(result); + } + + [Test] + public void ShouldAuthenticateRequest_When_Configured() + { + var dbCtx = new Mock(Mock.Of(), Mock.Of(), Mock.Of(), "test"); + dbCtx.Setup(x => x.IsDatabaseConfigured).Returns(true); + + var appCtx = new ApplicationContext( + dbCtx.Object, + MockHelper.GetMockedServiceContext(), + CacheHelper.CreateDisabledCacheHelper(), + new ProfilingLogger(Mock.Of(), Mock.Of())); + + var umbCtx = UmbracoContext.CreateContext( + Mock.Of(), + appCtx, + new WebSecurity(Mock.Of(), appCtx), + Mock.Of(), new List(), false); + + var mgr = new BackOfficeCookieManager(Mock.Of(accessor => accessor.Value == umbCtx)); + + var request = new Mock(); + request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco")); + + var result = mgr.ShouldAuthenticateRequest( + Mock.Of(context => context.Request == request.Object), + new Uri("http://localhost/umbraco")); + + Assert.IsTrue(result); + } + + //TODO : Write remaining tests for `ShouldAuthenticateRequest` + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs b/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs index 2e3bc39814..813653fb7c 100644 --- a/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs +++ b/src/Umbraco.Tests/Security/UmbracoBackOfficeIdentityTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Text; @@ -9,6 +8,7 @@ using Newtonsoft.Json; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Security; +using Umbraco.Core.Services; namespace Umbraco.Tests.Security { diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 223ea33faa..cbad6db867 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -75,6 +75,10 @@ False ..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll + + ..\packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll + True + True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll @@ -94,6 +98,10 @@ False ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + ..\packages\Owin.1.0\lib\net40\Owin.dll + True + ..\packages\semver.1.1.2\lib\net45\Semver.dll @@ -194,6 +202,7 @@ + diff --git a/src/Umbraco.Tests/packages.config b/src/Umbraco.Tests/packages.config index 8986f13197..89a6429d46 100644 --- a/src/Umbraco.Tests/packages.config +++ b/src/Umbraco.Tests/packages.config @@ -13,11 +13,13 @@ + +