Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/openshell-driver-mxc/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl MxcComputeBackend {
/// Test-only constructor wiring the in-process mock `wxc-exec` shim.
#[cfg(test)]
pub(crate) fn new_mocked(config: MxcComputeConfig) -> Self {
let mut backend = Self::new(config);
let mut backend = Self::new(openshell_core::config::DEFAULT_GATEWAY_NAME, config);
backend.invoker = WxcExecInvoker::mocked(&backend.config.wxc_exec_path);
backend
}
Expand Down
40 changes: 28 additions & 12 deletions crates/openshell-supervisor-network/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl BinaryIdentityCache {
mod tests {
use super::*;
use crate::procfs;
use crate::test_support::executable_path;
use openshell_isolation_interface::contract::{
BinaryIdentity, ExecutableIdentity, Sha256Digest,
};
Expand All @@ -294,19 +295,19 @@ mod tests {
}

fn supplied_identity(
executable_path: &str,
path: &str,
executable_digest: Option<&str>,
ancestors: &[(&str, Option<&str>)],
) -> BinaryIdentity {
BinaryIdentity {
executable: ExecutableIdentity {
path: PathBuf::from(executable_path),
path: executable_path(path),
digest: executable_digest.map(digest),
},
ancestors: ancestors
.iter()
.map(|(path, digest_value)| ExecutableIdentity {
path: PathBuf::from(path),
path: executable_path(path),
digest: digest_value.map(digest),
})
.collect(),
Expand Down Expand Up @@ -383,9 +384,22 @@ mod tests {
#[test]
fn supplied_identity_rejects_non_absolute_or_empty_paths() {
let cache = BinaryIdentityCache::new();
for path in ["", "sandbox/tool"] {
#[cfg(not(target_os = "windows"))]
let paths = ["", "sandbox/tool"];
#[cfg(target_os = "windows")]
let paths = [
"",
"sandbox/tool",
"C:sandbox/tool",
"/sandbox/tool",
r"\sandbox\tool",
];
for path in paths {
let mut identity = supplied_identity(path, Some("11"), &[]);
// Exercise the raw invalid path, without adapting the fixture.
identity.executable.path = PathBuf::from(path);
let error = cache
.verify_or_cache_supplied_identity(&supplied_identity(path, Some("11"), &[]))
.verify_or_cache_supplied_identity(&identity)
.unwrap_err()
.to_string();
assert!(error.contains("must be absolute"));
Expand Down Expand Up @@ -450,7 +464,7 @@ mod tests {
.hashes
.lock()
.unwrap()
.contains_key(Path::new("/sandbox/other"))
.contains_key(&executable_path("/sandbox/other"))
);
}

Expand Down Expand Up @@ -480,8 +494,8 @@ mod tests {
assert!(error.contains("capacity"));
let hashes = cache.hashes.lock().unwrap();
assert_eq!(hashes.len(), 4095);
assert!(!hashes.contains_key(Path::new("/sandbox/new-leaf")));
assert!(!hashes.contains_key(Path::new("/sandbox/new-ancestor")));
assert!(!hashes.contains_key(&executable_path("/sandbox/new-leaf")));
assert!(!hashes.contains_key(&executable_path("/sandbox/new-ancestor")));
}

#[test]
Expand All @@ -491,17 +505,19 @@ mod tests {
for index in 0..4096 {
cache
.verify_or_cache_with_paths(
&PathBuf::from(format!("/sandbox/pinned-{index}")),
&executable_path(&format!("/sandbox/pinned-{index}")),
executable.path(),
|_| Ok("11".repeat(32)),
)
.unwrap();
}

let error = cache
.verify_or_cache_with_paths(Path::new("/sandbox/overflow"), executable.path(), |_| {
Ok("11".repeat(32))
})
.verify_or_cache_with_paths(
&executable_path("/sandbox/overflow"),
executable.path(),
|_| Ok("11".repeat(32)),
)
.unwrap_err()
.to_string();

Expand Down
2 changes: 1 addition & 1 deletion crates/openshell-supervisor-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ pub(crate) use openshell_driver_vm::allocation_tracking as test_alloc;
#[global_allocator]
static TEST_ALLOCATOR: openshell_driver_vm::allocation_tracking::CountingAllocator =
openshell_driver_vm::allocation_tracking::CountingAllocator;
#[cfg(all(test, target_os = "linux"))]
#[cfg(test)]
mod test_support;
Loading
Loading