From 16db36eecd10cb339ba469b5f6086b3848b5e404 Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 21 Aug 2020 13:53:27 +0200 Subject: [PATCH 01/13] Start working on tests --- .../FileNames/UiFileNames.cs | 38 +++++++++++++++++++ .../AutoFixture/AutoMoqDataAttribute.cs | 14 +++++++ .../Extensions/LinkGeneratorExtensions.cs | 10 +++++ .../Extensions/UrlHelperExtensions.cs | 12 ------ .../Install/InstallController.cs | 2 +- 5 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs diff --git a/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs b/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs new file mode 100644 index 0000000000..b5ebc3f5bf --- /dev/null +++ b/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using NUnit.Framework; + +namespace Umbraco.Tests.Integration.FileNames +{ + [TestFixture] + public class UiFileNames + { + [Test] + public void MacroTemplates() + { + var files = Directory.GetFiles(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\PartialViewMacros\\Templates"); + foreach(var file in files) + { + var fileName = file.Split("\\").Last(); + Assert.AreEqual(char.ToUpper(fileName[0]), fileName[0], $"{fileName} does not start with an uppercase letter."); + var titleCase = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(fileName.ToLower()); + } + } + + [Test] + public void LanguageFilesAreLowercase() + { + var files = Directory.GetFiles(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\config\\lang"); + foreach(var file in files) + { + var fileName = file.Split("\\").Last(); + Assert.AreEqual(fileName.ToLower(), fileName); + } + + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index 568704583d..dab22fbb62 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -8,6 +8,8 @@ using Moq; using Umbraco.Core.BackOffice; using Umbraco.Core.Configuration; using Umbraco.Web.BackOffice.Controllers; +using Umbraco.Core; +using Umbraco.Web.Common.Install; namespace Umbraco.Tests.UnitTests.AutoFixture { @@ -36,12 +38,24 @@ namespace Umbraco.Tests.UnitTests.AutoFixture (a,b,c) => BackOfficeIdentityUser.CreateNew(Mock.Of(),a,b,c))); fixture .Customize(new ConstructorCustomization(typeof(UsersController), new GreedyConstructorQuery())) + .Customize(new ConstructorCustomization(typeof(InstallController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery())) .Customize(new AutoMoqCustomization()); // When requesting an IUserStore ensure we actually uses a IUserLockoutStore fixture.Customize>(cc => cc.FromFactory(() => Mock.Of>())); + fixture.Customize( + u => u.FromFactory( + (a, b, c) => new ConfigConnectionString(a, b, c))); + + fixture.Customize( + u => u.FromFactory( + () => new UmbracoVersion())); + + var connectionStrings = Mock.Of(); + Mock.Get(connectionStrings).Setup(x => x[Constants.System.UmbracoConnectionName]).Returns((ConfigConnectionString)new ConfigConnectionString(string.Empty, string.Empty, string.Empty)); + fixture.Customize(x => x.FromFactory(() => connectionStrings )); diff --git a/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs b/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs index dbfbee912e..66f219c266 100644 --- a/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs @@ -47,6 +47,16 @@ namespace Umbraco.Extensions return linkGenerator.GetPathByAction(nameof(InstallController.Index), ControllerExtensions.GetControllerName(), new { area = Constants.Web.Mvc.InstallArea }); } + /// + /// Returns the URL for the installer api + /// + /// + /// + public static string GetInstallerApiUrl(this LinkGenerator linkGenerator) + { + return linkGenerator.GetPathByAction(nameof(InstallController.Index), ControllerExtensions.GetControllerName(), new { area = Constants.Web.Mvc.InstallArea }); + } + /// /// Return the Url for a Web Api service /// diff --git a/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs b/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs index 8b1d41634d..03329547bc 100644 --- a/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UrlHelperExtensions.cs @@ -32,18 +32,6 @@ namespace Umbraco.Extensions return url.Action("Default", ControllerExtensions.GetControllerName(backOfficeControllerType), new { area = Constants.Web.Mvc.BackOfficeApiArea }); } - /// - /// Return the installer API url - /// - /// - /// - public static string GetInstallerApiUrl(this IUrlHelper url) - { - // there is no default action here so we need to get it by action and trim the action - return url.Action("GetSetup", ControllerExtensions.GetControllerName(), new { area = Constants.Web.Mvc.InstallArea }) - .TrimEnd("GetSetup"); - } - /// /// Return the Url for a Web Api service /// diff --git a/src/Umbraco.Web.Common/Install/InstallController.cs b/src/Umbraco.Web.Common/Install/InstallController.cs index 2b9f716516..dbd0def5e9 100644 --- a/src/Umbraco.Web.Common/Install/InstallController.cs +++ b/src/Umbraco.Web.Common/Install/InstallController.cs @@ -81,7 +81,7 @@ namespace Umbraco.Web.Common.Install } // gen the install base url - ViewData.SetInstallApiBaseUrl(Url.GetInstallerApiUrl()); + ViewData.SetInstallApiBaseUrl(_linkGenerator.GetInstallerApiUrl()); // get the base umbraco folder var baseFolder = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath); From 157068105c3805b59b366d0dbb346e8ae110918a Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 21 Aug 2020 13:53:57 +0200 Subject: [PATCH 02/13] Remember to actually add the test --- .../InstallControllerTest.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs new file mode 100644 index 0000000000..fc59231bee --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Moq; +using NUnit.Framework; +using Umbraco.Core.Configuration; +using Umbraco.Tests.UnitTests.AutoFixture; +using Umbraco.Web.Common.Install; +using Umbraco.Core; +using AutoFixture.NUnit3; +using Umbraco.Core.Hosting; +using System.IO; +using System.Reflection; + +namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common +{ + [TestFixture] + class InstallControllerTest + { + [Test, AutoMoqData] + public async Task InstallViewExists( + [Frozen] IHostingEnvironment hostingEnvironment, + IHostingEnvironment environment, + InstallController sut) + { + Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny())).Returns("/"); + var viewResult = await sut.Index() as ViewResult; + var sections = viewResult.ViewName.Split("\\"); + var fileName = sections[sections.Length - 1]; + var location = new FileInfo(typeof(InstallController).Assembly.Location).Directory; + } + } +} From 00f1e4a247c2943e453f031c734f87568062302a Mon Sep 17 00:00:00 2001 From: Mole Date: Fri, 21 Aug 2020 14:20:30 +0200 Subject: [PATCH 03/13] Assert that the view exists in InstallControllerTest --- .../Umbraco.Web.Common/InstallControllerTest.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs index fc59231bee..847d0a900b 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs @@ -13,6 +13,7 @@ using AutoFixture.NUnit3; using Umbraco.Core.Hosting; using System.IO; using System.Reflection; +using System.Linq; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common { @@ -29,7 +30,11 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common var viewResult = await sut.Index() as ViewResult; var sections = viewResult.ViewName.Split("\\"); var fileName = sections[sections.Length - 1]; - var location = new FileInfo(typeof(InstallController).Assembly.Location).Directory; + + // TODO: Don't use DirectoryInfo to get contents of UmbracoInstall, use something that works everywhere. + var views = new DirectoryInfo(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\UmbracoInstall").GetFiles() + .Select(f => f.Name).ToArray(); + Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } } } From b944142905bb818f3c5ac8ddeb2a7e17c3614f47 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Mon, 24 Aug 2020 08:45:41 +0200 Subject: [PATCH 04/13] Add PreviewViewExists test --- .../AutoFixture/AutoMoqDataAttribute.cs | 1 + .../InstallControllerTest.cs | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index dab22fbb62..adb1166cd8 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -39,6 +39,7 @@ namespace Umbraco.Tests.UnitTests.AutoFixture fixture .Customize(new ConstructorCustomization(typeof(UsersController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(InstallController), new GreedyConstructorQuery())) + .Customize(new ConstructorCustomization(typeof(PreviewController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery())) .Customize(new AutoMoqCustomization()); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs index 847d0a900b..484d7e48a6 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs @@ -14,16 +14,16 @@ using Umbraco.Core.Hosting; using System.IO; using System.Reflection; using System.Linq; +using Umbraco.Web.BackOffice.Controllers; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common { [TestFixture] - class InstallControllerTest + class InstallControllerTest // TODO: Is this the right place? { [Test, AutoMoqData] public async Task InstallViewExists( [Frozen] IHostingEnvironment hostingEnvironment, - IHostingEnvironment environment, InstallController sut) { Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny())).Returns("/"); @@ -36,5 +36,21 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common .Select(f => f.Name).ToArray(); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } + + [Test, AutoMoqData] + public void PrviewViewExists( + [Frozen] IGlobalSettings globalSettings, + PreviewController sut) + { + Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); + + var viewResult = sut.Index() as ViewResult; + var sections = viewResult.ViewName.Split("/"); + var fileName = sections[sections.Length - 1]; + + var views = new DirectoryInfo(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\UmbracoBackOffice").GetFiles() + .Select(f => f.Name).ToArray(); + Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); + } } } From 3e3f91c14d8fd99f7b51d416cac23504a60e55aa Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 26 Aug 2020 09:55:14 +0200 Subject: [PATCH 05/13] No longer use relative path to find views --- .../FileNames/UiFileNames.cs | 14 +-- .../AutoFixture/AutoMoqDataAttribute.cs | 1 + .../Umbraco.Web.Common/FileNameTests.cs | 108 ++++++++++++++++++ .../InstallControllerTest.cs | 56 --------- 4 files changed, 112 insertions(+), 67 deletions(-) create mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs delete mode 100644 src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs diff --git a/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs b/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs index b5ebc3f5bf..d671420791 100644 --- a/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs +++ b/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs @@ -5,15 +5,17 @@ using System.IO; using System.Linq; using System.Text; using NUnit.Framework; +using Umbraco.Tests.Integration.Testing; namespace Umbraco.Tests.Integration.FileNames { [TestFixture] - public class UiFileNames + public class UiFileNames : UmbracoIntegrationTest { [Test] public void MacroTemplates() { + var basePath = IOHelper.MapPath("~/"); var files = Directory.GetFiles(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\PartialViewMacros\\Templates"); foreach(var file in files) { @@ -23,16 +25,6 @@ namespace Umbraco.Tests.Integration.FileNames } } - [Test] - public void LanguageFilesAreLowercase() - { - var files = Directory.GetFiles(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\config\\lang"); - foreach(var file in files) - { - var fileName = file.Split("\\").Last(); - Assert.AreEqual(fileName.ToLower(), fileName); - } - } } } diff --git a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs index adb1166cd8..625e1ca619 100644 --- a/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs +++ b/src/Umbraco.Tests.UnitTests/AutoFixture/AutoMoqDataAttribute.cs @@ -40,6 +40,7 @@ namespace Umbraco.Tests.UnitTests.AutoFixture .Customize(new ConstructorCustomization(typeof(UsersController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(InstallController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(PreviewController), new GreedyConstructorQuery())) + .Customize(new ConstructorCustomization(typeof(BackOfficeController), new GreedyConstructorQuery())) .Customize(new ConstructorCustomization(typeof(BackOfficeUserManager), new GreedyConstructorQuery())) .Customize(new AutoMoqCustomization()); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs new file mode 100644 index 0000000000..aca6abbbbd --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Moq; +using NUnit.Framework; +using Umbraco.Core.Configuration; +using Umbraco.Tests.UnitTests.AutoFixture; +using Umbraco.Web.Common.Install; +using Umbraco.Core; +using AutoFixture.NUnit3; +using Umbraco.Core.Hosting; +using System.IO; +using System.Reflection; +using System.Linq; +using Umbraco.Web.BackOffice.Controllers; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using AutoFixture; +using Microsoft.AspNetCore.Http; + +namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common +{ + [TestFixture] + class FileNameTests + { + private string getViewName(ViewResult viewResult, string seperator = "/") + { + var sections = viewResult.ViewName.Split(seperator); + return sections[sections.Length - 1]; + } + + private string[] getUiFiles(IEnumerable pathFromNetCore) + { + var sourceRoot = TestContext.CurrentContext.TestDirectory.Split("Umbraco.Tests.UnitTests")[0]; + var pathToFiles = Path.Combine(sourceRoot, "Umbraco.Web.UI.NetCore"); + foreach(var pathSection in pathFromNetCore) + { + pathToFiles = Path.Combine(pathToFiles, pathSection); + } + + return new DirectoryInfo(pathToFiles).GetFiles().Select(f => f.Name).ToArray(); + } + + [Test, AutoMoqData] + public async Task InstallViewExists( + [Frozen] IHostingEnvironment hostingEnvironment, + InstallController sut) + { + Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny())).Returns("http://localhost/"); + var viewResult = await sut.Index() as ViewResult; + var fileName = getViewName(viewResult, "\\"); + + // TODO: Don't use DirectoryInfo to get contents of UmbracoInstall, use something that works everywhere. + var views = getUiFiles(new string[] { "Umbraco", "UmbracoInstall" }); + Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); + } + + [Test, AutoMoqData] + public void PrviewViewExists( + [Frozen] IGlobalSettings globalSettings, + PreviewController sut) + { + Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); + + var viewResult = sut.Index() as ViewResult; + var fileName = getViewName(viewResult); + + var views = getUiFiles(new string[] {"umbraco", "UmbracoBackOffice" }); + + Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); + } + + [Test, AutoMoqData] + public async Task BackOfficeDefaultExists( + [Frozen] IGlobalSettings globalSettings, + [Frozen] IHostingEnvironment hostingEnvironment, + [Frozen] ITempDataDictionary tempDataDictionary, + BackOfficeController sut) + { + Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); + Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/"); + Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/"); + + + sut.TempData = tempDataDictionary; + + var viewResult = await sut.Default() as ViewResult; + var fileName = getViewName(viewResult); + var views = getUiFiles(new string[] { "umbraco", "UmbracoBackOffice" }); + + Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); + } + + + [Test] + public void LanguageFilesAreLowercase() + { + + var files = getUiFiles(new string[] { "umbraco", "config", "lang" }); + foreach (var fileName in files) + { + Assert.AreEqual(fileName.ToLower(), fileName, $"Language files must be all lowercase but {fileName} is not lowercase."); + } + + } + } +} diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs deleted file mode 100644 index 484d7e48a6..0000000000 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/InstallControllerTest.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Moq; -using NUnit.Framework; -using Umbraco.Core.Configuration; -using Umbraco.Tests.UnitTests.AutoFixture; -using Umbraco.Web.Common.Install; -using Umbraco.Core; -using AutoFixture.NUnit3; -using Umbraco.Core.Hosting; -using System.IO; -using System.Reflection; -using System.Linq; -using Umbraco.Web.BackOffice.Controllers; - -namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common -{ - [TestFixture] - class InstallControllerTest // TODO: Is this the right place? - { - [Test, AutoMoqData] - public async Task InstallViewExists( - [Frozen] IHostingEnvironment hostingEnvironment, - InstallController sut) - { - Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny())).Returns("/"); - var viewResult = await sut.Index() as ViewResult; - var sections = viewResult.ViewName.Split("\\"); - var fileName = sections[sections.Length - 1]; - - // TODO: Don't use DirectoryInfo to get contents of UmbracoInstall, use something that works everywhere. - var views = new DirectoryInfo(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\UmbracoInstall").GetFiles() - .Select(f => f.Name).ToArray(); - Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); - } - - [Test, AutoMoqData] - public void PrviewViewExists( - [Frozen] IGlobalSettings globalSettings, - PreviewController sut) - { - Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); - - var viewResult = sut.Index() as ViewResult; - var sections = viewResult.ViewName.Split("/"); - var fileName = sections[sections.Length - 1]; - - var views = new DirectoryInfo(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\UmbracoBackOffice").GetFiles() - .Select(f => f.Name).ToArray(); - Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); - } - } -} From 9a243566aed4f25ab4cd782e40136f1d72476a7c Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 26 Aug 2020 10:09:24 +0200 Subject: [PATCH 06/13] Use Path.DirectorySeperatorChar for InstallView test --- .../Umbraco.Web.Common/FileNameTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs index aca6abbbbd..d68d474d78 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs @@ -49,7 +49,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common { Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny())).Returns("http://localhost/"); var viewResult = await sut.Index() as ViewResult; - var fileName = getViewName(viewResult, "\\"); + var fileName = getViewName(viewResult, Path.DirectorySeparatorChar.ToString()); // TODO: Don't use DirectoryInfo to get contents of UmbracoInstall, use something that works everywhere. var views = getUiFiles(new string[] { "Umbraco", "UmbracoInstall" }); @@ -66,7 +66,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common var viewResult = sut.Index() as ViewResult; var fileName = getViewName(viewResult); - var views = getUiFiles(new string[] {"umbraco", "UmbracoBackOffice" }); + var views = getUiFiles(new string[] {"Umbraco", "UmbracoBackOffice" }); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } @@ -87,7 +87,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common var viewResult = await sut.Default() as ViewResult; var fileName = getViewName(viewResult); - var views = getUiFiles(new string[] { "umbraco", "UmbracoBackOffice" }); + var views = getUiFiles(new string[] { "Umbraco", "UmbracoBackOffice" }); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } @@ -97,7 +97,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common public void LanguageFilesAreLowercase() { - var files = getUiFiles(new string[] { "umbraco", "config", "lang" }); + var files = getUiFiles(new string[] { "Umbraco", "config", "lang" }); foreach (var fileName in files) { Assert.AreEqual(fileName.ToLower(), fileName, $"Language files must be all lowercase but {fileName} is not lowercase."); From fd7e46588e48cbaee89cfdd46556b910d1235f13 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 26 Aug 2020 10:17:41 +0200 Subject: [PATCH 07/13] Remove unused partialViewMacro tests --- .../FileNames/UiFileNames.cs | 30 ------------------- 1 file changed, 30 deletions(-) delete mode 100644 src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs diff --git a/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs b/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs deleted file mode 100644 index d671420791..0000000000 --- a/src/Umbraco.Tests.Integration/FileNames/UiFileNames.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text; -using NUnit.Framework; -using Umbraco.Tests.Integration.Testing; - -namespace Umbraco.Tests.Integration.FileNames -{ - [TestFixture] - public class UiFileNames : UmbracoIntegrationTest - { - [Test] - public void MacroTemplates() - { - var basePath = IOHelper.MapPath("~/"); - var files = Directory.GetFiles(@"..\\..\\..\\..\\Umbraco.Web.UI.NetCore\\umbraco\\PartialViewMacros\\Templates"); - foreach(var file in files) - { - var fileName = file.Split("\\").Last(); - Assert.AreEqual(char.ToUpper(fileName[0]), fileName[0], $"{fileName} does not start with an uppercase letter."); - var titleCase = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(fileName.ToLower()); - } - } - - - } -} From 1243b7e127fb826559e9896d60ec991c231a7746 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Wed, 26 Aug 2020 10:21:43 +0200 Subject: [PATCH 08/13] Remove out of date TODO --- src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs index d68d474d78..772becf2e4 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs @@ -51,7 +51,6 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common var viewResult = await sut.Index() as ViewResult; var fileName = getViewName(viewResult, Path.DirectorySeparatorChar.ToString()); - // TODO: Don't use DirectoryInfo to get contents of UmbracoInstall, use something that works everywhere. var views = getUiFiles(new string[] { "Umbraco", "UmbracoInstall" }); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } From df4677e97000b3f8ace4974160e71c464689f03f Mon Sep 17 00:00:00 2001 From: Mole Date: Thu, 27 Aug 2020 11:31:46 +0200 Subject: [PATCH 09/13] Update src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs Co-authored-by: Bjarke Berg --- .../Umbraco.Web.Common/FileNameTests.cs | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs index 772becf2e4..c1c331903e 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Web.Common/FileNameTests.cs @@ -1,40 +1,34 @@ -using System; using System.Collections.Generic; -using System.Text; +using System.IO; +using System.Linq; using System.Threading.Tasks; +using AutoFixture.NUnit3; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ViewFeatures; using Moq; using NUnit.Framework; using Umbraco.Core.Configuration; -using Umbraco.Tests.UnitTests.AutoFixture; -using Umbraco.Web.Common.Install; -using Umbraco.Core; -using AutoFixture.NUnit3; using Umbraco.Core.Hosting; -using System.IO; -using System.Reflection; -using System.Linq; +using Umbraco.Tests.UnitTests.AutoFixture; using Umbraco.Web.BackOffice.Controllers; -using Microsoft.AspNetCore.Mvc.ViewFeatures; -using AutoFixture; -using Microsoft.AspNetCore.Http; +using Umbraco.Web.Common.Install; namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common { [TestFixture] - class FileNameTests + internal class FileNameTests { - private string getViewName(ViewResult viewResult, string seperator = "/") + private string GetViewName(ViewResult viewResult, string separator = "/") { - var sections = viewResult.ViewName.Split(seperator); - return sections[sections.Length - 1]; + var sections = viewResult.ViewName.Split(separator); + return sections[^1]; } - private string[] getUiFiles(IEnumerable pathFromNetCore) + private IEnumerable GetUiFiles(IEnumerable pathFromNetCore) { var sourceRoot = TestContext.CurrentContext.TestDirectory.Split("Umbraco.Tests.UnitTests")[0]; var pathToFiles = Path.Combine(sourceRoot, "Umbraco.Web.UI.NetCore"); - foreach(var pathSection in pathFromNetCore) + foreach (var pathSection in pathFromNetCore) { pathToFiles = Path.Combine(pathToFiles, pathSection); } @@ -42,35 +36,38 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common return new DirectoryInfo(pathToFiles).GetFiles().Select(f => f.Name).ToArray(); } - [Test, AutoMoqData] + [Test] + [AutoMoqData] public async Task InstallViewExists( [Frozen] IHostingEnvironment hostingEnvironment, InstallController sut) { Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute(It.IsAny())).Returns("http://localhost/"); var viewResult = await sut.Index() as ViewResult; - var fileName = getViewName(viewResult, Path.DirectorySeparatorChar.ToString()); + var fileName = GetViewName(viewResult, Path.DirectorySeparatorChar.ToString()); - var views = getUiFiles(new string[] { "Umbraco", "UmbracoInstall" }); + var views = GetUiFiles(new[] { "Umbraco", "UmbracoInstall" }); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } - [Test, AutoMoqData] - public void PrviewViewExists( + [Test] + [AutoMoqData] + public void PreviewViewExists( [Frozen] IGlobalSettings globalSettings, PreviewController sut) { Mock.Get(globalSettings).Setup(x => x.UmbracoPath).Returns("/"); var viewResult = sut.Index() as ViewResult; - var fileName = getViewName(viewResult); + var fileName = GetViewName(viewResult); - var views = getUiFiles(new string[] {"Umbraco", "UmbracoBackOffice" }); + var views = GetUiFiles(new[] { "Umbraco", "UmbracoBackOffice" }); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } - [Test, AutoMoqData] + [Test] + [AutoMoqData] public async Task BackOfficeDefaultExists( [Frozen] IGlobalSettings globalSettings, [Frozen] IHostingEnvironment hostingEnvironment, @@ -85,8 +82,8 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common sut.TempData = tempDataDictionary; var viewResult = await sut.Default() as ViewResult; - var fileName = getViewName(viewResult); - var views = getUiFiles(new string[] { "Umbraco", "UmbracoBackOffice" }); + var fileName = GetViewName(viewResult); + var views = GetUiFiles(new[] { "Umbraco", "UmbracoBackOffice" }); Assert.True(views.Contains(fileName), $"Expected {fileName} to exist, but it didn't"); } @@ -95,13 +92,12 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Web.Common [Test] public void LanguageFilesAreLowercase() { - - var files = getUiFiles(new string[] { "Umbraco", "config", "lang" }); + var files = GetUiFiles(new[] { "Umbraco", "config", "lang" }); foreach (var fileName in files) { - Assert.AreEqual(fileName.ToLower(), fileName, $"Language files must be all lowercase but {fileName} is not lowercase."); + Assert.AreEqual(fileName.ToLower(), fileName, + $"Language files must be all lowercase but {fileName} is not lowercase."); } - } } } From 7791fdcafa67cb2faf54f9605ead2b3a9ce433d6 Mon Sep 17 00:00:00 2001 From: Dirk Seefeld Date: Fri, 28 Aug 2020 16:07:21 +0200 Subject: [PATCH 10/13] ensure the the install api url ends with / to respect umbraco.installer.js method --- src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs b/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs index 66f219c266..31ff07b964 100644 --- a/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/LinkGeneratorExtensions.cs @@ -54,7 +54,7 @@ namespace Umbraco.Extensions /// public static string GetInstallerApiUrl(this LinkGenerator linkGenerator) { - return linkGenerator.GetPathByAction(nameof(InstallController.Index), ControllerExtensions.GetControllerName(), new { area = Constants.Web.Mvc.InstallArea }); + return linkGenerator.GetPathByAction(nameof(InstallController.Index), ControllerExtensions.GetControllerName(), new { area = Constants.Web.Mvc.InstallArea }).EnsureEndsWith('/'); } /// From cb88865a7df5fd0b1ab405841fcbc1d8020feea4 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 31 Aug 2020 15:23:43 +0200 Subject: [PATCH 11/13] Added iconApiBaseUrl to BareMinimumServerVariables --- src/Umbraco.Web/Editors/BackOfficeServerVariables.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 454338112c..bdcb93099b 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -73,7 +73,7 @@ namespace Umbraco.Web.Editors //this is the filter for the keys that we'll keep based on the full version of the server vars var keepOnlyKeys = new Dictionary { - {"umbracoUrls", new[] {"authenticationApiBaseUrl", "serverVarsJs", "externalLoginsUrl", "currentUserApiBaseUrl"}}, + {"umbracoUrls", new[] {"authenticationApiBaseUrl", "serverVarsJs", "externalLoginsUrl", "currentUserApiBaseUrl", "iconApiBaseUrl"}}, {"umbracoSettings", new[] {"allowPasswordReset", "imageFileTypes", "maxFileSize", "loginBackgroundImage", "canSendRequiredEmail", "usernameIsEmail"}}, {"application", new[] {"applicationPath", "cacheBuster"}}, {"isDebuggingEnabled", new string[] { }}, From 90d14158ee14d1bff3dfac4c831d8a47293040cf Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 2 Sep 2020 09:05:55 +0200 Subject: [PATCH 12/13] Clean up - Removed duplicate ctor in UmbracoVersion --- src/Umbraco.Core/Configuration/UmbracoVersion.cs | 8 -------- src/Umbraco.Tests.Common/TestHelperBase.cs | 2 +- src/Umbraco.Tests/Testing/UmbracoTestBase.cs | 2 +- .../Extensions/UmbracoCoreServiceCollectionExtensions.cs | 4 ++-- src/Umbraco.Web/UmbracoApplicationBase.cs | 2 +- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index 3ae59189fa..7d6d02f33e 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -10,14 +10,6 @@ namespace Umbraco.Core.Configuration /// public class UmbracoVersion : IUmbracoVersion { - private readonly GlobalSettings _globalSettings; - - public UmbracoVersion(GlobalSettings globalSettings) - : this() - { - _globalSettings = globalSettings; - } - public UmbracoVersion() { var umbracoCoreAssembly = typeof(SemVersion).Assembly; diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index 3e50cf2a53..df5f67a206 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -128,7 +128,7 @@ namespace Umbraco.Tests.Common return relativePath.Replace("~/", bin + "/"); } - public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(new GlobalSettingsBuilder().Build()); + public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(); public IRegister GetRegister() { diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index b8cab0d0f7..affce75c20 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -178,7 +178,7 @@ namespace Umbraco.Tests.Testing IBackOfficeInfo backOfficeInfo = new AspNetBackOfficeInfo(ConfigModelConversionsToLegacy.ConvertGlobalSettings(globalSettings), IOHelper, logger, settings); IIpResolver ipResolver = new AspNetIpResolver(); - UmbracoVersion = new UmbracoVersion(globalSettings); + UmbracoVersion = new UmbracoVersion(); LocalizedTextService = new LocalizedTextService(new Dictionary>(), logger); diff --git a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs index b514b4d918..1428048875 100644 --- a/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.Common/Extensions/UmbracoCoreServiceCollectionExtensions.cs @@ -126,7 +126,7 @@ namespace Umbraco.Extensions services.Configure(configuration.GetSection(Constants.Configuration.ConfigSecurityPrefix + "UserPassword")); services.Configure(configuration.GetSection(Constants.Configuration.ConfigPrefix + "WebRouting")); - // TODO: remove this once no longer requred in Umbraco.Web. + // TODO: remove this once no longer requred in Umbraco.Web. var configsFactory = new AspNetCoreConfigsFactory(configuration); var configs = configsFactory.Create(); services.AddSingleton(configs); @@ -238,7 +238,7 @@ namespace Umbraco.Extensions loggingConfiguration, out var logger, out var ioHelper, out var hostingEnvironment, out var backOfficeInfo, out var profiler); - var umbracoVersion = new UmbracoVersion(globalSettings); + var umbracoVersion = new UmbracoVersion(); var typeFinder = CreateTypeFinder(logger, profiler, webHostEnvironment, entryAssembly, typeFinderSettings); var configs = serviceProvider.GetService(); diff --git a/src/Umbraco.Web/UmbracoApplicationBase.cs b/src/Umbraco.Web/UmbracoApplicationBase.cs index 4f6f2c7f0f..8599464bd1 100644 --- a/src/Umbraco.Web/UmbracoApplicationBase.cs +++ b/src/Umbraco.Web/UmbracoApplicationBase.cs @@ -160,7 +160,7 @@ namespace Umbraco.Web var globalSettings = Umbraco.Composing.Current.Configs.Global(); - var umbracoVersion = new UmbracoVersion(ConfigModelConversionsFromLegacy.ConvertGlobalSettings(globalSettings)); + var umbracoVersion = new UmbracoVersion(); // create the register for the application, and boot // the boot manager is responsible for registrations From edca4af7f43eb586ba91810729569f7a9a3fcce7 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Wed, 2 Sep 2020 10:03:35 +0200 Subject: [PATCH 13/13] Fix MaxFailedAccessAttemptsBeforeLockout from config --- src/Umbraco.Web.UI.NetCore/appsettings.json | 110 ++++++++++---------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index ee67d0cf58..2044a8e696 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -1,60 +1,60 @@ { - "ConnectionStrings": { + "ConnectionStrings": { "umbracoDbDSN": "" - }, - "Umbraco": { - "CMS": { - "Content": { - "Notifications": { - "Email": "your@email.here" - }, - "MacroErrors": "throw" - }, - "Global": { - "DefaultUILanguage": "en-us", - "HideTopLevelNodeFromPath": true, - "Path": "~/umbraco", - "TimeOutInMinutes": 20, - "UseHttps": false - }, - "Hosting": { - "Debug": false - }, - "KeepAlive": { - "DisableKeepAliveTask": false, - "KeepAlivePingUrl": "{umbracoApplicationUrl}/api/keepalive/ping" - }, - "RequestHandler": { - "ConvertUrlsToAscii": "try" - }, - "RuntimeMinification": { - "dataFolder": "App_Data\\Smidge", - "version": "1" - }, - "Security": { - "KeepUserLoggedIn": false, - "UsernameIsEmail": true, - "HideDisabledUsersInBackoffice": false, - "UserPassword": { - "RequiredLength": 10, - "RequireNonLetterOrDigit": false, - "RequireDigit": false, - "RequireLowercase": false, - "RequireUppercase": false, - "MaxFailedAccessAttemptsBeforeLockout": 0 - }, - "MemberPassword": { - "RequiredLength": 10, - "RequireNonLetterOrDigit": false, - "RequireDigit": false, - "RequireLowercase": false, - "RequireUppercase": false, - "MaxFailedAccessAttemptsBeforeLockout": 0 - } - }, - "Tours": { - "EnableTours": true - } + }, + "Umbraco": { + "CMS": { + "Content": { + "Notifications": { + "Email": "your@email.here" + }, + "MacroErrors": "throw" + }, + "Global": { + "DefaultUILanguage": "en-us", + "HideTopLevelNodeFromPath": true, + "Path": "~/umbraco", + "TimeOutInMinutes": 20, + "UseHttps": false + }, + "Hosting": { + "Debug": false + }, + "KeepAlive": { + "DisableKeepAliveTask": false, + "KeepAlivePingUrl": "{umbracoApplicationUrl}/api/keepalive/ping" + }, + "RequestHandler": { + "ConvertUrlsToAscii": "try" + }, + "RuntimeMinification": { + "dataFolder": "App_Data\\Smidge", + "version": "1" + }, + "Security": { + "KeepUserLoggedIn": false, + "UsernameIsEmail": true, + "HideDisabledUsersInBackoffice": false, + "UserPassword": { + "RequiredLength": 10, + "RequireNonLetterOrDigit": false, + "RequireDigit": false, + "RequireLowercase": false, + "RequireUppercase": false, + "MaxFailedAccessAttemptsBeforeLockout": 5 + }, + "MemberPassword": { + "RequiredLength": 10, + "RequireNonLetterOrDigit": false, + "RequireDigit": false, + "RequireLowercase": false, + "RequireUppercase": false, + "MaxFailedAccessAttemptsBeforeLockout": 5 } + }, + "Tours": { + "EnableTours": true + } } + } }