PreToolUse answers {} when no rule stopped a call: permissionDecision allow skipped Claude
Code's own prompt. allow_prefixes now only skips fermata's ask rules. PowerShell and Monitor
commands reach [policy.bash]. SCHEMA_VALUES covers the remaining getters of 2.1.314, Artifact
refuses in its read form, and data beside a binary type stays only in a top-level block.
62 lines
2.2 KiB
Rust
62 lines
2.2 KiB
Rust
use dirigent_fermata::core::{Decision, Policy};
|
|
use std::fs;
|
|
use tempfile::TempDir;
|
|
|
|
fn project_with(botsecrets: &str) -> TempDir {
|
|
let tmp = TempDir::new().unwrap();
|
|
fs::write(tmp.path().join(".botsecrets"), botsecrets).unwrap();
|
|
tmp
|
|
}
|
|
|
|
#[test]
|
|
fn deny_substring_blocks() {
|
|
let tmp = project_with("[policy.bash]\ndeny = [\"rm -rf /\"]\n");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert!(matches!(p.check_command("sudo rm -rf / now").unwrap(), Decision::Deny(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn deny_glob_blocks() {
|
|
let tmp = project_with("[policy.bash]\ndeny = [\"git push --force*\"]\n");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert!(matches!(p.check_command("git push --force-with-lease").unwrap(), Decision::Deny(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn ask_returns_ask() {
|
|
let tmp = project_with("[policy.bash]\nask = [\"rm *\"]\n");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert!(matches!(p.check_command("rm somefile").unwrap(), Decision::Ask(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn allow_prefixes_allows() {
|
|
let tmp = project_with("[policy.bash]\nallow_prefixes = [\"make test\"]\n");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert_eq!(p.check_command("make test").unwrap(), Decision::Allow);
|
|
assert_eq!(p.check_command("make test-unit").unwrap(), Decision::Allow);
|
|
}
|
|
|
|
#[test]
|
|
fn no_rules_means_allow() {
|
|
let tmp = project_with("");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert_eq!(p.check_command("anything goes").unwrap(), Decision::Allow);
|
|
}
|
|
|
|
#[test]
|
|
fn deny_takes_precedence_over_allow_prefix() {
|
|
let tmp = project_with("[policy.bash]\ndeny = [\"rm -rf /\"]\nallow_prefixes = [\"rm\"]\n");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert!(matches!(p.check_command("rm -rf /").unwrap(), Decision::Deny(_)));
|
|
}
|
|
|
|
/// `allow_prefixes` skips fermata's own `ask` rules, and nothing else.
|
|
#[test]
|
|
fn an_allow_prefix_skips_the_ask_rule() {
|
|
let tmp = project_with("[policy.bash]\nallow_prefixes = [\"docker ps\"]\nask = [\"docker\"]\n");
|
|
let p = Policy::load(tmp.path()).unwrap();
|
|
assert!(matches!(p.check_command("docker ps -a").unwrap(), Decision::Allow));
|
|
assert!(matches!(p.check_command("docker rm x").unwrap(), Decision::Ask(_)));
|
|
}
|