public async Task RejectsOffsetOutOfBounds() { // Assert using (var stream = TestUtility.BufferTestData(@"System.IO.Compression\badzipfiles\localFileOffsetOutOfBounds.zip")) { var reader = new ZipDirectoryReader(stream); var directory = await reader.ReadAsync(); var entry = directory.Entries[0]; // Act & Assert await Assert.ThrowsAsync <EndOfStreamException>( () => reader.ReadLocalFileHeaderAsync(directory, entry)); } }
public async Task RejectsEncryptedFiles() { // Arrange using (var stream = TestUtility.BufferTestData(@"SharpZipLib\FastZipHandling.Encryption\0.zip")) { var reader = new ZipDirectoryReader(stream); var directory = await reader.ReadAsync(); var entry = directory.Entries[0]; // Act & Assert var ex = await Assert.ThrowsAsync <MiniZipException>( () => reader.ReadLocalFileHeaderAsync(directory, entry)); Assert.Equal("Archives containing encrypted files are not supported.", ex.Message); } }
public async Task RejectsInvalidLocalFileHeaderSignature() { // Assert using (var stream = TestUtility.BufferTestData(@"System.IO.Compression\badzipfiles\localFileHeaderSignatureWrong.zip")) { var reader = new ZipDirectoryReader(stream); var directory = await reader.ReadAsync(); var entry = directory.Entries[0]; // Act & Assert var ex = await Assert.ThrowsAsync <MiniZipException>( () => reader.ReadLocalFileHeaderAsync(directory, entry)); Assert.Equal("Invalid local file header signature found.", ex.Message); } }
public async Task ReadsLocalHeaderOfAllFiles(string resourceName) { // Arrange using (var stream = TestUtility.BufferTestData(resourceName)) { var reader = new ZipDirectoryReader(stream); var directory = await reader.ReadAsync(); // Act foreach (var entry in directory.Entries) { var localFileHeader = await reader.ReadLocalFileHeaderAsync(directory, entry); // Assert Assert.NotNull(localFileHeader); } } }
public async Task ReadsDataDescriptorWithoutSignature(string resourceName) { // Arrange using (var stream = TestUtility.BufferTestData(resourceName)) { var reader = new ZipDirectoryReader(stream); var directory = await reader.ReadAsync(); var entry = directory.Entries[0]; // Act var localFileHeader = await reader.ReadLocalFileHeaderAsync(directory, entry); // Assert Assert.NotNull(localFileHeader.DataDescriptor); Assert.False(localFileHeader.DataDescriptor.HasSignature); Assert.Equal(entry.Crc32, localFileHeader.DataDescriptor.Crc32); Assert.Equal(entry.CompressedSize, localFileHeader.DataDescriptor.CompressedSize); Assert.Equal(entry.UncompressedSize, localFileHeader.DataDescriptor.UncompressedSize); } }