public void TestRejectParentDirectoryEntry() { var builder = new PackageBuilder(); builder.AddFolder(".."); using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip"))) { builder.GeneratePackageArchive(archiveStream); archiveStream.Seek(0, SeekOrigin.Begin); using (var extractor = new ZipExtractor(archiveStream, _sandbox)) extractor.Invoking(x => x.Run()).ShouldThrow <IOException>(because: "ZipExtractor must not accept archives with '..' as entry"); } }
public void TestExtractEmptyFile() { var builder = new PackageBuilder() .AddFile("emptyFile", new byte[] {}); using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip"))) { builder.GeneratePackageArchive(archiveStream); archiveStream.Seek(0, SeekOrigin.Begin); const string message = "ZipExtractor should correctly extract empty files in an archive"; using (var extractor = new ZipExtractor(archiveStream, _sandbox)) extractor.Invoking(x => x.Run()).ShouldNotThrow(); File.Exists(Path.Combine(_sandbox, "emptyFile")).Should().BeTrue(because: message); File.ReadAllBytes(Path.Combine(_sandbox, "emptyFile")).Should().BeEmpty(because: message); } }
public void TestExtractToCustomDestination() { var builder = new PackageBuilder() .AddFile("emptyFile", new byte[] {}); using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip"))) { builder.GeneratePackageArchive(archiveStream); archiveStream.Seek(0, SeekOrigin.Begin); const string message = "ZipExtractor should correctly extract empty files in an archive to custom destination"; using (var extractor = new ZipExtractor(archiveStream, _sandbox) {Destination = "custom"}) extractor.Invoking(x => x.Run()).ShouldNotThrow(); File.Exists(Path.Combine(_sandbox, "custom", "emptyFile")).Should().BeTrue(because: message); File.ReadAllBytes(Path.Combine(_sandbox, "custom", "emptyFile")).Should().BeEmpty(because: message); } }
public void TestRejectParentDirectoryEntry() { var builder = new PackageBuilder(); builder.AddFolder(".."); using (var archiveStream = File.Create(Path.Combine(_sandbox, "ar.zip"))) { builder.GeneratePackageArchive(archiveStream); archiveStream.Seek(0, SeekOrigin.Begin); using (var extractor = new ZipExtractor(archiveStream, _sandbox)) extractor.Invoking(x => x.Run()).ShouldThrow<IOException>(because: "ZipExtractor must not accept archives with '..' as entry"); } }