diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/zip.rs | 81 |
1 files changed, 52 insertions, 29 deletions
diff --git a/tests/zip.rs b/tests/zip.rs index 1422bb3..e00789d 100644 --- a/tests/zip.rs +++ b/tests/zip.rs | |||
| @@ -90,11 +90,17 @@ fn test_zip_weak() { | |||
| 90 | } | 90 | } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | const EMPTY: Cursor<&[u8]> = Cursor::new(b"PK\x05\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); | ||
| 94 | |||
| 95 | #[test] | 93 | #[test] |
| 96 | fn test_zip() { | 94 | fn test_zip() { |
| 97 | assert_eq!(Archive::<Zip<_>>::read(EMPTY).unwrap().len(), 0); | 95 | assert_eq!( |
| 96 | Archive::<Zip<_>>::read(Cursor::new(&[ | ||
| 97 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 98 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 99 | ])) | ||
| 100 | .unwrap() | ||
| 101 | .len(), | ||
| 102 | 0 | ||
| 103 | ); | ||
| 98 | 104 | ||
| 99 | let mut archive = Archive::<Zip>::read_from_file("tests/files/archive.zip").unwrap(); | 105 | let mut archive = Archive::<Zip>::read_from_file("tests/files/archive.zip").unwrap(); |
| 100 | 106 | ||
| @@ -158,32 +164,49 @@ fn test_zip() { | |||
| 158 | } | 164 | } |
| 159 | } | 165 | } |
| 160 | 166 | ||
| 161 | const NOT_FOUND: Cursor<&[u8]> = Cursor::new(b""); | ||
| 162 | const INVALID: Cursor<&[u8]> = Cursor::new( | ||
| 163 | b"PK\x06\x07\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PK\x05\x06\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0", | ||
| 164 | ); | ||
| 165 | const OVERLAP: Cursor<&[u8]> = Cursor::new(b"PK\x05\x06\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0"); | ||
| 166 | const OVERLAP64: Cursor<&[u8]> = Cursor::new(b"PK\x06\x06\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PK\x06\x07\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0PK\x05\x06\0\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0"); | ||
| 167 | |||
| 168 | #[test] | 167 | #[test] |
| 169 | fn test_bad_zip() { | 168 | fn test_bad_zip() { |
| 170 | assert!( | 169 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[])) |
| 171 | Archive::<Zip<_>>::read(NOT_FOUND).is_err_and(|e| e == ZipError::StructNotFound("Eocdr")) | 170 | .is_err_and(|e| e == ZipError::StructNotFound("Eocdr"))); |
| 172 | ); | 171 | |
| 173 | 172 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ | |
| 174 | assert!( | 173 | // No Eocdr64 |
| 175 | Archive::<Zip<_>>::read(INVALID).is_err_and(|e| e == ZipError::InvalidSignature("Eocdr64")) | 174 | 0x50, 0x4b, 0x06, 0x07, 0, 0, 0, 0, // |
| 176 | ); | 175 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64Locator |
| 177 | 176 | // | |
| 178 | assert!(Archive::<Zip<_>>::read(OVERLAP).is_err_and(|e| e | 177 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // |
| 179 | == ZipError::Overlapping( | 178 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr |
| 180 | "Central directory records", | 179 | ])) |
| 181 | "End of central directory record" | 180 | .is_err_and(|e| e == ZipError::InvalidSignature("Eocdr64"))); |
| 182 | ))); | 181 | |
| 183 | 182 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ | |
| 184 | assert!(Archive::<Zip<_>>::read(OVERLAP64).is_err_and(|e| e | 183 | 0x50, 0x4b, 0x06, 0x06, // Eocdr64 |
| 185 | == ZipError::Overlapping( | 184 | // |
| 186 | "Central directory records", | 185 | 0x50, 0x4b, 0x06, 0x07, 0, 0, 0, 0, // |
| 187 | "Zip64 end of central directory record" | 186 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64Locator |
| 188 | ))); | 187 | // |
| 188 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 189 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 190 | ])) | ||
| 191 | .is_err_and(|e| e == ZipError::Overlapping("Eocdr64", "Eocdr64Locator"))); | ||
| 192 | |||
| 193 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ | ||
| 194 | // No records | ||
| 195 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 196 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 197 | ])) | ||
| 198 | .is_err_and(|e| e == ZipError::Overlapping("Cdr", "Eocdr"))); | ||
| 199 | |||
| 200 | assert!(Archive::<Zip<_>>::read(Cursor::new(&[ | ||
| 201 | 0x50, 0x4b, 0x06, 0x06, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // | ||
| 202 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // | ||
| 203 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64 | ||
| 204 | // | ||
| 205 | 0x50, 0x4b, 0x06, 0x07, 0, 0, 0, 0, // | ||
| 206 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr64Locator | ||
| 207 | // | ||
| 208 | 0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0, 0, // | ||
| 209 | 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Eocdr | ||
| 210 | ])) | ||
| 211 | .is_err_and(|e| e == ZipError::Overlapping("Cdr", "Eocdr64"))); | ||
| 189 | } | 212 | } |
