Skip to content

Commit

Permalink
Github action is set to test on ubuntu - given test is windows only
Browse files Browse the repository at this point in the history
  • Loading branch information
René Mihula committed Nov 22, 2024
1 parent dd726f2 commit fd09cca
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
11 changes: 11 additions & 0 deletions test/BasicTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Ionic.Zip.Tests;

public class BasicTests
{
[Fact]
public void TestCreate()
{
var result = new ZipFile();
Assert.NotNull(result);
}
}
49 changes: 31 additions & 18 deletions test/BasicTest.cs → test/CVETests.cs
Original file line number Diff line number Diff line change
@@ -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<IOException>(() => 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)
{
Expand All @@ -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}",
Expand All @@ -49,4 +40,26 @@ private void Extract_ZipFile(string fileName)
e.Extract(extractDir);
}
}

[Fact]
public void Extract_ZipWithAbsolutePathsOutside()
{
if (IsOsWindows)
{
Assert.Throws<IOException>(() => 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<IOException>(() => Extract_ZipFile(zipFile));
//}
}
2 changes: 1 addition & 1 deletion test/ProDotNetZipNetStandardTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ItemGroup>

<ItemGroup>
<None Update="zips\absolute-path-traversal.zip">
<None Update="zips\*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions test/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using Xunit;
global using Xunit.Abstractions;
Binary file added test/zips/zip-slip-win.zip
Binary file not shown.
Binary file added test/zips/zip-slip.zip
Binary file not shown.

0 comments on commit fd09cca

Please sign in to comment.