|
| 1 | +// Copyright (c) Umbraco. |
| 2 | +// See LICENSE for more details. |
| 3 | + |
| 4 | +using NUnit.Framework; |
| 5 | +using Umbraco.Cms.Core.Configuration.Models; |
| 6 | +using Umbraco.Extensions; |
| 7 | + |
| 8 | +namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Configuration; |
| 9 | + |
| 10 | +[TestFixture] |
| 11 | +public class ContentSettingsExtensionsTests |
| 12 | +{ |
| 13 | + [TestCase("jpg")] |
| 14 | + [TestCase("JPG")] |
| 15 | + [TestCase("jpg ")] |
| 16 | + public void IsFileAllowedForUpload_Allows_File_In_Allow_List(string extension) |
| 17 | + { |
| 18 | + var contentSettings = new ContentSettings |
| 19 | + { |
| 20 | + AllowedUploadedFileExtensions = ["jpg", "png"], |
| 21 | + }; |
| 22 | + |
| 23 | + Assert.IsTrue(contentSettings.IsFileAllowedForUpload(extension)); |
| 24 | + } |
| 25 | + |
| 26 | + [TestCase("gif")] |
| 27 | + [TestCase("GIF")] |
| 28 | + [TestCase("gif ")] |
| 29 | + public void IsFileAllowedForUpload_Rejects_File_Not_In_Allow_List(string extension) |
| 30 | + { |
| 31 | + var contentSettings = new ContentSettings |
| 32 | + { |
| 33 | + AllowedUploadedFileExtensions = ["jpg", "png"], |
| 34 | + }; |
| 35 | + |
| 36 | + Assert.IsFalse(contentSettings.IsFileAllowedForUpload(extension)); |
| 37 | + } |
| 38 | + |
| 39 | + [TestCase("jpg")] |
| 40 | + [TestCase("JPG")] |
| 41 | + [TestCase("jpg ")] |
| 42 | + public void IsFileAllowedForUpload_Allows_File_Not_In_Disallow_List(string extension) |
| 43 | + { |
| 44 | + var contentSettings = new ContentSettings |
| 45 | + { |
| 46 | + DisallowedUploadedFileExtensions = ["gif", "png"], |
| 47 | + }; |
| 48 | + |
| 49 | + Assert.IsTrue(contentSettings.IsFileAllowedForUpload(extension)); |
| 50 | + } |
| 51 | + |
| 52 | + [TestCase("gif")] |
| 53 | + [TestCase("GIF")] |
| 54 | + [TestCase("gif ")] |
| 55 | + public void IsFileAllowedForUpload_Rejects_File_In_Disallow_List(string extension) |
| 56 | + { |
| 57 | + var contentSettings = new ContentSettings |
| 58 | + { |
| 59 | + DisallowedUploadedFileExtensions = ["gif", "png"], |
| 60 | + }; |
| 61 | + |
| 62 | + Assert.IsFalse(contentSettings.IsFileAllowedForUpload(extension)); |
| 63 | + } |
| 64 | + |
| 65 | + [Test] |
| 66 | + public void IsFileAllowedForUpload_Allows_File_In_Allow_List_Even_If_Also_In_Disallow_List() |
| 67 | + { |
| 68 | + var contentSettings = new ContentSettings |
| 69 | + { |
| 70 | + AllowedUploadedFileExtensions = ["jpg", "png"], |
| 71 | + DisallowedUploadedFileExtensions = ["jpg"], |
| 72 | + }; |
| 73 | + |
| 74 | + Assert.IsTrue(contentSettings.IsFileAllowedForUpload("jpg")); |
| 75 | + } |
| 76 | +} |
0 commit comments