Browse Source

Check if groups have valid hook names

ng
Rodolphe Bréard 4 weeks ago
parent
commit
78bd0821f9
Failed to extract signature
  1. 22
      src/config.rs
  2. 6
      tests/config/hook_404/hook.toml
  3. 4
      tests/config/override/00_initial.toml
  4. 3
      tests/config/override/01_override.toml

22
src/config.rs

@ -54,10 +54,15 @@ impl<'de> Deserialize<'de> for AcmedConfig {
return Err(de::Error::custom(format!("{key}: invalid hook name")));
}
}
for key in unchecked.group.keys() {
for (key, hook_lst) in &unchecked.group {
if key.starts_with(crate::INTERNAL_HOOK_PREFIX) {
return Err(de::Error::custom(format!("{key}: invalid group name")));
}
for hook_name in hook_lst {
if !unchecked.hook.contains_key(hook_name) {
return Err(de::Error::custom(format!("{hook_name}: hook not found")));
}
}
}
Ok(unchecked)
}
@ -194,7 +199,6 @@ mod tests {
);
assert!(cfg.rate_limit.is_empty());
assert_eq!(cfg.endpoint.len(), 2);
println!("Debug: cfg.endpoint: {:?}", cfg.endpoint);
let ac1 = cfg.endpoint.get("test ac 1").unwrap();
assert_eq!(ac1.url, "https://acme-v02.ac1.example.org/directory");
assert_eq!(ac1.tos_agreed, true);
@ -205,8 +209,12 @@ mod tests {
assert_eq!(ac2.tos_agreed, false);
assert_eq!(ac2.random_early_renew, Some(Duration::from_secs(10)));
assert_eq!(ac2.root_certificates, vec![PathBuf::from("test.pem")]);
assert!(cfg.hook.is_empty());
assert!(cfg.group.is_empty());
assert_eq!(cfg.hook.len(), 1);
let h = cfg.hook.get("test-hook").unwrap();
assert_eq!(h.cmd, "cat");
assert_eq!(cfg.group.len(), 1);
let g = cfg.group.get("test-grp").unwrap();
assert_eq!(*g, vec!["test-hook".to_string()]);
assert_eq!(cfg.account.len(), 1);
let account = cfg.account.get("example").unwrap();
assert_eq!(account.contacts.len(), 1);
@ -254,4 +262,10 @@ internal-grp = ["internaltest"]
let res = load_str::<AcmedConfig>(cfg);
assert!(res.is_ok());
}
#[test]
fn hook_404() {
let res = load("tests/config/hook_404");
assert!(res.is_err());
}
}

6
tests/config/hook_404/hook.toml

@ -0,0 +1,6 @@
[hook."test-hook"]
cmd = "cat"
type = ["file-post-edit"]
[group]
test-grp = ["test-hook", "invalid-name"]

4
tests/config/override/00_initial.toml

@ -13,3 +13,7 @@ url = "https://acme-v02.ac2.example.org/directory"
contacts = [
{ mailto = "acme@example.org" },
]
[hook."test-hook"]
cmd = "cat"
type = ["file-post-edit"]

3
tests/config/override/01_override.toml

@ -6,3 +6,6 @@ endpoint."test AC 1".tos_agreed = true
[endpoint."test AC 2"]
root_certificates = ["test.pem"]
[group]
test-grp = ["test-hook"]
Loading…
Cancel
Save