39 lines
1.4 KiB
Rust
39 lines
1.4 KiB
Rust
// file: crates/ksp-app-wallet-desk/tests/desktop_security.rs
|
|
// version: 1
|
|
|
|
//! Static desktop security contracts for the Wallet Desk pre.002 shell.
|
|
|
|
fn app_root() -> std::path::PathBuf {
|
|
return std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
}
|
|
|
|
fn read_text(path: &std::path::Path) -> String {
|
|
let source = std::fs::read_to_string(path);
|
|
assert!(source.is_ok(), "unable to read {}", path.display());
|
|
return match source {
|
|
std::result::Result::Ok(value) => value,
|
|
std::result::Result::Err(_) => String::new(),
|
|
};
|
|
}
|
|
|
|
#[test]
|
|
fn initial_capability_surface_is_core_plus_tracing_only() {
|
|
let root = app_root();
|
|
let capability = read_text(root.join("capabilities/default.json").as_path());
|
|
assert!(capability.contains("\"core:default\""));
|
|
assert!(capability.contains("\"tracing:default\""));
|
|
assert!(!capability.contains("dialog:"));
|
|
assert!(!capability.contains("fs:"));
|
|
}
|
|
|
|
#[test]
|
|
fn frontend_shell_uses_no_browser_native_dialog_or_secret_storage() {
|
|
let root = app_root();
|
|
let main = read_text(root.join("frontend/ts/main.ts").as_path());
|
|
let html = read_text(root.join("frontend/main.html").as_path());
|
|
for forbidden in ["window.alert", "window.confirm", "window.prompt", "localStorage", "sessionStorage"] {
|
|
assert!(!main.contains(forbidden), "forbidden frontend primitive {forbidden}");
|
|
assert!(!html.contains(forbidden), "forbidden frontend primitive {forbidden}");
|
|
}
|
|
}
|