public static async Task UnsupportedCompression() { //lzma compression method await UnsupportedCompressionRoutine(ZipTest.bad("LZMA.zip"), true); await UnsupportedCompressionRoutine(ZipTest.bad("invalidDeflate.zip"), false); }
public static async Task ZipArchive_InvalidEntryTable(String zipname) { string filename = ZipTest.bad(zipname); using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(filename), ZipArchiveMode.Read)) Assert.Throws <InvalidDataException>(() => archive.Entries[0]); }
public static async Task ZipArchive_InvalidStream(String zipname) { string filename = ZipTest.bad(zipname); using (var stream = await StreamHelpers.CreateTempCopyStream(filename)) Assert.Throws <InvalidDataException>(() => new ZipArchive(stream, ZipArchiveMode.Read)); }
public static async Task ZipArchiveEntry_InvalidUpdate(String zipname) { string filename = ZipTest.bad(zipname); Stream updatedCopy = await StreamHelpers.CreateTempCopyStream(filename); String name; Int64 length, compressedLength; DateTimeOffset lastWriteTime; using (ZipArchive archive = new ZipArchive(updatedCopy, ZipArchiveMode.Update, true)) { ZipArchiveEntry e = archive.Entries[0]; name = e.FullName; lastWriteTime = e.LastWriteTime; length = e.Length; compressedLength = e.CompressedLength; Assert.Throws <InvalidDataException>(() => e.Open()); //"Should throw on open" } //make sure that update mode preserves that unreadable file using (ZipArchive archive = new ZipArchive(updatedCopy, ZipArchiveMode.Update)) { ZipArchiveEntry e = archive.Entries[0]; Assert.Equal(name, e.FullName); //"Name isn't the same" Assert.Equal(lastWriteTime, e.LastWriteTime); //"LastWriteTime not the same" Assert.Equal(length, e.Length); //"Length isn't the same" Assert.Equal(compressedLength, e.CompressedLength); //"CompressedLength isn't the same" Assert.Throws <InvalidDataException>(() => e.Open()); //"Should throw on open" } }
public static async Task ZipArchiveEntry_InvalidLastWriteTime_Read() { using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream( ZipTest.bad("invaliddate.zip")), ZipArchiveMode.Read)) { Assert.Equal(new DateTime(1980, 1, 1, 0, 0, 0), archive.Entries[0].LastWriteTime.DateTime); //"Date isn't correct on invalid date" } }
public static async Task UnsupportedCompressionRoutine(String zipname, Boolean throwsOnOpen) { // using (ZipArchive archive = ZipFile.OpenRead(filename)) string filename = ZipTest.bad(zipname); using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(filename), ZipArchiveMode.Read)) { ZipArchiveEntry e = archive.Entries[0]; if (throwsOnOpen) { Assert.Throws <InvalidDataException>(() => e.Open()); //"should throw on open" } else { using (Stream s = e.Open()) { Assert.Throws <InvalidDataException>(() => s.ReadByte()); //"Unreadable stream" } } } Stream updatedCopy = await StreamHelpers.CreateTempCopyStream(filename); String name; Int64 length, compressedLength; DateTimeOffset lastWriteTime; using (ZipArchive archive = new ZipArchive(updatedCopy, ZipArchiveMode.Update, true)) { ZipArchiveEntry e = archive.Entries[0]; name = e.FullName; lastWriteTime = e.LastWriteTime; length = e.Length; compressedLength = e.CompressedLength; Assert.Throws <InvalidDataException>(() => e.Open()); //"Should throw on open" } //make sure that update mode preserves that unreadable file using (ZipArchive archive = new ZipArchive(updatedCopy, ZipArchiveMode.Update)) { ZipArchiveEntry e = archive.Entries[0]; Assert.Equal(name, e.FullName); //"Name isn't the same" Assert.Equal(lastWriteTime, e.LastWriteTime); //"LastWriteTime not the same" Assert.Equal(length, e.Length); //"Length isn't the same" Assert.Equal(compressedLength, e.CompressedLength); //"CompressedLength isn't the same" Assert.Throws <InvalidDataException>(() => e.Open()); //"Should throw on open" } }
public static async Task InvalidDates() { using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream( ZipTest.bad("invaliddate.zip")), ZipArchiveMode.Read)) { Assert.Equal(new DateTime(1980, 1, 1, 0, 0, 0), archive.Entries[0].LastWriteTime.DateTime); //"Date isn't correct on invalid date" } using (ZipArchive archive = new ZipArchive(new MemoryStream(), ZipArchiveMode.Create)) { ZipArchiveEntry entry = archive.CreateEntry("test"); Assert.Throws <ArgumentOutOfRangeException>(() => { entry.LastWriteTime = new DateTimeOffset(1979, 12, 3, 5, 6, 2, new TimeSpan()); }); //"should throw on bad date" Assert.Throws <ArgumentOutOfRangeException>(() => { entry.LastWriteTime = new DateTimeOffset(2980, 12, 3, 5, 6, 2, new TimeSpan()); }); //"Should throw on bad date" } }
public static async Task ZipArchive_InvalidEntry(String zipname, Boolean throwsOnOpen) { string filename = ZipTest.bad(zipname); using (ZipArchive archive = new ZipArchive(await StreamHelpers.CreateTempCopyStream(filename), ZipArchiveMode.Read)) { ZipArchiveEntry e = archive.Entries[0]; if (throwsOnOpen) { Assert.Throws <InvalidDataException>(() => e.Open()); //"should throw on open" } else { using (Stream s = e.Open()) { Assert.Throws <InvalidDataException>(() => s.ReadByte()); //"Unreadable stream" } } } }