| | @@ -225,3 +225,103 @@ fn invalid_descendant_names_and_case_collisions_fail_before_password() { |
| 225 | 225 | fs::remove_file(s.0.join("tree").join(leaf)).unwrap(); |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | +추가: |
| 229 | +추가: #[cfg(target_os = "linux")] |
| 230 | +추가: fn readable_sources_under_parent(mode: u32) { |
| 231 | +추가: use std::os::unix::fs::PermissionsExt; |
| 232 | +추가: struct RestoreParent(PathBuf); |
| 233 | +추가: impl Drop for RestoreParent { |
| 234 | +추가: fn drop(&mut self) { |
| 235 | +추가: fs::set_permissions(&self.0, fs::Permissions::from_mode(0o700)).unwrap(); |
| 236 | +추가: } |
| 237 | +추가: } |
| 238 | +추가: let s = Scratch::new(); |
| 239 | +추가: let parent = s.0.join("restricted"); |
| 240 | +추가: fs::create_dir_all(parent.join("tree/empty")).unwrap(); |
| 241 | +추가: fs::write(parent.join("loose"), b"readable file").unwrap(); |
| 242 | +추가: fs::write(parent.join("tree/nested"), b"nested content").unwrap(); |
| 243 | +추가: let _restore = RestoreParent(parent.clone()); |
| 244 | +추가: fs::set_permissions(&parent, fs::Permissions::from_mode(mode)).unwrap(); |
| 245 | +추가: if mode == 0o111 { |
| 246 | +추가: assert_eq!( |
| 247 | +추가: fs::read_dir(&parent).unwrap_err().kind(), |
| 248 | +추가: std::io::ErrorKind::PermissionDenied |
| 249 | +추가: ); |
| 250 | +추가: } else { |
| 251 | +추가: assert!(fs::read_dir(&parent).is_ok()); |
| 252 | +추가: } |
| 253 | +추가: assert_eq!(fs::read(parent.join("loose")).unwrap(), b"readable file"); |
| 254 | +추가: for (name, encryption) in [("plain", Encryption::None), ("aes", Encryption::Aes256)] { |
| 255 | +추가: let archive_name = format!("{name}.zip"); |
| 256 | +추가: let events = interactive( |
| 257 | +추가: Start { |
| 258 | +추가: action: Action::CreateZip { |
| 259 | +추가: sources: vec![ |
| 260 | +추가: Source { |
| 261 | +추가: path: NativePath::from_path(&parent.join("loose")), |
| 262 | +추가: archive_name: "loose.txt".into(), |
| 263 | +추가: }, |
| 264 | +추가: Source { |
| 265 | +추가: path: NativePath::from_path(&parent.join("tree")), |
| 266 | +추가: archive_name: "tree".into(), |
| 267 | +추가: }, |
| 268 | +추가: ], |
| 269 | +추가: output_file: s.path(&archive_name), |
| 270 | +추가: method: Method::Deflate, |
| 271 | +추가: encryption, |
| 272 | +추가: }, |
| 273 | +추가: limits: Limits::default(), |
| 274 | +추가: }, |
| 275 | +추가: |id, _, _| { |
| 276 | +추가: vec![Message::Password { |
| 277 | +추가: challenge_id: id, |
| 278 | +추가: secret: Secret(b"parent-password".to_vec()), |
| 279 | +추가: }] |
| 280 | +추가: }, |
| 281 | +추가: ); |
| 282 | +추가: assert_eq!(terminal(&events).outcome, Outcome::Completed, "{events:?}"); |
| 283 | +추가: let output = format!("output-{name}"); |
| 284 | +추가: fs::create_dir(s.0.join(&output)).unwrap(); |
| 285 | +추가: fs::set_permissions(s.0.join(&output), fs::Permissions::from_mode(0o700)).unwrap(); |
| 286 | +추가: let extracted = interactive( |
| 287 | +추가: Start { |
| 288 | +추가: action: Action::Extract { |
| 289 | +추가: archive: s.path(&archive_name), |
| 290 | +추가: destination: s.path(&output), |
| 291 | +추가: selection: Selection::All, |
| 292 | +추가: list_id: None, |
| 293 | +추가: gzip_output_name: None, |
| 294 | +추가: }, |
| 295 | +추가: limits: Limits::default(), |
| 296 | +추가: }, |
| 297 | +추가: |id, _, _| { |
| 298 | +추가: vec![Message::Password { |
| 299 | +추가: challenge_id: id, |
| 300 | +추가: secret: Secret(b"parent-password".to_vec()), |
| 301 | +추가: }] |
| 302 | +추가: }, |
| 303 | +추가: ); |
| 304 | +추가: assert_eq!( |
| 305 | +추가: terminal(&extracted).outcome, |
| 306 | +추가: Outcome::Completed, |
| 307 | +추가: "{extracted:?}" |
| 308 | +추가: ); |
| 309 | +추가: for (source, destination) in [("loose", "loose.txt"), ("tree/nested", "tree/nested")] { |
| 310 | +추가: assert_eq!( |
| 311 | +추가: Sha256::digest(fs::read(parent.join(source)).unwrap()), |
| 312 | +추가: Sha256::digest(fs::read(s.0.join(&output).join(destination)).unwrap()) |
| 313 | +추가: ); |
| 314 | +추가: } |
| 315 | +추가: assert!(s.0.join(&output).join("tree/empty").is_dir()); |
| 316 | +추가: } |
| 317 | +추가: } |
| 318 | +추가: #[cfg(target_os = "linux")] |
| 319 | +추가: #[test] |
| 320 | +추가: fn readable_sources_under_search_only_parent_0111() { |
| 321 | +추가: readable_sources_under_parent(0o111); |
| 322 | +추가: } |
| 323 | +추가: #[cfg(target_os = "linux")] |
| 324 | +추가: #[test] |
| 325 | +추가: fn readable_sources_under_readable_parent_0711() { |
| 326 | +추가: readable_sources_under_parent(0o711); |
| 327 | +추가: } |