Merge commit from fork
This commit is contained in:
@@ -14,8 +14,8 @@ public static class ContentSettingsExtensions
|
||||
/// <c>true</c> if the file extension is allowed for upload; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public static bool IsFileAllowedForUpload(this ContentSettings contentSettings, string extension)
|
||||
=> contentSettings.AllowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension)) ||
|
||||
(contentSettings.AllowedUploadedFileExtensions.Any() == false && contentSettings.DisallowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension)) == false);
|
||||
=> contentSettings.AllowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension.Trim())) ||
|
||||
(contentSettings.AllowedUploadedFileExtensions.Any() == false && contentSettings.DisallowedUploadedFileExtensions.Any(x => x.InvariantEquals(extension.Trim())) == false);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the auto-fill configuration for a specified property alias.
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration;
|
||||
|
||||
[TestFixture]
|
||||
public class ContentSettingsExtensionsTests
|
||||
{
|
||||
[TestCase("jpg")]
|
||||
[TestCase("JPG")]
|
||||
[TestCase("jpg ")]
|
||||
public void IsFileAllowedForUpload_Allows_File_In_Allow_List(string extension)
|
||||
{
|
||||
var contentSettings = new ContentSettings
|
||||
{
|
||||
AllowedUploadedFileExtensions = new[] { "jpg", "png" }.ToHashSet(),
|
||||
};
|
||||
|
||||
Assert.IsTrue(contentSettings.IsFileAllowedForUpload(extension));
|
||||
}
|
||||
|
||||
[TestCase("gif")]
|
||||
[TestCase("GIF")]
|
||||
[TestCase("gif ")]
|
||||
public void IsFileAllowedForUpload_Rejects_File_Not_In_Allow_List(string extension)
|
||||
{
|
||||
var contentSettings = new ContentSettings
|
||||
{
|
||||
AllowedUploadedFileExtensions = new[] { "jpg", "png" }.ToHashSet(),
|
||||
};
|
||||
|
||||
Assert.IsFalse(contentSettings.IsFileAllowedForUpload(extension));
|
||||
}
|
||||
|
||||
[TestCase("jpg")]
|
||||
[TestCase("JPG")]
|
||||
[TestCase("jpg ")]
|
||||
public void IsFileAllowedForUpload_Allows_File_Not_In_Disallow_List(string extension)
|
||||
{
|
||||
var contentSettings = new ContentSettings
|
||||
{
|
||||
DisallowedUploadedFileExtensions = new[] { "gif", "png" }.ToHashSet(),
|
||||
};
|
||||
|
||||
Assert.IsTrue(contentSettings.IsFileAllowedForUpload(extension));
|
||||
}
|
||||
|
||||
[TestCase("gif")]
|
||||
[TestCase("GIF")]
|
||||
[TestCase("gif ")]
|
||||
public void IsFileAllowedForUpload_Rejects_File_In_Disallow_List(string extension)
|
||||
{
|
||||
var contentSettings = new ContentSettings
|
||||
{
|
||||
DisallowedUploadedFileExtensions = new[] { "gif", "png" }.ToHashSet(),
|
||||
};
|
||||
|
||||
Assert.IsFalse(contentSettings.IsFileAllowedForUpload(extension));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsFileAllowedForUpload_Allows_File_In_Allow_List_Even_If_Also_In_Disallow_List()
|
||||
{
|
||||
var contentSettings = new ContentSettings
|
||||
{
|
||||
AllowedUploadedFileExtensions = new[] { "jpg", "png" }.ToHashSet(),
|
||||
DisallowedUploadedFileExtensions = new[] { "jpg", }.ToHashSet(),
|
||||
};
|
||||
|
||||
Assert.IsTrue(contentSettings.IsFileAllowedForUpload("jpg"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user