#[cfg(test)]
mod tests {
use std::fs;
use std::path::PathBuf;
fn repo_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
}
#[test]
fn deny_open_permission_is_defined() {
let open =
fs::read_to_string(repo_root().join("permissions/autogenerated/commands/open.toml"))
.expect("open.toml");
assert!(
open.contains("identifier = \"deny-open\""),
"deny-open missing from open.toml"
);
assert!(
open.contains("commands.deny = [\"open\"]"),
"deny-open must deny the open command"
);
assert!(
open.contains("identifier = \"allow-open\""),
"allow-open missing from open.toml"
);
assert!(
open.contains("commands.allow = [\"open\"]"),
"allow-open must allow the open command"
);
}
#[test]
fn default_capability_includes_allow_open_not_deny() {
let default =
fs::read_to_string(repo_root().join("permissions/default.toml")).expect("default.toml");
assert!(
default.contains("\"allow-open\""),
"default set must grant allow-open"
);
assert!(
!default.contains("\"deny-open\""),
"default set must not include deny-open"
);
}
#[test]
fn example_app_capability_grants_serialplugin_default_or_allow_open() {
let json = fs::read_to_string(
repo_root().join("examples/serialport-test/src-tauri/capabilities/default.json"),
)
.expect("example capability");
let value: serde_json::Value = serde_json::from_str(&json).expect("parse capability");
let perms = value["permissions"]
.as_array()
.expect("permissions array")
.iter()
.filter_map(|v| v.as_str())
.collect::<Vec<_>>();
assert!(
perms
.iter()
.any(|p| *p == "serialplugin:default" || *p == "serialplugin:allow-open"),
"example capability must include serialplugin:default or allow-open, got {perms:?}"
);
}
}