aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/files/archive_aes.zipbin0 -> 3898 bytes
-rw-r--r--tests/files/archive_weak.zip (renamed from tests/files/archive_passwd.zip)bin1059 -> 1059 bytes
-rw-r--r--tests/zip.rs67
3 files changed, 62 insertions, 5 deletions
diff --git a/tests/files/archive_aes.zip b/tests/files/archive_aes.zip
new file mode 100644
index 0000000..a64415b
--- /dev/null
+++ b/tests/files/archive_aes.zip
Binary files differ
diff --git a/tests/files/archive_passwd.zip b/tests/files/archive_weak.zip
index 291bd12..291bd12 100644
--- a/tests/files/archive_passwd.zip
+++ b/tests/files/archive_weak.zip
Binary files differ
diff --git a/tests/zip.rs b/tests/zip.rs
index 2c8fc56..9283df3 100644
--- a/tests/zip.rs
+++ b/tests/zip.rs
@@ -3,8 +3,60 @@ use archivator::{Archive, Zip};
3use std::io::{Read, Seek, SeekFrom}; 3use std::io::{Read, Seek, SeekFrom};
4 4
5#[test] 5#[test]
6fn test_zip_passwd() { 6fn test_zip_aes() {
7 let mut archive = Archive::<Zip>::read_from_file("tests/files/archive_passwd.zip").unwrap(); 7 let mut archive = Archive::<Zip>::read_from_file("tests/files/archive_aes.zip").unwrap();
8
9 assert_eq!(archive.comment(), "archive comment");
10 assert_eq!(
11 archive
12 .files()
13 .iter()
14 .map(|f| &f.name)
15 .collect::<Vec<&String>>(),
16 vec![
17 "aes128/store",
18 "aes192/store",
19 "aes256/store",
20 "aes128/deflate",
21 "aes192/deflate",
22 "aes256/deflate",
23 "aes128/bzip",
24 "aes192/bzip",
25 "aes256/bzip",
26 "aes128/lzma",
27 "aes192/lzma",
28 "aes256/lzma",
29 ]
30 );
31
32 for encryption in ["aes128", "aes192", "aes256"] {
33 assert!(archive
34 .get_file_reader_by_name(&format!("{encryption}/store"))
35 .is_err_and(|e| e == ZipError::PasswordIsNotSpecified));
36 assert!(archive
37 .get_file_reader_by_name_with_password("aes128/store", b"wrong_passwd")
38 .is_err_and(|e| e == ZipError::WrongPassword));
39
40 for (name, check) in [
41 ("store", "98f64f03b3d168875ffa778f7fb4"),
42 ("deflate", "0230e7cadb76460e80cd9de611eb"),
43 ("bzip", "061c17646f025837e33e00425cca"),
44 ("lzma", "43ef5e8ed799eb7a0f25501824ff"),
45 ] {
46 let mut f = archive
47 .get_file_reader_by_name_with_password(&format!("{encryption}/{name}"), b"passwd")
48 .unwrap();
49 let mut data = String::new();
50 f.read_to_string(&mut data).unwrap();
51 assert_eq!(&data[..24], "test encrypted file data");
52 assert_eq!(&data[172..], check);
53 }
54 }
55}
56
57#[test]
58fn test_zip_weak() {
59 let mut archive = Archive::<Zip>::read_from_file("tests/files/archive_weak.zip").unwrap();
8 60
9 assert_eq!(archive.comment(), "archive comment"); 61 assert_eq!(archive.comment(), "archive comment");
10 assert_eq!( 62 assert_eq!(
@@ -21,9 +73,9 @@ fn test_zip_passwd() {
21 .is_err_and(|e| e == ZipError::PasswordIsNotSpecified)); 73 .is_err_and(|e| e == ZipError::PasswordIsNotSpecified));
22 assert!(archive 74 assert!(archive
23 .get_file_reader_by_name_with_password("store", b"wrong_passwd") 75 .get_file_reader_by_name_with_password("store", b"wrong_passwd")
24 .is_err_and(|e| e == ZipError::IncorrectPassword)); 76 .is_err_and(|e| e == ZipError::WrongPassword));
25 77
26 for (name, check_data) in [ 78 for (name, check) in [
27 ("store", "1e643774f40510e37c6f3c451d9d"), 79 ("store", "1e643774f40510e37c6f3c451d9d"),
28 ("deflate", "a70aff4b6b2754ad47852503236a"), 80 ("deflate", "a70aff4b6b2754ad47852503236a"),
29 ("bzip", "f7085f4f8ecc512a8c2c3cbe8227"), 81 ("bzip", "f7085f4f8ecc512a8c2c3cbe8227"),
@@ -34,7 +86,7 @@ fn test_zip_passwd() {
34 let mut data = String::new(); 86 let mut data = String::new();
35 f.read_to_string(&mut data).unwrap(); 87 f.read_to_string(&mut data).unwrap();
36 assert_eq!(&data[..24], "test encrypted file data"); 88 assert_eq!(&data[..24], "test encrypted file data");
37 assert_eq!(&data[172..], check_data); 89 assert_eq!(&data[172..], check);
38 } 90 }
39} 91}
40 92
@@ -52,6 +104,11 @@ fn test_zip() {
52 vec!["store", "deflate", "bzip", "lzma", "zstd", "xz"] 104 vec!["store", "deflate", "bzip", "lzma", "zstd", "xz"]
53 ); 105 );
54 106
107 assert_eq!(
108 archive.get_file_info_by_name("none").unwrap_err(),
109 ZipError::FileNotFound
110 );
111
55 let mut f = archive.get_file_reader_by_name("store").unwrap(); 112 let mut f = archive.get_file_reader_by_name("store").unwrap();
56 113
57 let mut data = String::new(); 114 let mut data = String::new();