| 1 | use std::{ |
| 2 | fs, |
| 3 | io::Write, |
| 4 | path::PathBuf, |
| 5 | process::{Command, Stdio}, |
| 6 | sync::atomic::{AtomicU64, Ordering}, |
| 7 | }; |
| 8 | use zipelo_archive_worker::{ |
| 9 | archive, |
| 10 | protocol::*, |
| 11 | wire::{Reader, Writer}, |
| 12 | }; |
| 13 | static NEXT: AtomicU64 = AtomicU64::new(0); |
| 14 | struct Scratch(PathBuf); |
| 15 | impl Scratch { |
| 16 | fn new() -> Self { |
| 17 | let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 18 | .parent() |
| 19 | .unwrap() |
| 20 | .parent() |
| 21 | .unwrap() |
| 22 | .join("tests/rust-archive-worker/runs") |
| 23 | .join(format!( |
| 24 | "{}-{}", |
| 25 | std::process::id(), |
| 26 | NEXT.fetch_add(1, Ordering::Relaxed) |
| 27 | )); |
| 28 | fs::create_dir_all(path.parent().unwrap()).unwrap(); |
| 29 | let builder = fs::DirBuilder::new(); |
| 30 | #[cfg(unix)] |
| 31 | let mut builder = builder; |
| 32 | #[cfg(unix)] |
| 33 | { |
| 34 | use std::os::unix::fs::DirBuilderExt; |
| 35 | builder.mode(0o700); |
| 36 | } |
| 37 | builder.create(&path).unwrap(); |
| 38 | Self(path) |
| 39 | } |
| 40 | fn path(&self, name: &str) -> NativePath { |
| 41 | NativePath::from_path(&self.0.join(name)) |
| 42 | } |
| 43 | fn worker(&self) -> Command { |
| 44 | let mut command = Command::new(env!("CARGO_BIN_EXE_zipelo-archive-worker")); |
| 45 | // 공유 임시 폴더의 할당량과 다른 시험의 사용량에 의존하지 않음. |
| 46 | command |
| 47 | .env("TMPDIR", &self.0) |
| 48 | .env("TMP", &self.0) |
| 49 | .env("TEMP", &self.0); |
| 50 | command |
| 51 | } |
| 52 | } |
| 53 | impl Drop for Scratch { |
| 54 | fn drop(&mut self) { |
| 55 | fs::remove_dir_all(&self.0).unwrap(); |
| 56 | } |
| 57 | } |
| 58 | fn execute(start: Start) -> Vec<Message> { |
| 59 | let mut data = Vec::new(); |
| 60 | Writer::new(&mut data, 17) |
| 61 | .send(&Message::Start(start)) |
| 62 | .unwrap(); |
| 63 | let temporary = Scratch::new(); |
| 64 | let mut command = temporary.worker(); |
| 65 | command |
| 66 | .stdin(Stdio::piped()) |
| 67 | .stdout(Stdio::piped()) |
| 68 | .stderr(Stdio::piped()); |
| 69 | #[cfg(target_os = "linux")] |
| 70 | { |
| 71 | use std::os::unix::process::CommandExt; |
| 72 | #[repr(C)] |
| 73 | struct Limit { |
| 74 | soft: usize, |
| 75 | hard: usize, |
| 76 | } |
| 77 | unsafe extern "C" { |
| 78 | fn setrlimit(resource: i32, limit: *const Limit) -> i32; |
| 79 | } |
| 80 | // 자식 프로세스의 주소 공간만 512 MiB로 제한함. |
| 81 | unsafe { |
| 82 | command.pre_exec(|| { |
| 83 | let limit = Limit { |
| 84 | soft: 512 * 1024 * 1024, |
| 85 | hard: 512 * 1024 * 1024, |
| 86 | }; |
| 87 | if setrlimit(9, &limit) == 0 { |
| 88 | Ok(()) |
| 89 | } else { |
| 90 | Err(std::io::Error::last_os_error()) |
| 91 | } |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | let mut child = command.spawn().unwrap(); |
| 96 | child.stdin.take().unwrap().write_all(&data).unwrap(); |
| 97 | let output = child.wait_with_output().unwrap(); |
| 98 | assert!(output.status.success(), "{:?}", output.stderr); |
| 99 | assert!(output.stderr.is_empty()); |
| 100 | let mut reader = Reader::new(output.stdout.as_slice()); |
| 101 | let mut events = Vec::new(); |
| 102 | while let Some((job, _, event)) = reader.read().unwrap() { |
| 103 | assert_eq!(job, 17); |
| 104 | events.push(event); |
| 105 | } |
| 106 | assert!(matches!(events.last(), Some(Message::Terminal(_)))); |
| 107 | events |
| 108 | } |
| 109 | fn terminal(events: &[Message]) -> &Terminal { |
| 110 | match events.last().unwrap() { |
| 111 | Message::Terminal(t) => t, |
| 112 | _ => panic!("missing terminal"), |
| 113 | } |
| 114 | } |
| 115 | fn extract( |
| 116 | s: &Scratch, |
| 117 | bytes: &[u8], |
| 118 | gzip: Option<&str>, |
| 119 | selection: Selection, |
| 120 | list_id: Option<ListId>, |
| 121 | limits: Limits, |
| 122 | ) -> Vec<Message> { |
| 123 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 124 | if !s.0.join("output").exists() { |
| 125 | let d = fs::DirBuilder::new(); |
| 126 | #[cfg(unix)] |
| 127 | let mut d = d; |
| 128 | #[cfg(unix)] |
| 129 | { |
| 130 | use std::os::unix::fs::DirBuilderExt; |
| 131 | d.mode(0o700); |
| 132 | } |
| 133 | d.create(s.0.join("output")).unwrap(); |
| 134 | } |
| 135 | execute(Start { |
| 136 | action: Action::Extract { |
| 137 | archive: s.path("input"), |
| 138 | destination: s.path("output"), |
| 139 | selection, |
| 140 | list_id, |
| 141 | gzip_output_name: gzip.map(str::to_owned), |
| 142 | }, |
| 143 | limits, |
| 144 | }) |
| 145 | } |
| 146 | const PAYLOAD: &[u8] = b"Zipelo worker interoperability\n"; |
| 147 | fn basic(bytes: &[u8], gzip: Option<&str>, output: &str) { |
| 148 | let s = Scratch::new(); |
| 149 | let events = extract(&s, bytes, gzip, Selection::All, None, Limits::default()); |
| 150 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 151 | assert_eq!(terminal(&events).publication, Publication::Complete); |
| 152 | assert_eq!(fs::read(s.0.join("output").join(output)).unwrap(), PAYLOAD); |
| 153 | } |
| 154 | #[test] |
| 155 | fn stored_zip() { |
| 156 | basic( |
| 157 | include_bytes!("fixtures/store.zip"), |
| 158 | None, |
| 159 | "folder/hello.txt", |
| 160 | ); |
| 161 | } |
| 162 | #[test] |
| 163 | fn deflated_zip() { |
| 164 | basic( |
| 165 | include_bytes!("fixtures/deflate.zip"), |
| 166 | None, |
| 167 | "folder/hello.txt", |
| 168 | ); |
| 169 | } |
| 170 | #[test] |
| 171 | fn tar() { |
| 172 | basic( |
| 173 | include_bytes!("fixtures/sample.tar"), |
| 174 | None, |
| 175 | "folder/hello.txt", |
| 176 | ); |
| 177 | } |
| 178 | #[test] |
| 179 | fn tar_gzip() { |
| 180 | basic( |
| 181 | include_bytes!("fixtures/sample.tar.gz"), |
| 182 | None, |
| 183 | "folder/hello.txt", |
| 184 | ); |
| 185 | } |
| 186 | #[test] |
| 187 | fn gzip_explicit_name_ignores_fname() { |
| 188 | basic( |
| 189 | include_bytes!("fixtures/sample.gz"), |
| 190 | Some("chosen.txt"), |
| 191 | "chosen.txt", |
| 192 | ); |
| 193 | } |
| 194 | #[test] |
| 195 | fn gzip_concatenated_members() { |
| 196 | let s = Scratch::new(); |
| 197 | let events = extract( |
| 198 | &s, |
| 199 | include_bytes!("fixtures/concat.gz"), |
| 200 | Some("combined"), |
| 201 | Selection::All, |
| 202 | None, |
| 203 | Limits::default(), |
| 204 | ); |
| 205 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 206 | assert_eq!(fs::read(s.0.join("output/combined")).unwrap(), b"onetwo"); |
| 207 | } |
| 208 | #[test] |
| 209 | fn gzip_requires_leaf() { |
| 210 | for name in [None, Some("../escape"), Some("a/b")] { |
| 211 | let s = Scratch::new(); |
| 212 | let e = extract( |
| 213 | &s, |
| 214 | include_bytes!("fixtures/sample.gz"), |
| 215 | name, |
| 216 | Selection::All, |
| 217 | None, |
| 218 | Limits::default(), |
| 219 | ); |
| 220 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 221 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 222 | } |
| 223 | } |
| 224 | #[test] |
| 225 | fn archive_rejects_gzip_name() { |
| 226 | let s = Scratch::new(); |
| 227 | let e = extract( |
| 228 | &s, |
| 229 | include_bytes!("fixtures/store.zip"), |
| 230 | Some("a"), |
| 231 | Selection::All, |
| 232 | None, |
| 233 | Limits::default(), |
| 234 | ); |
| 235 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 236 | } |
| 237 | #[test] |
| 238 | fn no_clobber_and_preflight_no_partial_outputs() { |
| 239 | let s = Scratch::new(); |
| 240 | fs::create_dir(s.0.join("output")).unwrap(); |
| 241 | #[cfg(unix)] |
| 242 | { |
| 243 | use std::os::unix::fs::PermissionsExt; |
| 244 | fs::set_permissions(s.0.join("output"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 245 | } |
| 246 | fs::create_dir(s.0.join("output/folder")).unwrap(); |
| 247 | #[cfg(unix)] |
| 248 | { |
| 249 | use std::os::unix::fs::PermissionsExt; |
| 250 | fs::set_permissions(s.0.join("output/folder"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 251 | } |
| 252 | fs::write(s.0.join("output/folder/hello.txt"), b"preserve").unwrap(); |
| 253 | let e = extract( |
| 254 | &s, |
| 255 | include_bytes!("fixtures/store.zip"), |
| 256 | None, |
| 257 | Selection::All, |
| 258 | None, |
| 259 | Limits::default(), |
| 260 | ); |
| 261 | assert_eq!(terminal(&e).error, ErrorCode::Conflict); |
| 262 | assert_eq!( |
| 263 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 264 | b"preserve" |
| 265 | ); |
| 266 | assert!(!s.0.join("output/empty").exists()); |
| 267 | } |
| 268 | #[test] |
| 269 | fn unsafe_archives_reject_without_writes() { |
| 270 | for bytes in [ |
| 271 | include_bytes!("fixtures/traversal.zip").as_slice(), |
| 272 | include_bytes!("fixtures/absolute.zip"), |
| 273 | include_bytes!("fixtures/drive.zip"), |
| 274 | include_bytes!("fixtures/reserved.zip"), |
| 275 | include_bytes!("fixtures/link.zip"), |
| 276 | include_bytes!("fixtures/collision.zip"), |
| 277 | include_bytes!("fixtures/parent-collision.zip"), |
| 278 | ] { |
| 279 | let s = Scratch::new(); |
| 280 | let e = extract(&s, bytes, None, Selection::All, None, Limits::default()); |
| 281 | assert_eq!(terminal(&e).outcome, Outcome::Failed, "{e:?}"); |
| 282 | assert_eq!(terminal(&e).created_count, 0); |
| 283 | assert_eq!(terminal(&e).publication, Publication::None); |
| 284 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 285 | } |
| 286 | } |
| 287 | #[test] |
| 288 | fn bomb_rejects_before_writes() { |
| 289 | let s = Scratch::new(); |
| 290 | let e = extract( |
| 291 | &s, |
| 292 | include_bytes!("fixtures/bomb.zip"), |
| 293 | None, |
| 294 | Selection::All, |
| 295 | None, |
| 296 | Limits { |
| 297 | output: 1024, |
| 298 | ..Limits::default() |
| 299 | }, |
| 300 | ); |
| 301 | assert_eq!(terminal(&e).error, ErrorCode::Limit); |
| 302 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 303 | } |
| 304 | #[test] |
| 305 | fn corrupt_crc_and_truncation_reject_without_writes() { |
| 306 | let mut zip = include_bytes!("fixtures/store.zip").to_vec(); |
| 307 | let at = zip |
| 308 | .windows(PAYLOAD.len()) |
| 309 | .position(|b| b == PAYLOAD) |
| 310 | .unwrap(); |
| 311 | zip[at] ^= 1; |
| 312 | for bytes in [zip.as_slice(), &include_bytes!("fixtures/store.zip")[..40]] { |
| 313 | let s = Scratch::new(); |
| 314 | let e = extract(&s, bytes, None, Selection::All, None, Limits::default()); |
| 315 | assert_eq!(terminal(&e).outcome, Outcome::Failed); |
| 316 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 317 | } |
| 318 | } |
| 319 | fn listing(s: &Scratch) -> ListId { |
| 320 | let e = execute(Start { |
| 321 | action: Action::List { |
| 322 | archive: s.path("input"), |
| 323 | }, |
| 324 | limits: Limits::default(), |
| 325 | }); |
| 326 | assert_eq!(terminal(&e).outcome, Outcome::Completed); |
| 327 | e.into_iter() |
| 328 | .find_map(|m| { |
| 329 | if let Message::ListEnd { list_id, .. } = m { |
| 330 | Some(list_id) |
| 331 | } else { |
| 332 | None |
| 333 | } |
| 334 | }) |
| 335 | .unwrap() |
| 336 | } |
| 337 | #[test] |
| 338 | fn list_and_selected_extract() { |
| 339 | let s = Scratch::new(); |
| 340 | let bytes = include_bytes!("fixtures/store.zip"); |
| 341 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 342 | let id = listing(&s); |
| 343 | let e = extract( |
| 344 | &s, |
| 345 | bytes, |
| 346 | None, |
| 347 | Selection::EntryIds(vec![0]), |
| 348 | Some(id), |
| 349 | Limits::default(), |
| 350 | ); |
| 351 | assert_eq!(terminal(&e).outcome, Outcome::Completed); |
| 352 | assert!(!s.0.join("output/empty").exists()); |
| 353 | assert_eq!( |
| 354 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 355 | PAYLOAD |
| 356 | ); |
| 357 | } |
| 358 | #[test] |
| 359 | fn stale_list_content_rejected() { |
| 360 | let s = Scratch::new(); |
| 361 | fs::write(s.0.join("input"), include_bytes!("fixtures/store.zip")).unwrap(); |
| 362 | let mut id = listing(&s); |
| 363 | id.archive_sha256[0] ^= 1; |
| 364 | let e = extract( |
| 365 | &s, |
| 366 | include_bytes!("fixtures/store.zip"), |
| 367 | None, |
| 368 | Selection::EntryIds(vec![0]), |
| 369 | Some(id), |
| 370 | Limits::default(), |
| 371 | ); |
| 372 | assert_eq!(terminal(&e).error, ErrorCode::SourceChanged); |
| 373 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 374 | } |
| 375 | #[test] |
| 376 | fn missing_duplicate_and_out_of_range_selection() { |
| 377 | for ids in [vec![], vec![0, 0], vec![999]] { |
| 378 | let s = Scratch::new(); |
| 379 | fs::write(s.0.join("input"), include_bytes!("fixtures/store.zip")).unwrap(); |
| 380 | let id = listing(&s); |
| 381 | let e = extract( |
| 382 | &s, |
| 383 | include_bytes!("fixtures/store.zip"), |
| 384 | None, |
| 385 | Selection::EntryIds(ids), |
| 386 | Some(id), |
| 387 | Limits::default(), |
| 388 | ); |
| 389 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 390 | } |
| 391 | let s = Scratch::new(); |
| 392 | let e = extract( |
| 393 | &s, |
| 394 | include_bytes!("fixtures/store.zip"), |
| 395 | None, |
| 396 | Selection::EntryIds(vec![0]), |
| 397 | None, |
| 398 | Limits::default(), |
| 399 | ); |
| 400 | assert_eq!(terminal(&e).error, ErrorCode::InvalidRequest); |
| 401 | } |
| 402 | #[test] |
| 403 | fn create_store_and_deflate_zip() { |
| 404 | for method in [Method::Store, Method::Deflate] { |
| 405 | let s = Scratch::new(); |
| 406 | fs::write(s.0.join("source"), PAYLOAD).unwrap(); |
| 407 | let e = execute(Start { |
| 408 | action: Action::CreateZip { |
| 409 | sources: vec![Source { |
| 410 | path: s.path("source"), |
| 411 | archive_name: "dir/hello.txt".into(), |
| 412 | }], |
| 413 | output_file: s.path("result.zip"), |
| 414 | method, |
| 415 | encryption: Encryption::None, |
| 416 | }, |
| 417 | limits: Limits::default(), |
| 418 | }); |
| 419 | assert_eq!(terminal(&e).outcome, Outcome::Completed, "{e:?}"); |
| 420 | let bytes = fs::read(s.0.join("result.zip")).unwrap(); |
| 421 | let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); |
| 422 | assert_eq!(parsed.members[0].data, PAYLOAD); |
| 423 | } |
| 424 | } |
| 425 | #[test] |
| 426 | fn encryption_password_eof_is_protocol_failure() { |
| 427 | let s = Scratch::new(); |
| 428 | let e = execute(Start { |
| 429 | action: Action::CreateZip { |
| 430 | sources: vec![], |
| 431 | output_file: s.path("result.zip"), |
| 432 | method: Method::Store, |
| 433 | encryption: Encryption::Aes256, |
| 434 | }, |
| 435 | limits: Limits::default(), |
| 436 | }); |
| 437 | assert_eq!(terminal(&e).error, ErrorCode::Protocol); |
| 438 | assert!(!s.0.join("result.zip").exists()); |
| 439 | } |
| 440 | #[test] |
| 441 | fn name_policy() { |
| 442 | for name in [ |
| 443 | "../a", "/a", "a\\b", "C:a", "a/../b", "a.", "a ", "COM1.txt", "a//b", "a/./b", |
| 444 | ] { |
| 445 | assert!(archive::valid_name(name, false).is_err(), "{name}"); |
| 446 | } |
| 447 | assert!(archive::valid_name("folder/한글.txt", false).is_ok()); |
| 448 | } |
| 449 | #[test] |
| 450 | fn frame_round_trip_and_secret_redaction() { |
| 451 | let mut b = Vec::new(); |
| 452 | Writer::new(&mut b, 42).send(&Message::Cancel).unwrap(); |
| 453 | let mut reader = Reader::new(b.as_slice()); |
| 454 | assert!(matches!( |
| 455 | reader.read().unwrap(), |
| 456 | Some((42, 0, Message::Cancel)) |
| 457 | )); |
| 458 | assert!(reader.read().unwrap().is_none()); |
| 459 | assert!( |
| 460 | !format!( |
| 461 | "{:?}", |
| 462 | Message::Password { |
| 463 | challenge_id: 1, |
| 464 | secret: Secret(b"private-password".to_vec()) |
| 465 | } |
| 466 | ) |
| 467 | .contains("private-password") |
| 468 | ); |
| 469 | } |
| 470 | #[test] |
| 471 | fn invalid_headers_are_rejected() { |
| 472 | let mut b = Vec::new(); |
| 473 | Writer::new(&mut b, 42).send(&Message::Cancel).unwrap(); |
| 474 | for (offset, value) in [(0, 0), (4, 2), (12, 1), (16, 0), (24, 1)] { |
| 475 | let mut bad = b.clone(); |
| 476 | bad[offset] = value; |
| 477 | assert!(Reader::new(bad.as_slice()).read().is_err()); |
| 478 | } |
| 479 | let mut big = b.clone(); |
| 480 | big[8..12].copy_from_slice(&1_048_577u32.to_le_bytes()); |
| 481 | assert!(Reader::new(big.as_slice()).read().is_err()); |
| 482 | assert!(Reader::new(&b[..16]).read().is_err()); |
| 483 | } |
| 484 | #[test] |
| 485 | fn terminal_is_final_frame() { |
| 486 | let t = Terminal { |
| 487 | outcome: Outcome::Failed, |
| 488 | error: ErrorCode::Io, |
| 489 | publication: Publication::Uncertain, |
| 490 | created_count: 0, |
| 491 | retained_partial_count: 0, |
| 492 | durability: Durability::Unconfirmed, |
| 493 | cleanup: Cleanup::Unconfirmed, |
| 494 | detail: "uncertain".into(), |
| 495 | }; |
| 496 | let mut b = Vec::new(); |
| 497 | let mut w = Writer::new(&mut b, 1); |
| 498 | w.send(&Message::Terminal(t)).unwrap(); |
| 499 | assert!(w.send(&Message::Cancel).is_err()); |
| 500 | } |
| 501 | #[cfg(unix)] |
| 502 | #[test] |
| 503 | fn symlink_parent_escape_is_rejected() { |
| 504 | use std::os::unix::fs::symlink; |
| 505 | let s = Scratch::new(); |
| 506 | let d = fs::DirBuilder::new(); |
| 507 | #[cfg(unix)] |
| 508 | let mut d = d; |
| 509 | use std::os::unix::fs::DirBuilderExt; |
| 510 | d.mode(0o700); |
| 511 | d.create(s.0.join("output")).unwrap(); |
| 512 | d.create(s.0.join("outside")).unwrap(); |
| 513 | symlink(s.0.join("outside"), s.0.join("output/folder")).unwrap(); |
| 514 | let e = extract( |
| 515 | &s, |
| 516 | include_bytes!("fixtures/store.zip"), |
| 517 | None, |
| 518 | Selection::All, |
| 519 | None, |
| 520 | Limits::default(), |
| 521 | ); |
| 522 | assert_eq!(terminal(&e).error, ErrorCode::UnsafePath); |
| 523 | assert_eq!(fs::read_dir(s.0.join("outside")).unwrap().count(), 0); |
| 524 | } |
| 525 | |
| 526 | #[test] |
| 527 | fn changed_source_is_reopen_error_before_decode() { |
| 528 | let s = Scratch::new(); |
| 529 | let bytes = include_bytes!("fixtures/store.zip"); |
| 530 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 531 | let id = listing(&s); |
| 532 | let mut changed = bytes.to_vec(); |
| 533 | changed[40] ^= 1; |
| 534 | let e = extract( |
| 535 | &s, |
| 536 | &changed, |
| 537 | None, |
| 538 | Selection::EntryIds(vec![0]), |
| 539 | Some(id), |
| 540 | Limits::default(), |
| 541 | ); |
| 542 | assert_eq!(terminal(&e).error, ErrorCode::SourceChanged); |
| 543 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 544 | } |
| 545 | #[test] |
| 546 | fn cancel_ack_and_terminal_are_distinct() { |
| 547 | let s = Scratch::new(); |
| 548 | fs::write(s.0.join("source"), vec![0u8; 16 * 1024 * 1024]).unwrap(); |
| 549 | let start = Start { |
| 550 | action: Action::CreateZip { |
| 551 | sources: vec![Source { |
| 552 | path: s.path("source"), |
| 553 | archive_name: "data".into(), |
| 554 | }], |
| 555 | output_file: s.path("result.zip"), |
| 556 | method: Method::Deflate, |
| 557 | encryption: Encryption::None, |
| 558 | }, |
| 559 | limits: Limits::default(), |
| 560 | }; |
| 561 | let mut child = Command::new(env!("CARGO_BIN_EXE_zipelo-archive-worker")) |
| 562 | .stdin(Stdio::piped()) |
| 563 | .stdout(Stdio::piped()) |
| 564 | .stderr(Stdio::piped()) |
| 565 | .spawn() |
| 566 | .unwrap(); |
| 567 | let mut writer = Writer::new(child.stdin.take().unwrap(), 19); |
| 568 | let mut reader = Reader::new(child.stdout.take().unwrap()); |
| 569 | writer.send(&Message::Start(start)).unwrap(); |
| 570 | assert!(matches!( |
| 571 | reader.read().unwrap(), |
| 572 | Some((19, 0, Message::Accepted { .. })) |
| 573 | )); |
| 574 | writer.send(&Message::Cancel).unwrap(); |
| 575 | writer.send(&Message::Cancel).unwrap(); |
| 576 | let mut events = Vec::new(); |
| 577 | while let Some((_, _, m)) = reader.read().unwrap() { |
| 578 | events.push(m); |
| 579 | } |
| 580 | assert!(child.wait().unwrap().success()); |
| 581 | let terminal = terminal(&events); |
| 582 | assert!(matches!( |
| 583 | terminal.outcome, |
| 584 | Outcome::Cancelled | Outcome::Completed |
| 585 | )); |
| 586 | for m in &events { |
| 587 | if let Message::CancelAck { |
| 588 | request_sequence, |
| 589 | status, |
| 590 | } = m |
| 591 | { |
| 592 | assert!([1, 2].contains(request_sequence)); |
| 593 | assert!(matches!( |
| 594 | status, |
| 595 | CancelStatus::Requested |
| 596 | | CancelStatus::AlreadyRequested |
| 597 | | CancelStatus::TooLate |
| 598 | | CancelStatus::Finished |
| 599 | )); |
| 600 | } |
| 601 | } |
| 602 | assert!( |
| 603 | events |
| 604 | .iter() |
| 605 | .any(|m| matches!(m, Message::CancelAck { .. })), |
| 606 | "cancel must be consumed during bounded source read: {events:?}" |
| 607 | ); |
| 608 | } |
| 609 | |
| 610 | #[test] |
| 611 | fn encrypted_zip_password_eof_preserves_outputs() { |
| 612 | let mut bytes = include_bytes!("fixtures/store.zip").to_vec(); |
| 613 | bytes[6] |= 1; |
| 614 | let central = bytes.windows(4).position(|b| b == b"PK\x01\x02").unwrap(); |
| 615 | bytes[central + 8] |= 1; |
| 616 | let s = Scratch::new(); |
| 617 | let e = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 618 | assert_eq!(terminal(&e).error, ErrorCode::Protocol); |
| 619 | assert_eq!(terminal(&e).publication, Publication::None); |
| 620 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 621 | } |
| 622 | #[test] |
| 623 | fn uncertain_report_survives_codec() { |
| 624 | let t = Terminal { |
| 625 | outcome: Outcome::Failed, |
| 626 | error: ErrorCode::Io, |
| 627 | publication: Publication::Uncertain, |
| 628 | created_count: 2, |
| 629 | retained_partial_count: 1, |
| 630 | durability: Durability::Failed, |
| 631 | cleanup: Cleanup::Failed, |
| 632 | detail: "publication uncertain".into(), |
| 633 | }; |
| 634 | let mut bytes = Vec::new(); |
| 635 | Writer::new(&mut bytes, 88) |
| 636 | .send(&Message::Terminal(t.clone())) |
| 637 | .unwrap(); |
| 638 | let mut reader = Reader::new(bytes.as_slice()); |
| 639 | match reader.read().unwrap() { |
| 640 | Some((88, 0, Message::Terminal(actual))) => assert_eq!(actual, t), |
| 641 | other => panic!("{other:?}"), |
| 642 | }; |
| 643 | assert!(reader.read().unwrap().is_none()); |
| 644 | } |
| 645 | |
| 646 | fn path_fixture_zip(names: &[String]) -> Vec<u8> { |
| 647 | let mut output = Vec::new(); |
| 648 | let mut central = Vec::new(); |
| 649 | for name in names { |
| 650 | let offset = output.len() as u32; |
| 651 | output.extend(b"PK\x03\x04"); |
| 652 | for value in [20u16, 0x0800, 0, 0, 33] { |
| 653 | output.extend(value.to_le_bytes()); |
| 654 | } |
| 655 | for value in [0u32, 0, 0] { |
| 656 | output.extend(value.to_le_bytes()); |
| 657 | } |
| 658 | output.extend((name.len() as u16).to_le_bytes()); |
| 659 | output.extend(0u16.to_le_bytes()); |
| 660 | output.extend(name.as_bytes()); |
| 661 | central.extend(b"PK\x01\x02"); |
| 662 | for value in [0x0314u16, 20, 0x0800, 0, 0, 33] { |
| 663 | central.extend(value.to_le_bytes()); |
| 664 | } |
| 665 | for value in [0u32, 0, 0] { |
| 666 | central.extend(value.to_le_bytes()); |
| 667 | } |
| 668 | central.extend((name.len() as u16).to_le_bytes()); |
| 669 | for value in [0u16, 0, 0, 0] { |
| 670 | central.extend(value.to_le_bytes()); |
| 671 | } |
| 672 | central.extend((0o100600u32 << 16).to_le_bytes()); |
| 673 | central.extend(offset.to_le_bytes()); |
| 674 | central.extend(name.as_bytes()); |
| 675 | } |
| 676 | let offset = output.len() as u32; |
| 677 | output.extend(¢ral); |
| 678 | output.extend(b"PK\x05\x06"); |
| 679 | for value in [0u16, 0, names.len() as u16, names.len() as u16] { |
| 680 | output.extend(value.to_le_bytes()); |
| 681 | } |
| 682 | output.extend((central.len() as u32).to_le_bytes()); |
| 683 | output.extend(offset.to_le_bytes()); |
| 684 | output.extend(0u16.to_le_bytes()); |
| 685 | output |
| 686 | } |
| 687 | |
| 688 | fn assert_metadata_limit(names: &[String]) { |
| 689 | let scratch = Scratch::new(); |
| 690 | let events = extract( |
| 691 | &scratch, |
| 692 | &path_fixture_zip(names), |
| 693 | None, |
| 694 | Selection::All, |
| 695 | None, |
| 696 | Limits::default(), |
| 697 | ); |
| 698 | let result = terminal(&events); |
| 699 | assert_eq!(result.outcome, Outcome::Failed, "{events:?}"); |
| 700 | assert_eq!(result.error, ErrorCode::Limit, "{events:?}"); |
| 701 | assert_eq!(result.publication, Publication::None); |
| 702 | assert_eq!(result.created_count, 0); |
| 703 | assert_eq!(fs::read_dir(scratch.0.join("output")).unwrap().count(), 0); |
| 704 | } |
| 705 | |
| 706 | #[test] |
| 707 | fn deep_zip_returns_limit_without_abort_or_writes() { |
| 708 | let names = (0..100) |
| 709 | .map(|i| format!("{}file{i:03}", "a/".repeat(2000))) |
| 710 | .collect::<Vec<_>>(); |
| 711 | assert_metadata_limit(&names); |
| 712 | } |
| 713 | |
| 714 | #[test] |
| 715 | fn shallow_zip_parent_metadata_is_bounded() { |
| 716 | let names = (0..500) |
| 717 | .map(|i| { |
| 718 | format!( |
| 719 | "d{i:04}{}/{}file", |
| 720 | "a".repeat(180), |
| 721 | format!("{}/", "b".repeat(200)).repeat(7) |
| 722 | ) |
| 723 | }) |
| 724 | .collect::<Vec<_>>(); |
| 725 | assert!( |
| 726 | names |
| 727 | .iter() |
| 728 | .all(|n| n.split('/').count() <= archive::MAX_PATH_DEPTH) |
| 729 | ); |
| 730 | assert!( |
| 731 | archive::parse( |
| 732 | &path_fixture_zip(&names), |
| 733 | Limits::default(), |
| 734 | false, |
| 735 | &mut || Ok(()) |
| 736 | ) |
| 737 | .is_ok() |
| 738 | ); |
| 739 | assert_metadata_limit(&names); |
| 740 | } |
| 741 | |
| 742 | #[test] |
| 743 | fn aggregate_archive_name_metadata_is_bounded() { |
| 744 | let names = (0..1100) |
| 745 | .map(|i| { |
| 746 | format!( |
| 747 | "d{i:04}{}/{}file", |
| 748 | "a".repeat(180), |
| 749 | format!("{}/", "b".repeat(200)).repeat(9) |
| 750 | ) |
| 751 | }) |
| 752 | .collect::<Vec<_>>(); |
| 753 | let bytes = path_fixture_zip(&names); |
| 754 | assert!((bytes.len() as u64) < Limits::default().input); |
| 755 | assert!(matches!( |
| 756 | archive::parse(&bytes, Limits::default(), false, &mut || Ok(())), |
| 757 | Err(ErrorCode::Limit) |
| 758 | )); |
| 759 | assert_metadata_limit(&names); |
| 760 | } |
| 761 | |
| 762 | #[test] |
| 763 | fn path_depth_boundary_is_explicit() { |
| 764 | let accepted = format!("{}file", "a/".repeat(archive::MAX_PATH_DEPTH - 1)); |
| 765 | let rejected = format!("{}file", "a/".repeat(archive::MAX_PATH_DEPTH)); |
| 766 | assert!(archive::valid_name(&accepted, false).is_ok()); |
| 767 | assert_eq!(archive::valid_name(&rejected, false), Err(ErrorCode::Limit)); |
| 768 | } |
| 769 | |
| 770 | fn zeros_gzip(length: usize) -> Vec<u8> { |
| 771 | let mut gzip = vec![31, 139, 8, 0, 0, 0, 0, 0, 0, 255]; |
| 772 | let mut left = length; |
| 773 | loop { |
| 774 | let size = left.min(u16::MAX as usize) as u16; |
| 775 | left -= size as usize; |
| 776 | gzip.push(u8::from(left == 0)); |
| 777 | gzip.extend(size.to_le_bytes()); |
| 778 | gzip.extend((!size).to_le_bytes()); |
| 779 | gzip.resize(gzip.len() + size as usize, 0); |
| 780 | if left == 0 { |
| 781 | break; |
| 782 | } |
| 783 | } |
| 784 | gzip.extend(zlib_rs::crc32::crc32(0, &vec![0; length]).to_le_bytes()); |
| 785 | gzip.extend((length as u32).to_le_bytes()); |
| 786 | gzip |
| 787 | } |
| 788 | |
| 789 | #[test] |
| 790 | fn zero_payload_gzip_is_not_tar() { |
| 791 | for length in [512, 1024, 1536] { |
| 792 | let scratch = Scratch::new(); |
| 793 | let bytes = zeros_gzip(length); |
| 794 | let parsed = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())).unwrap(); |
| 795 | assert_eq!(parsed.format, Format::Gzip); |
| 796 | let events = extract( |
| 797 | &scratch, |
| 798 | &bytes, |
| 799 | Some("zeros.bin"), |
| 800 | Selection::All, |
| 801 | None, |
| 802 | Limits::default(), |
| 803 | ); |
| 804 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 805 | assert_eq!( |
| 806 | fs::read(scratch.0.join("output/zeros.bin")).unwrap(), |
| 807 | vec![0; length] |
| 808 | ); |
| 809 | fs::write(scratch.0.join("input"), &bytes).unwrap(); |
| 810 | let list_id = listing(&scratch); |
| 811 | assert_eq!(list_id.format, Format::Gzip); |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | const ENCRYPTED_PAYLOAD: &[u8] = b"Zipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\nZipelo encrypted interoperability\n"; |
| 816 | const TEST_PASSWORD: &[u8] = b"fixture-password"; |
| 817 | const AES_ZIP: &[u8] = include_bytes!("fixtures/aes2-deflate.zip"); |
| 818 | fn interactive( |
| 819 | start: Start, |
| 820 | mut respond: impl FnMut(u64, u32, PasswordPurpose) -> Vec<Message>, |
| 821 | ) -> Vec<Message> { |
| 822 | use std::{io::Read, sync::mpsc, time::Duration}; |
| 823 | let temporary = Scratch::new(); |
| 824 | let mut child = temporary |
| 825 | .worker() |
| 826 | .stdin(Stdio::piped()) |
| 827 | .stdout(Stdio::piped()) |
| 828 | .stderr(Stdio::piped()) |
| 829 | .spawn() |
| 830 | .unwrap(); |
| 831 | let mut writer = Some(Writer::new(child.stdin.take().unwrap(), 17)); |
| 832 | writer |
| 833 | .as_mut() |
| 834 | .unwrap() |
| 835 | .send(&Message::Start(start)) |
| 836 | .unwrap(); |
| 837 | let output = child.stdout.take().unwrap(); |
| 838 | let mut errors = child.stderr.take().unwrap(); |
| 839 | let error_thread = std::thread::spawn(move || { |
| 840 | let mut bytes = Vec::new(); |
| 841 | errors.read_to_end(&mut bytes).unwrap(); |
| 842 | bytes |
| 843 | }); |
| 844 | let (sender, receiver) = mpsc::channel(); |
| 845 | let reader_thread = std::thread::spawn(move || { |
| 846 | let mut reader = Reader::new(output); |
| 847 | loop { |
| 848 | let event = reader.read().map(|v| { |
| 849 | v.map(|(job, _, message)| { |
| 850 | assert_eq!(job, 17); |
| 851 | message |
| 852 | }) |
| 853 | }); |
| 854 | let done = !matches!(event, Ok(Some(_))); |
| 855 | if sender.send(event).is_err() || done { |
| 856 | break; |
| 857 | } |
| 858 | } |
| 859 | }); |
| 860 | let mut events = Vec::new(); |
| 861 | loop { |
| 862 | let event = match receiver.recv_timeout(Duration::from_secs(10)) { |
| 863 | Ok(event) => event.unwrap(), |
| 864 | Err(error) => { |
| 865 | child.kill().unwrap(); |
| 866 | child.wait().unwrap(); |
| 867 | panic!("worker timeout: {error}"); |
| 868 | } |
| 869 | }; |
| 870 | let Some(event) = event else { |
| 871 | break; |
| 872 | }; |
| 873 | if let Message::PasswordRequired { |
| 874 | challenge_id, |
| 875 | attempt, |
| 876 | purpose, |
| 877 | } = &event |
| 878 | { |
| 879 | let commands = respond(*challenge_id, *attempt, *purpose); |
| 880 | if commands.is_empty() { |
| 881 | writer = None; |
| 882 | } else { |
| 883 | for command in commands { |
| 884 | writer.as_mut().unwrap().send(&command).unwrap(); |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | if matches!(event, Message::Terminal(_)) { |
| 889 | writer = None; |
| 890 | } |
| 891 | events.push(event); |
| 892 | } |
| 893 | assert!(child.wait().unwrap().success()); |
| 894 | reader_thread.join().unwrap(); |
| 895 | assert!(error_thread.join().unwrap().is_empty()); |
| 896 | assert!(matches!(events.last(), Some(Message::Terminal(_)))); |
| 897 | events |
| 898 | } |
| 899 | fn password_reply(id: u64, password: &[u8]) -> Vec<Message> { |
| 900 | vec![Message::Password { |
| 901 | challenge_id: id, |
| 902 | secret: Secret(password.to_vec()), |
| 903 | }] |
| 904 | } |
| 905 | fn encrypted_start(s: &Scratch, bytes: &[u8]) -> Start { |
| 906 | fs::write(s.0.join("input"), bytes).unwrap(); |
| 907 | fs::create_dir(s.0.join("output")).unwrap(); |
| 908 | #[cfg(unix)] |
| 909 | { |
| 910 | use std::os::unix::fs::PermissionsExt; |
| 911 | fs::set_permissions(s.0.join("output"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 912 | } |
| 913 | Start { |
| 914 | action: Action::Extract { |
| 915 | archive: s.path("input"), |
| 916 | destination: s.path("output"), |
| 917 | selection: Selection::All, |
| 918 | list_id: None, |
| 919 | gzip_output_name: None, |
| 920 | }, |
| 921 | limits: Limits::default(), |
| 922 | } |
| 923 | } |
| 924 | fn no_encrypted_output(s: &Scratch, events: &[Message], error: ErrorCode) { |
| 925 | assert_eq!(terminal(events).error, error, "{events:?}"); |
| 926 | assert_eq!(terminal(events).publication, Publication::None); |
| 927 | assert_eq!(terminal(events).created_count, 0); |
| 928 | assert!(!events.iter().any(|e| matches!(e, Message::Output { .. }))); |
| 929 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 930 | } |
| 931 | #[test] |
| 932 | fn independent_encrypted_fixtures_list_and_extract() { |
| 933 | for bytes in [ |
| 934 | include_bytes!("fixtures/aes1-store.zip").as_slice(), |
| 935 | include_bytes!("fixtures/aes1-deflate.zip").as_slice(), |
| 936 | include_bytes!("fixtures/aes2-store.zip").as_slice(), |
| 937 | AES_ZIP, |
| 938 | include_bytes!("fixtures/zipcrypto-store.zip").as_slice(), |
| 939 | include_bytes!("fixtures/zipcrypto-deflate.zip").as_slice(), |
| 940 | ] { |
| 941 | let s = Scratch::new(); |
| 942 | let start = encrypted_start(&s, bytes); |
| 943 | let listing = execute(Start { |
| 944 | action: Action::List { |
| 945 | archive: s.path("input"), |
| 946 | }, |
| 947 | limits: Limits::default(), |
| 948 | }); |
| 949 | assert_eq!( |
| 950 | terminal(&listing).outcome, |
| 951 | Outcome::Completed, |
| 952 | "{listing:?}" |
| 953 | ); |
| 954 | assert!(listing.iter().any(|e| matches!( |
| 955 | e, |
| 956 | Message::Entry(Entry { |
| 957 | encrypted: true, |
| 958 | .. |
| 959 | }) |
| 960 | ))); |
| 961 | assert!( |
| 962 | !listing |
| 963 | .iter() |
| 964 | .any(|e| matches!(e, Message::PasswordRequired { .. })) |
| 965 | ); |
| 966 | let events = interactive(start, |id, attempt, purpose| { |
| 967 | assert_eq!(purpose, PasswordPurpose::Decrypt); |
| 968 | assert_eq!(attempt, 1); |
| 969 | password_reply(id, TEST_PASSWORD) |
| 970 | }); |
| 971 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 972 | assert_eq!( |
| 973 | fs::read(s.0.join("output/payload.bin")).unwrap(), |
| 974 | ENCRYPTED_PAYLOAD |
| 975 | ); |
| 976 | } |
| 977 | } |
| 978 | #[test] |
| 979 | fn aes_creation_uses_password_flow_and_independent_verification() { |
| 980 | for method in [Method::Store, Method::Deflate] { |
| 981 | let s = Scratch::new(); |
| 982 | fs::write(s.0.join("source"), ENCRYPTED_PAYLOAD).unwrap(); |
| 983 | let events = interactive( |
| 984 | Start { |
| 985 | action: Action::CreateZip { |
| 986 | sources: vec![Source { |
| 987 | path: s.path("source"), |
| 988 | archive_name: "payload.bin".into(), |
| 989 | }], |
| 990 | output_file: s.path("encrypted.zip"), |
| 991 | method, |
| 992 | encryption: Encryption::Aes256, |
| 993 | }, |
| 994 | limits: Limits::default(), |
| 995 | }, |
| 996 | |id, attempt, purpose| { |
| 997 | assert_eq!(purpose, PasswordPurpose::Encrypt); |
| 998 | assert_eq!(attempt, 1); |
| 999 | password_reply(id, TEST_PASSWORD) |
| 1000 | }, |
| 1001 | ); |
| 1002 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 1003 | assert!(events.iter().any(|e| matches!( |
| 1004 | e, |
| 1005 | Message::Accepted { |
| 1006 | encryption: true, |
| 1007 | .. |
| 1008 | } |
| 1009 | ))); |
| 1010 | #[cfg(target_os = "linux")] |
| 1011 | { |
| 1012 | let helper = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1013 | .join("../../tests/rust-archive-worker/encryption_fixtures.py"); |
| 1014 | assert!( |
| 1015 | Command::new("python3") |
| 1016 | .arg(helper) |
| 1017 | .arg("--verify") |
| 1018 | .arg(s.0.join("encrypted.zip")) |
| 1019 | .status() |
| 1020 | .unwrap() |
| 1021 | .success() |
| 1022 | ); |
| 1023 | } |
| 1024 | let bytes = fs::read(s.0.join("encrypted.zip")).unwrap(); |
| 1025 | let start = encrypted_start(&s, &bytes); |
| 1026 | let events = interactive(start, |id, _, _| password_reply(id, TEST_PASSWORD)); |
| 1027 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 1028 | assert_eq!( |
| 1029 | fs::read(s.0.join("output/payload.bin")).unwrap(), |
| 1030 | ENCRYPTED_PAYLOAD |
| 1031 | ); |
| 1032 | } |
| 1033 | } |
| 1034 | #[test] |
| 1035 | fn wrong_password_retries_with_new_challenge_then_succeeds() { |
| 1036 | let s = Scratch::new(); |
| 1037 | let start = encrypted_start(&s, AES_ZIP); |
| 1038 | let mut previous = 0; |
| 1039 | let events = interactive(start, |id, attempt, _| { |
| 1040 | assert!(id > previous); |
| 1041 | previous = id; |
| 1042 | password_reply( |
| 1043 | id, |
| 1044 | if attempt == 1 { |
| 1045 | b"wrong" |
| 1046 | } else { |
| 1047 | TEST_PASSWORD |
| 1048 | }, |
| 1049 | ) |
| 1050 | }); |
| 1051 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 1052 | assert_eq!(previous, 2); |
| 1053 | } |
| 1054 | #[test] |
| 1055 | fn wrong_password_attempts_are_bounded_without_writes() { |
| 1056 | let s = Scratch::new(); |
| 1057 | let start = encrypted_start(&s, AES_ZIP); |
| 1058 | let mut attempts = 0; |
| 1059 | let events = interactive(start, |id, attempt, _| { |
| 1060 | attempts = attempt; |
| 1061 | password_reply(id, b"wrong") |
| 1062 | }); |
| 1063 | assert_eq!(attempts, 3); |
| 1064 | no_encrypted_output(&s, &events, ErrorCode::WrongPassword); |
| 1065 | } |
| 1066 | #[test] |
| 1067 | fn cancellation_while_waiting_for_password_is_acknowledged() { |
| 1068 | let s = Scratch::new(); |
| 1069 | let start = encrypted_start(&s, AES_ZIP); |
| 1070 | let events = interactive(start, |_, _, _| vec![Message::Cancel]); |
| 1071 | assert_eq!(terminal(&events).outcome, Outcome::Cancelled); |
| 1072 | assert!(events.iter().any(|e| matches!( |
| 1073 | e, |
| 1074 | Message::CancelAck { |
| 1075 | status: CancelStatus::Requested, |
| 1076 | .. |
| 1077 | } |
| 1078 | ))); |
| 1079 | no_encrypted_output(&s, &events, ErrorCode::None); |
| 1080 | } |
| 1081 | #[test] |
| 1082 | fn stale_and_mismatched_password_challenges_fail_without_writes() { |
| 1083 | for stale in [false, true] { |
| 1084 | let s = Scratch::new(); |
| 1085 | let start = encrypted_start(&s, AES_ZIP); |
| 1086 | let events = interactive(start, |id, attempt, _| { |
| 1087 | if stale && attempt == 1 { |
| 1088 | password_reply(id, b"wrong") |
| 1089 | } else { |
| 1090 | password_reply(if stale { id - 1 } else { id + 1 }, TEST_PASSWORD) |
| 1091 | } |
| 1092 | }); |
| 1093 | no_encrypted_output(&s, &events, ErrorCode::Protocol); |
| 1094 | } |
| 1095 | } |
| 1096 | #[test] |
| 1097 | fn password_input_eof_fails_without_writes() { |
| 1098 | let s = Scratch::new(); |
| 1099 | let start = encrypted_start(&s, AES_ZIP); |
| 1100 | let events = interactive(start, |_, _, _| vec![]); |
| 1101 | no_encrypted_output(&s, &events, ErrorCode::Protocol); |
| 1102 | } |
| 1103 | #[test] |
| 1104 | fn aes_authentication_failure_never_publishes_plaintext() { |
| 1105 | for tamper_tag in [false, true] { |
| 1106 | let mut bytes = AES_ZIP.to_vec(); |
| 1107 | let central = bytes.windows(4).position(|b| b == b"PK\x01\x02").unwrap(); |
| 1108 | if tamper_tag { |
| 1109 | bytes[central - 1] ^= 1; |
| 1110 | } else { |
| 1111 | bytes[30 + b"payload.bin".len() + 11 + 18] ^= 1; |
| 1112 | } |
| 1113 | let s = Scratch::new(); |
| 1114 | let start = encrypted_start(&s, &bytes); |
| 1115 | let events = interactive(start, |id, _, _| password_reply(id, TEST_PASSWORD)); |
| 1116 | no_encrypted_output(&s, &events, ErrorCode::Integrity); |
| 1117 | } |
| 1118 | } |
| 1119 | #[test] |
| 1120 | fn aes1_crc_and_extra_consistency_are_checked() { |
| 1121 | let original = include_bytes!("fixtures/aes1-store.zip"); |
| 1122 | for corrupt_extra in [false, true] { |
| 1123 | let mut bytes = original.to_vec(); |
| 1124 | let central = bytes.windows(4).position(|b| b == b"PK\x01\x02").unwrap(); |
| 1125 | if corrupt_extra { |
| 1126 | bytes[30 + b"payload.bin".len() + 4] = 2; |
| 1127 | } else { |
| 1128 | bytes[14] ^= 1; |
| 1129 | bytes[central + 16] ^= 1; |
| 1130 | } |
| 1131 | let s = Scratch::new(); |
| 1132 | let start = encrypted_start(&s, &bytes); |
| 1133 | let events = interactive(start, |id, _, _| password_reply(id, TEST_PASSWORD)); |
| 1134 | no_encrypted_output(&s, &events, ErrorCode::Integrity); |
| 1135 | } |
| 1136 | } |
| 1137 | #[test] |
| 1138 | fn empty_aes_members_and_random_salts_round_trip() { |
| 1139 | let members = vec![archive::Member { |
| 1140 | entry: Entry { |
| 1141 | entry_id: 0, |
| 1142 | name: "empty".into(), |
| 1143 | kind: EntryKind::File, |
| 1144 | size: 0, |
| 1145 | compressed_size: 0, |
| 1146 | encrypted: false, |
| 1147 | }, |
| 1148 | data: vec![], |
| 1149 | }]; |
| 1150 | let a = archive::create_zip_with_password( |
| 1151 | &members, |
| 1152 | Method::Store, |
| 1153 | Limits::default(), |
| 1154 | Some(TEST_PASSWORD), |
| 1155 | &mut || Ok(()), |
| 1156 | ) |
| 1157 | .unwrap(); |
| 1158 | let b = archive::create_zip_with_password( |
| 1159 | &members, |
| 1160 | Method::Store, |
| 1161 | Limits::default(), |
| 1162 | Some(TEST_PASSWORD), |
| 1163 | &mut || Ok(()), |
| 1164 | ) |
| 1165 | .unwrap(); |
| 1166 | assert_ne!(a, b); |
| 1167 | let decoded = archive::parse_with_password( |
| 1168 | &a, |
| 1169 | Limits::default(), |
| 1170 | true, |
| 1171 | Some(TEST_PASSWORD), |
| 1172 | &mut || Ok(()), |
| 1173 | ) |
| 1174 | .unwrap(); |
| 1175 | assert!(decoded.members[0].data.is_empty()); |
| 1176 | } |
| 1177 | |
| 1178 | #[test] |
| 1179 | fn password_racing_after_cancel_does_not_override_cancellation() { |
| 1180 | let s = Scratch::new(); |
| 1181 | let start = encrypted_start(&s, AES_ZIP); |
| 1182 | let events = interactive(start, |id, _, _| { |
| 1183 | vec![ |
| 1184 | Message::Cancel, |
| 1185 | Message::Password { |
| 1186 | challenge_id: id, |
| 1187 | secret: Secret(TEST_PASSWORD.to_vec()), |
| 1188 | }, |
| 1189 | ] |
| 1190 | }); |
| 1191 | assert_eq!(terminal(&events).outcome, Outcome::Cancelled); |
| 1192 | no_encrypted_output(&s, &events, ErrorCode::None); |
| 1193 | } |
| 1194 | #[test] |
| 1195 | fn empty_encryption_password_never_creates_zip() { |
| 1196 | let s = Scratch::new(); |
| 1197 | let events = interactive( |
| 1198 | Start { |
| 1199 | action: Action::CreateZip { |
| 1200 | sources: vec![], |
| 1201 | output_file: s.path("empty.zip"), |
| 1202 | method: Method::Store, |
| 1203 | encryption: Encryption::Aes256, |
| 1204 | }, |
| 1205 | limits: Limits::default(), |
| 1206 | }, |
| 1207 | |id, _, _| password_reply(id, b""), |
| 1208 | ); |
| 1209 | assert_eq!(terminal(&events).error, ErrorCode::InvalidRequest); |
| 1210 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1211 | assert!(!s.0.join("empty.zip").exists()); |
| 1212 | } |
| 1213 | |
| 1214 | const SEVEN_PAYLOAD: &[u8] = b"Zipelo 7z interoperability\n"; |
| 1215 | fn seven_fixture(name: &str) -> Vec<u8> { |
| 1216 | fs::read( |
| 1217 | PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1218 | .join("../../tests/rust-archive-worker/fixtures/7z") |
| 1219 | .join(name), |
| 1220 | ) |
| 1221 | .unwrap() |
| 1222 | } |
| 1223 | #[test] |
| 1224 | fn seven_zip_lzma_lzma2_and_copy_interoperate() { |
| 1225 | for name in [ |
| 1226 | "copy.7z", |
| 1227 | "lzma.7z", |
| 1228 | "lzma2.7z", |
| 1229 | "properties-0.7z", |
| 1230 | "properties-1.7z", |
| 1231 | "properties-2.7z", |
| 1232 | "properties-3.7z", |
| 1233 | "libarchive-lzma1.7z", |
| 1234 | "libarchive-lzma2.7z", |
| 1235 | ] { |
| 1236 | let bytes = seven_fixture(name); |
| 1237 | let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())) |
| 1238 | .unwrap_or_else(|e| panic!("{name}: {e:?}")); |
| 1239 | assert_eq!(catalog.format, Format::SevenZip); |
| 1240 | assert_eq!(catalog.members[0].data, SEVEN_PAYLOAD.repeat(100), "{name}"); |
| 1241 | let s = Scratch::new(); |
| 1242 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1243 | assert_eq!( |
| 1244 | terminal(&events).outcome, |
| 1245 | Outcome::Completed, |
| 1246 | "{name}: {events:?}" |
| 1247 | ); |
| 1248 | assert_eq!( |
| 1249 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 1250 | SEVEN_PAYLOAD.repeat(100) |
| 1251 | ); |
| 1252 | } |
| 1253 | } |
| 1254 | #[test] |
| 1255 | fn seven_zip_encoded_header_solid_and_empty_entries() { |
| 1256 | let s = Scratch::new(); |
| 1257 | let bytes = seven_fixture("encoded-solid.7z"); |
| 1258 | let catalog = archive::parse(&bytes, Limits::default(), false, &mut || Ok(())).unwrap(); |
| 1259 | assert_eq!(catalog.members.len(), 4); |
| 1260 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1261 | assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 1262 | assert_eq!(fs::read(s.0.join("output/folder/empty")).unwrap(), b""); |
| 1263 | assert_eq!( |
| 1264 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 1265 | SEVEN_PAYLOAD.repeat(100) |
| 1266 | ); |
| 1267 | let mut reverse = SEVEN_PAYLOAD.repeat(100); |
| 1268 | reverse.reverse(); |
| 1269 | assert_eq!(fs::read(s.0.join("output/한글.txt")).unwrap(), reverse); |
| 1270 | } |
| 1271 | #[test] |
| 1272 | fn seven_zip_long_matches_and_lzma2_chunks() { |
| 1273 | for name in ["long-match.7z", "lzma2-chunks.7z"] { |
| 1274 | let bytes = seven_fixture(name); |
| 1275 | let catalog = archive::parse(&bytes, Limits::default(), true, &mut || Ok(())) |
| 1276 | .unwrap_or_else(|e| panic!("{name}: {e:?}")); |
| 1277 | if name == "long-match.7z" { |
| 1278 | assert_eq!(catalog.members[0].data, SEVEN_PAYLOAD.repeat(10000)); |
| 1279 | } else { |
| 1280 | let expected = (0..100000u64) |
| 1281 | .map(|i| (((i * 1103515245 + (i >> 2) * 12345) >> ((i % 4) * 8)) & 255) as u8) |
| 1282 | .collect::<Vec<_>>(); |
| 1283 | assert_eq!(catalog.members[0].data, expected); |
| 1284 | } |
| 1285 | } |
| 1286 | } |
| 1287 | #[test] |
| 1288 | fn seven_zip_malicious_inputs_never_write() { |
| 1289 | for name in [ |
| 1290 | "unsafe-dotdot.7z", |
| 1291 | "unsafe-absolute.7z", |
| 1292 | "unsafe-drive.7z", |
| 1293 | "unsafe-backslash.7z", |
| 1294 | "unsafe-deep.7z", |
| 1295 | "symlink.7z", |
| 1296 | "collision.7z", |
| 1297 | "bad-payload.7z", |
| 1298 | "bad-crc.7z", |
| 1299 | "bad-dictionary.7z", |
| 1300 | ] { |
| 1301 | let s = Scratch::new(); |
| 1302 | let bytes = seven_fixture(name); |
| 1303 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1304 | assert_eq!( |
| 1305 | terminal(&events).outcome, |
| 1306 | Outcome::Failed, |
| 1307 | "{name}: {events:?}" |
| 1308 | ); |
| 1309 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1310 | assert_eq!(terminal(&events).created_count, 0); |
| 1311 | assert!(!events.iter().any(|e| matches!(e, Message::Output { .. }))); |
| 1312 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1313 | assert!(!s.0.join("outside.txt").exists()); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | #[test] |
| 1318 | fn seven_zip_format_wire_tag_preserves_existing_encodings() { |
| 1319 | for (tag, format) in [ |
| 1320 | Format::Zip, |
| 1321 | Format::Tar, |
| 1322 | Format::Gzip, |
| 1323 | Format::TarGzip, |
| 1324 | Format::SevenZip, |
| 1325 | ] |
| 1326 | .into_iter() |
| 1327 | .enumerate() |
| 1328 | { |
| 1329 | let token = ListId { |
| 1330 | catalog_version: 1, |
| 1331 | format, |
| 1332 | source_object: SourceObject::Unix { |
| 1333 | device: 1, |
| 1334 | inode: 2, |
| 1335 | }, |
| 1336 | archive_bytes: 3, |
| 1337 | archive_sha256: [4; 32], |
| 1338 | }; |
| 1339 | let mut bytes = Vec::new(); |
| 1340 | Writer::new(&mut bytes, 17) |
| 1341 | .send(&Message::ListEnd { |
| 1342 | entry_count: 5, |
| 1343 | list_id: token.clone(), |
| 1344 | }) |
| 1345 | .unwrap(); |
| 1346 | assert_eq!(bytes[38], tag as u8); |
| 1347 | match Reader::new(bytes.as_slice()).read().unwrap().unwrap().2 { |
| 1348 | Message::ListEnd { |
| 1349 | entry_count, |
| 1350 | list_id, |
| 1351 | } => { |
| 1352 | assert_eq!(entry_count, 5); |
| 1353 | assert_eq!(list_id, token); |
| 1354 | } |
| 1355 | _ => panic!("expected ListEnd"), |
| 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | #[test] |
| 1360 | fn seven_zip_listing_token_and_selection() { |
| 1361 | let s = Scratch::new(); |
| 1362 | let bytes = seven_fixture("encoded-solid.7z"); |
| 1363 | fs::write(s.0.join("input"), &bytes).unwrap(); |
| 1364 | let events = execute(Start { |
| 1365 | action: Action::List { |
| 1366 | archive: s.path("input"), |
| 1367 | }, |
| 1368 | limits: Limits::default(), |
| 1369 | }); |
| 1370 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 1371 | let list_id = events |
| 1372 | .into_iter() |
| 1373 | .find_map(|e| { |
| 1374 | if let Message::ListEnd { list_id, .. } = e { |
| 1375 | Some(list_id) |
| 1376 | } else { |
| 1377 | None |
| 1378 | } |
| 1379 | }) |
| 1380 | .unwrap(); |
| 1381 | assert_eq!(list_id.format, Format::SevenZip); |
| 1382 | let events = extract( |
| 1383 | &s, |
| 1384 | &bytes, |
| 1385 | None, |
| 1386 | Selection::EntryIds(vec![3]), |
| 1387 | Some(list_id), |
| 1388 | Limits::default(), |
| 1389 | ); |
| 1390 | assert_eq!(terminal(&events).outcome, Outcome::Completed); |
| 1391 | assert_eq!(terminal(&events).created_count, 1); |
| 1392 | assert!(!s.0.join("output/folder").exists()); |
| 1393 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 1); |
| 1394 | } |
| 1395 | #[test] |
| 1396 | fn seven_zip_limits_truncation_and_existing_files_are_preserved() { |
| 1397 | let bytes = seven_fixture("lzma2.7z"); |
| 1398 | for cut in [0, 1, 6, 12, 31, 32, bytes.len() - 1] { |
| 1399 | let s = Scratch::new(); |
| 1400 | let events = extract( |
| 1401 | &s, |
| 1402 | &bytes[..cut], |
| 1403 | None, |
| 1404 | Selection::All, |
| 1405 | None, |
| 1406 | Limits::default(), |
| 1407 | ); |
| 1408 | assert_eq!(terminal(&events).outcome, Outcome::Failed); |
| 1409 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1410 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1411 | } |
| 1412 | let s = Scratch::new(); |
| 1413 | let events = extract( |
| 1414 | &s, |
| 1415 | &bytes, |
| 1416 | None, |
| 1417 | Selection::All, |
| 1418 | None, |
| 1419 | Limits { |
| 1420 | output: 100, |
| 1421 | ..Limits::default() |
| 1422 | }, |
| 1423 | ); |
| 1424 | assert_eq!(terminal(&events).error, ErrorCode::Limit); |
| 1425 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1426 | fs::create_dir(s.0.join("output/folder")).unwrap(); |
| 1427 | #[cfg(unix)] |
| 1428 | { |
| 1429 | use std::os::unix::fs::PermissionsExt; |
| 1430 | fs::set_permissions(s.0.join("output/folder"), fs::Permissions::from_mode(0o700)).unwrap(); |
| 1431 | } |
| 1432 | fs::write(s.0.join("output/folder/hello.txt"), b"preserve").unwrap(); |
| 1433 | let events = extract(&s, &bytes, None, Selection::All, None, Limits::default()); |
| 1434 | assert_eq!(terminal(&events).error, ErrorCode::Conflict); |
| 1435 | assert_eq!( |
| 1436 | fs::read(s.0.join("output/folder/hello.txt")).unwrap(), |
| 1437 | b"preserve" |
| 1438 | ); |
| 1439 | let s = Scratch::new(); |
| 1440 | let events = extract( |
| 1441 | &s, |
| 1442 | &seven_fixture("bad-trailing.7z"), |
| 1443 | None, |
| 1444 | Selection::All, |
| 1445 | None, |
| 1446 | Limits::default(), |
| 1447 | ); |
| 1448 | assert_eq!(terminal(&events).error, ErrorCode::Integrity); |
| 1449 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1450 | } |
| 1451 | #[test] |
| 1452 | fn seven_zip_parser_honors_cancellation_checkpoints() { |
| 1453 | let bytes = seven_fixture("long-match.7z"); |
| 1454 | let mut calls = 0; |
| 1455 | let result = archive::parse(&bytes, Limits::default(), true, &mut || { |
| 1456 | calls += 1; |
| 1457 | if calls >= 5 { |
| 1458 | Err(ErrorCode::None) |
| 1459 | } else { |
| 1460 | Ok(()) |
| 1461 | } |
| 1462 | }); |
| 1463 | assert!(matches!(result, Err(ErrorCode::None))); |
| 1464 | } |
| 1465 | #[test] |
| 1466 | fn pr64_malicious_corpus_is_rejected_without_writes() { |
| 1467 | let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1468 | .join("../../tests/malicious-archive-fixtures/fixtures"); |
| 1469 | let cases = [ |
| 1470 | ("zip-dotdot.zip", ErrorCode::UnsafePath, 131072, None), |
| 1471 | ( |
| 1472 | "zip-absolute-posix.zip", |
| 1473 | ErrorCode::UnsafePath, |
| 1474 | 131072, |
| 1475 | None, |
| 1476 | ), |
| 1477 | ( |
| 1478 | "zip-absolute-drive.zip", |
| 1479 | ErrorCode::UnsafePath, |
| 1480 | 131072, |
| 1481 | None, |
| 1482 | ), |
| 1483 | ( |
| 1484 | "zip-backslash-dotdot.zip", |
| 1485 | ErrorCode::UnsafePath, |
| 1486 | 131072, |
| 1487 | None, |
| 1488 | ), |
| 1489 | ("tar-dotdot.tar", ErrorCode::UnsafePath, 131072, None), |
| 1490 | ("targz-dotdot.tar.gz", ErrorCode::UnsafePath, 131072, None), |
| 1491 | ( |
| 1492 | "tar-absolute-posix.tar", |
| 1493 | ErrorCode::UnsafePath, |
| 1494 | 131072, |
| 1495 | None, |
| 1496 | ), |
| 1497 | ("zip-symlink-escape.zip", ErrorCode::Conflict, 131072, None), |
| 1498 | ("tar-symlink-escape.tar", ErrorCode::Conflict, 131072, None), |
| 1499 | ("zip-output-limit.zip", ErrorCode::Limit, 1024, None), |
| 1500 | ( |
| 1501 | "gzip-output-limit.gz", |
| 1502 | ErrorCode::Limit, |
| 1503 | 1024, |
| 1504 | Some("payload.bin"), |
| 1505 | ), |
| 1506 | ("targz-output-limit.tar.gz", ErrorCode::Limit, 1024, None), |
| 1507 | ( |
| 1508 | "zip-bad-local-header.zip", |
| 1509 | ErrorCode::Integrity, |
| 1510 | 131072, |
| 1511 | None, |
| 1512 | ), |
| 1513 | ("tar-bad-checksum.tar", ErrorCode::Integrity, 131072, None), |
| 1514 | ( |
| 1515 | "gzip-reserved-flags.gz", |
| 1516 | ErrorCode::Integrity, |
| 1517 | 131072, |
| 1518 | Some("payload.bin"), |
| 1519 | ), |
| 1520 | ]; |
| 1521 | for (name, expected, output, gzip) in cases { |
| 1522 | let s = Scratch::new(); |
| 1523 | let bytes = fs::read(root.join(name)).unwrap(); |
| 1524 | fs::write(s.0.join("outside.txt"), b"preserve").unwrap(); |
| 1525 | let events = extract( |
| 1526 | &s, |
| 1527 | &bytes, |
| 1528 | gzip, |
| 1529 | Selection::All, |
| 1530 | None, |
| 1531 | Limits { |
| 1532 | input: 1048576, |
| 1533 | output, |
| 1534 | entries: 64, |
| 1535 | }, |
| 1536 | ); |
| 1537 | assert_eq!( |
| 1538 | terminal(&events).outcome, |
| 1539 | Outcome::Failed, |
| 1540 | "{name}: {events:?}" |
| 1541 | ); |
| 1542 | assert_eq!(terminal(&events).error, expected, "{name}"); |
| 1543 | assert_eq!(terminal(&events).publication, Publication::None); |
| 1544 | assert_eq!(terminal(&events).created_count, 0); |
| 1545 | assert_eq!(terminal(&events).retained_partial_count, 0); |
| 1546 | assert!(!events.iter().any(|e| matches!(e, Message::Output { .. }))); |
| 1547 | assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0); |
| 1548 | assert_eq!(fs::read(s.0.join("outside.txt")).unwrap(), b"preserve"); |
| 1549 | assert_eq!(fs::read(s.0.join("input")).unwrap(), bytes); |
| 1550 | } |
| 1551 | } |
| 1552 | #[cfg(target_os = "linux")] |
| 1553 | #[test] |
| 1554 | fn seven_zip_reference_reader_accepts_synthetic_fixtures() { |
| 1555 | let helper = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 1556 | .join("../../tests/rust-archive-worker/seven_zip_reference.py"); |
| 1557 | assert!( |
| 1558 | Command::new("python3") |
| 1559 | .arg(helper) |
| 1560 | .status() |
| 1561 | .unwrap() |
| 1562 | .success() |
| 1563 | ); |
| 1564 | } |
| 1565 | |
| 1566 | mod hardening; |
| 1567 | |
| 1568 | #[test] |
| 1569 | fn disk_full_error_tag_preserves_previous_tags_and_rejects_unknown() { |
| 1570 | for (tag, error) in [ |
| 1571 | ErrorCode::None, |
| 1572 | ErrorCode::Integrity, |
| 1573 | ErrorCode::UnsupportedFormat, |
| 1574 | ErrorCode::UnsupportedFeature, |
| 1575 | ErrorCode::WrongPassword, |
| 1576 | ErrorCode::UnsafePath, |
| 1577 | ErrorCode::Conflict, |
| 1578 | ErrorCode::Limit, |
| 1579 | ErrorCode::Io, |
| 1580 | ErrorCode::Protocol, |
| 1581 | ErrorCode::Internal, |
| 1582 | ErrorCode::SourceChanged, |
| 1583 | ErrorCode::InvalidRequest, |
| 1584 | ErrorCode::DiskFull, |
| 1585 | ] |
| 1586 | .into_iter() |
| 1587 | .enumerate() |
| 1588 | { |
| 1589 | let message = Message::Terminal(Terminal { |
| 1590 | outcome: Outcome::Failed, |
| 1591 | error, |
| 1592 | publication: Publication::None, |
| 1593 | created_count: 0, |
| 1594 | retained_partial_count: 0, |
| 1595 | durability: Durability::NotApplicable, |
| 1596 | cleanup: Cleanup::Complete, |
| 1597 | detail: String::new(), |
| 1598 | }); |
| 1599 | let mut bytes = Vec::new(); |
| 1600 | Writer::new(&mut bytes, 17).send(&message).unwrap(); |
| 1601 | assert_eq!(bytes[33], tag as u8); |
| 1602 | let decoded = Reader::new(bytes.as_slice()).read().unwrap().unwrap().2; |
| 1603 | assert_eq!(terminal(&[decoded]).error, error); |
| 1604 | bytes[33] = 14; |
| 1605 | assert!(Reader::new(bytes.as_slice()).read().is_err()); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | mod folder_inputs; |
| 1610 | |
| 1611 | mod zip_names; |