| | @@ -3,11 +3,41 @@ use super::*; |
| 3 | 3 | // 해제 작업의 원본 사본과 단계 임시 파일은 시스템 임시 폴더가 아니라 출력 폴더에 둠. |
| 4 | 4 | // 시스템 임시 폴더를 쓸 수 없게 만들어도(/tmp 할당량 초과와 같은 상황) 해제가 성공해야 함. |
| 5 | 5 | fn extract_without_system_temp(bytes: &[u8]) -> (Scratch, Vec<Message>) { |
| 6 | +추가: extract_unusable_system_temp(bytes, None, false) |
| 7 | +추가: } |
| 8 | +추가: fn extract_unusable_system_temp( |
| 9 | +추가: bytes: &[u8], |
| 10 | +추가: fault: Option<&str>, |
| 11 | +추가: file_at_temp_path: bool, |
| 12 | +추가: ) -> (Scratch, Vec<Message>) { |
| 6 | 13 | let s = Scratch::new(); |
| 7 | 14 | let start = encrypted_start(&s, bytes); |
| 8 | | -삭제: let mut child = s |
| 9 | | -삭제: .worker() |
| 10 | | -삭제: .env("TMPDIR", s.0.join("missing-temp")) |
| 15 | +추가: let temp = s.0.join("missing-temp"); |
| 16 | +추가: if file_at_temp_path { |
| 17 | +추가: fs::write(&temp, b"keep").unwrap(); |
| 18 | +추가: } |
| 19 | +추가: let mut command = s.worker(); |
| 20 | +추가: command.env("TMPDIR", &temp); |
| 21 | +추가: if let Some(fault) = fault { |
| 22 | +추가: let shim = s.0.join("io_fault.so"); |
| 23 | +추가: assert!( |
| 24 | +추가: Command::new("cc") |
| 25 | +추가: .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"]) |
| 26 | +추가: .arg( |
| 27 | +추가: PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 28 | +추가: .join("../../tests/rust-archive-worker/io_fault.c") |
| 29 | +추가: ) |
| 30 | +추가: .args(["-ldl", "-o"]) |
| 31 | +추가: .arg(&shim) |
| 32 | +추가: .status() |
| 33 | +추가: .unwrap() |
| 34 | +추가: .success() |
| 35 | +추가: ); |
| 36 | +추가: command |
| 37 | +추가: .env("LD_PRELOAD", shim) |
| 38 | +추가: .env("ZIPELO_TEST_FAULT", fault); |
| 39 | +추가: } |
| 40 | +추가: let mut child = command |
| 11 | 41 | .stdin(Stdio::piped()) |
| 12 | 42 | .stdout(Stdio::piped()) |
| 13 | 43 | .stderr(Stdio::piped()) |
| | @@ -37,7 +67,11 @@ fn extract_without_system_temp(bytes: &[u8]) -> (Scratch, Vec<Message>) { |
| 37 | 67 | let output = child.wait_with_output().unwrap(); |
| 38 | 68 | assert!(output.status.success(), "{:?}", output.stderr); |
| 39 | 69 | assert!(output.stderr.is_empty()); |
| 40 | | -삭제: assert!(!s.0.join("missing-temp").exists()); |
| 70 | +추가: if file_at_temp_path { |
| 71 | +추가: assert_eq!(fs::read(&temp).unwrap(), b"keep"); |
| 72 | +추가: } else { |
| 73 | +추가: assert!(!temp.exists()); |
| 74 | +추가: } |
| 41 | 75 | (s, events) |
| 42 | 76 | } |
| 43 | 77 | |
| | @@ -101,3 +135,48 @@ fn corrupt_archive_error_wins_over_read_only_destination() { |
| 101 | 135 | assert_eq!(terminal(&events).cleanup, Cleanup::Complete); |
| 102 | 136 | assert_eq!(fs::read_dir(&output).unwrap().count(), 0); |
| 103 | 137 | } |
| 138 | +추가: |
| 139 | +추가: #[test] |
| 140 | +추가: fn destination_space_or_quota_failure_survives_unusable_system_temp() { |
| 141 | +추가: let input = include_bytes!("fixtures/deflate.zip"); |
| 142 | +추가: for fault in [ |
| 143 | +추가: "destination-enospc", |
| 144 | +추가: "destination-edquot", |
| 145 | +추가: "destination-named-enospc", |
| 146 | +추가: "destination-named-edquot", |
| 147 | +추가: ] { |
| 148 | +추가: for file in [false, true] { |
| 149 | +추가: let (s, events) = extract_unusable_system_temp(input, Some(fault), file); |
| 150 | +추가: let terminal = terminal(&events); |
| 151 | +추가: assert_eq!( |
| 152 | +추가: terminal.outcome, |
| 153 | +추가: Outcome::Failed, |
| 154 | +추가: "{fault}/{file}: {events:?}" |
| 155 | +추가: ); |
| 156 | +추가: assert_eq!( |
| 157 | +추가: terminal.error, |
| 158 | +추가: ErrorCode::DiskFull, |
| 159 | +추가: "{fault}/{file}: {events:?}" |
| 160 | +추가: ); |
| 161 | +추가: assert_eq!(terminal.publication, Publication::None); |
| 162 | +추가: assert_eq!(terminal.cleanup, Cleanup::Complete); |
| 163 | +추가: assert_eq!(terminal.created_count, 0); |
| 164 | +추가: assert_only_outputs(&s, &[]); |
| 165 | +추가: assert_eq!(fs::read(s.0.join("input")).unwrap(), input); |
| 166 | +추가: } |
| 167 | +추가: } |
| 168 | +추가: } |
| 169 | +추가: |
| 170 | +추가: #[test] |
| 171 | +추가: fn destination_permission_failure_with_unusable_system_temp_stays_io() { |
| 172 | +추가: for file in [false, true] { |
| 173 | +추가: let (s, events) = extract_unusable_system_temp( |
| 174 | +추가: include_bytes!("fixtures/deflate.zip"), |
| 175 | +추가: Some("destination-denied"), |
| 176 | +추가: file, |
| 177 | +추가: ); |
| 178 | +추가: assert_eq!(terminal(&events).error, ErrorCode::Io, "{events:?}"); |
| 179 | +추가: assert_eq!(terminal(&events).outcome, Outcome::Failed); |
| 180 | +추가: assert_only_outputs(&s, &[]); |
| 181 | +추가: } |
| 182 | +추가: } |