Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: test fails in chroot environment #300

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading