From fd09cca1bcd33ee6c9abea1885136ac5b5aecd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Mihula?= Date: Sat, 23 Nov 2024 00:38:48 +0100 Subject: [PATCH] Github action is set to test on ubuntu - given test is windows only --- test/BasicTests.cs | 11 ++++++ test/{BasicTest.cs => CVETests.cs} | 49 +++++++++++++++--------- test/ProDotNetZipNetStandardTest.csproj | 2 +- test/Usings.cs | 2 + test/zips/zip-slip-win.zip | Bin 0 -> 547 bytes test/zips/zip-slip.zip | Bin 0 -> 545 bytes 6 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 test/BasicTests.cs rename test/{BasicTest.cs => CVETests.cs} (54%) create mode 100644 test/Usings.cs create mode 100644 test/zips/zip-slip-win.zip create mode 100644 test/zips/zip-slip.zip diff --git a/test/BasicTests.cs b/test/BasicTests.cs new file mode 100644 index 0000000..47f15b7 --- /dev/null +++ b/test/BasicTests.cs @@ -0,0 +1,11 @@ +namespace Ionic.Zip.Tests; + +public class BasicTests +{ + [Fact] + public void TestCreate() + { + var result = new ZipFile(); + Assert.NotNull(result); + } +} \ No newline at end of file diff --git a/test/BasicTest.cs b/test/CVETests.cs similarity index 54% rename from test/BasicTest.cs rename to test/CVETests.cs index b09219b..9432e93 100644 --- a/test/BasicTest.cs +++ b/test/CVETests.cs @@ -1,30 +1,17 @@ -using Xunit; -using Xunit.Abstractions; +using System.Runtime.InteropServices; namespace Ionic.Zip.Tests; -public class BasicTest +public class CVETests { private readonly ITestOutputHelper _output; - - public BasicTest(ITestOutputHelper output) + + public CVETests(ITestOutputHelper output) { _output = output; } - - [Fact] - public void TestCreate() - { - var result = new ZipFile(); - Assert.NotNull(result); - } - [Fact] - public void Extract_ZipWithAbsolutePathsOutside() - { - Assert.Throws(() => Extract_ZipFile("absolute-path-traversal.zip")); - Assert.False(File.Exists(@"C:\Windows\Temp\foo")); - } + private bool IsOsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private void Extract_ZipFile(string fileName) { @@ -36,6 +23,10 @@ private void Extract_ZipFile(string fileName) _output.WriteLine("Reading zip file: '{0}'", fqFileName); using var zip = ZipFile.Read(fqFileName); const string extractDir = "extract"; + if (Directory.Exists(extractDir)) + { + Directory.Delete(extractDir, true); + } foreach (ZipEntry e in zip) { _output.WriteLine("{1,-22} {2,9} {3,5:F0}% {4,9} {5,3} {6:X8} {0}", @@ -49,4 +40,26 @@ private void Extract_ZipFile(string fileName) e.Extract(extractDir); } } + + [Fact] + public void Extract_ZipWithAbsolutePathsOutside() + { + if (IsOsWindows) + { + Assert.Throws(() => Extract_ZipFile("absolute-path-traversal.zip")); + } + else + { + Extract_ZipFile("absolute-path-traversal.zip"); + Assert.False(File.Exists(@"C:\Windows\Temp\foo")); + Assert.True(File.Exists(@"./extract/C:/Windows/Temp/foo")); + } + } + + //[Fact] + //public void Extract_ZipWithZipSlip() + //{ + // var zipFile = IsOsWindows ? "zip-slip-win.zip" : "zip-slip.zip"; + // Assert.Throws(() => Extract_ZipFile(zipFile)); + //} } \ No newline at end of file diff --git a/test/ProDotNetZipNetStandardTest.csproj b/test/ProDotNetZipNetStandardTest.csproj index a84da7c..80b71d9 100644 --- a/test/ProDotNetZipNetStandardTest.csproj +++ b/test/ProDotNetZipNetStandardTest.csproj @@ -27,7 +27,7 @@ - + Always diff --git a/test/Usings.cs b/test/Usings.cs new file mode 100644 index 0000000..8970211 --- /dev/null +++ b/test/Usings.cs @@ -0,0 +1,2 @@ +global using Xunit; +global using Xunit.Abstractions; diff --git a/test/zips/zip-slip-win.zip b/test/zips/zip-slip-win.zip new file mode 100644 index 0000000000000000000000000000000000000000..3474c88bec74e6381fb9e1e598f98076c64f2d68 GIT binary patch literal 547 zcmWIWW@h1H0D=Au{XYEp{-1?`Y!K#PkYPyA&ri`SsVE5z;bdU8U359BLG@ZxX$3a} zBg;2N1_l-ppt_Qb%wh!~N>l);R>;pw*3=BYDGc0KYu@GUy3JDvua0&2cWD;S< n9Sk5dKwwE@D3BbG5CK|>5-0)QtZX1BF##bX(5E~g-!cFIhBtZG literal 0 HcmV?d00001 diff --git a/test/zips/zip-slip.zip b/test/zips/zip-slip.zip new file mode 100644 index 0000000000000000000000000000000000000000..38b3f499de0163e62ca15ce18350a9d9a477a51b GIT binary patch literal 545 zcmWIWW@h1H0D=Au{XYEp{-1?`Y!K#PkYPyA&ri`SsVE5z;bdU8U359h4v0%DxEUB( zzA-W|u!sQFm1JZVD*#cV0!Xz&eqJh90MJm76a&LlprHwl)s`S02)6*So}T`Ippx7I z{nWC|9FT|Lj?Pm62|-=W$Rx*%D=;L0E@xl>dYWNLBZ!3v8dgZqpan~SHzSh>Gwx6T jnE?Vz8bg8PfCLE8QsgiR@MdKLxrhk}K_2A>d6oeH^pk5C literal 0 HcmV?d00001