use std::path::PathBuf;
#[cfg(windows)]
use super::status::WindowsStatus;
#[derive(Debug)]
pub(crate) struct Runner {
pub(crate) exe: PathBuf,
pub(crate) dacl_allows: Option<bool>,
}
impl Runner {
#[cfg(windows)]
pub(crate) fn of(exe: PathBuf, status: Option<&WindowsStatus>) -> Self {
let sids = status.map_or_else(Vec::new, |status| status.sandbox_sids());
Self {
dacl_allows: super::ffi::sandbox_can_read(&exe, &sids),
exe,
}
}
pub(crate) fn readable(&self) -> bool {
self.dacl_allows.unwrap_or(true)
}
}
#[cfg(test)]
mod tests {
use super::*;
fn runner(dacl_allows: Option<bool>) -> Runner {
Runner {
exe: PathBuf::from(r"C:\Users\runneradmin\.cargo\bin\crabpot.exe"),
dacl_allows,
}
}
#[test]
fn a_file_the_check_read_as_granted_is_readable() {
assert!(runner(Some(true)).readable());
}
#[test]
fn a_file_the_check_read_as_denied_is_not_readable() {
assert!(!runner(Some(false)).readable());
}
#[test]
fn a_check_the_machine_could_not_make_refuses_nothing() {
assert!(runner(None).readable());
}
}