Merge pull request #6599 from ronaldbarendse/v8/bugfix/5947-custom-exceptions

Fixed and cleaned up custom exception classes
This commit is contained in:
Shannon Deminick
2019-11-21 19:21:19 +11:00
committed by GitHub
77 changed files with 1442 additions and 594 deletions

View File

@@ -101,7 +101,7 @@ namespace Umbraco.Tests.IO
Assert.AreEqual(Path.Combine(basePath, @"foo\bar.tmp"), path);
// that path is invalid as it would be outside the root directory
Assert.Throws<FileSecurityException>(() => _fileSystem.GetFullPath("../../foo.tmp"));
Assert.Throws<UnauthorizedAccessException>(() => _fileSystem.GetFullPath("../../foo.tmp"));
// a very long path, which ends up being very long, works
path = Repeat("bah/bah/", 50);

View File

@@ -238,7 +238,7 @@ namespace Umbraco.Tests.IO
var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore");
var ss = new ShadowFileSystem(fs, sfs);
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
ss.AddFile("../../f1.txt", ms);

View File

@@ -7,6 +7,7 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using System;
namespace Umbraco.Tests.Persistence.Repositories
{
@@ -77,7 +78,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.AreEqual("/Views/Partials/path-2/test-path-3.cshtml", partialView.VirtualPath);
partialView = new PartialView(PartialViewType.PartialView, "\\test-path-4.cshtml") { Content = "// partialView" };
Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
Assert.Throws<UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
{
repository.Save(partialView);
});
@@ -86,11 +87,11 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.IsNull(partialView);
// fixed in 7.3 - 7.2.8 used to...
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
partialView = (PartialView) repository.Get("\\test-path-4.cshtml"); // outside the filesystem, does not exist
});
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
partialView = (PartialView) repository.Get("../../packages.config"); // outside the filesystem, exists
});

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Text;
using Moq;
@@ -301,7 +302,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath);
script = new Script("\\test-path-4.js") { Content = "// script" };
Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
Assert.Throws<UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
{
repository.Save(script);
});
@@ -310,11 +311,11 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.IsNull(script);
// fixed in 7.3 - 7.2.8 used to...
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
script = repository.Get("\\test-path-4.js"); // outside the filesystem, does not exist
});
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
script = repository.Get("../packages.config"); // outside the filesystem, exists
});

View File

@@ -1,4 +1,5 @@
using System.Data;
using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
@@ -284,7 +285,7 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.AreEqual("/css/path-2/test-path-3.css", stylesheet.VirtualPath);
stylesheet = new Stylesheet("\\test-path-4.css") { Content = "body { color:#000; } .bold {font-weight:bold;}" };
Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
Assert.Throws<UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \
{
repository.Save(stylesheet);
});
@@ -294,11 +295,11 @@ namespace Umbraco.Tests.Persistence.Repositories
Assert.IsNull(stylesheet);
// fixed in 7.3 - 7.2.8 used to...
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
stylesheet = repository.Get("\\test-path-4.css"); // outside the filesystem, does not exist
});
Assert.Throws<FileSecurityException>(() =>
Assert.Throws<UnauthorizedAccessException>(() =>
{
stylesheet = repository.Get("../packages.config"); // outside the filesystem, exists
});

View File

@@ -264,7 +264,7 @@ namespace Umbraco.Tests.Published
public override bool HasValue(string culture = null, string segment = null) => _hasValue;
public override object GetSourceValue(string culture = null, string segment = null) => _sourceValue;
public override object GetValue(string culture = null, string segment = null) => PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview);
public override object GetXPathValue(string culture = null, string segment = null) => throw new WontImplementException();
public override object GetXPathValue(string culture = null, string segment = null) => throw new InvalidOperationException("This method won't be implemented.");
}
}
}

View File

@@ -865,7 +865,7 @@ namespace Umbraco.Tests.Services
var userService = ServiceContext.UserService;
// Act & Assert
Assert.Throws<ArgumentNullOrEmptyException>(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io"));
Assert.Throws<ArgumentException>(() => userService.CreateUserWithIdentity(string.Empty, "john@umbraco.io"));
}
[Test]