Browse Source

Check if accounts have valid hook names

ng
Rodolphe Bréard 4 weeks ago
parent
commit
f319e4c38b
Failed to extract signature
  1. 43
      src/config.rs

43
src/config.rs

@ -64,6 +64,15 @@ impl<'de> Deserialize<'de> for AcmedConfig {
}
}
}
for account in unchecked.account.values() {
for hook_name in &account.hooks {
if !unchecked.hook.contains_key(hook_name)
&& !unchecked.group.contains_key(hook_name)
{
return Err(de::Error::custom(format!("{hook_name}: hook not found")));
}
}
}
Ok(unchecked)
}
}
@ -268,4 +277,38 @@ internal-grp = ["internaltest"]
let res = load("tests/config/hook_404");
assert!(res.is_err());
}
#[test]
fn hook_account() {
let cfg = r#"
[hook."test"]
cmd = "cat"
type = ["file-pre-edit"]
[account."toto"]
contacts = [
{ mailto = "acme@example.org" },
]
hooks = ["test"]
"#;
let res = load_str::<AcmedConfig>(cfg);
assert!(res.is_ok());
}
#[test]
fn hook_404_account() {
let cfg = r#"
[hook."test"]
cmd = "cat"
type = ["file-pre-edit"]
[account."toto"]
contacts = [
{ mailto = "acme@example.org" },
]
hooks = ["not-found"]
"#;
let res = load_str::<AcmedConfig>(cfg);
assert!(res.is_err());
}
}
Loading…
Cancel
Save