Skip to content

Commit

Permalink
Merge pull request #300 from kyoheiu/fix/test_has_write_permission
Browse files Browse the repository at this point in the history
Fix: test fails in chroot environment
  • Loading branch information
kyoheiu authored Dec 29, 2024
2 parents 1adf529 + 6c444d0 commit 33b3628
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2050,21 +2050,22 @@ mod tests {

#[test]
fn test_has_write_permission() {
// chmod to 444 and check if it's read-only
let p = std::path::PathBuf::from("./testfiles/permission_test");
let _status = std::process::Command::new("chmod")
.args(["444", "./testfiles/permission_test"])
.status()
.unwrap();
assert!(!has_write_permission(p.as_path()).unwrap());
let _status = std::process::Command::new("chmod")
.args(["755", "./testfiles/permission_test"])
.status()
.unwrap();

// Test the home directory, which should pass
assert!(has_write_permission(&p).unwrap());

// chmod to 444 and check if it's read-only
let mut perms = std::fs::metadata(&p).unwrap().permissions();
perms.set_readonly(true);
std::fs::set_permissions(&p, perms.clone()).unwrap();
assert!(!has_write_permission(&p).unwrap());

// HOME_DIR should pass as writable
let home_dir = dirs::home_dir().unwrap();
assert!(has_write_permission(&home_dir).unwrap());

// Set the file writable
perms.set_readonly(false);
std::fs::set_permissions(&p, perms).unwrap();
}

#[test]
Expand Down

0 comments on commit 33b3628

Please sign in to comment.