69 lines
2.0 KiB
Rust
69 lines
2.0 KiB
Rust
//! `[approvals]` in `gatewayd.toml`: who may answer, the first approver, and `gateway.sock`
|
|
//! (M4b spec, section 3). Do not edit.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use gatewayd::config::Config;
|
|
|
|
const KYLE: &str = "k0000000000000000000000000";
|
|
const HERMES: &str = "h0000000000000000000000000";
|
|
const OTHER: &str = "o0000000000000000000000000";
|
|
|
|
fn text(approvals: &str) -> String {
|
|
format!(
|
|
"[mattermost]\nurl = \"https://chat.example\"\n[secrets.mattermost_token]\nenv = \"T\"\n[allow]\nusers = [\"{KYLE}\", \"{HERMES}\"]\n[paths]\nhome = \"/srv/bx\"\n{approvals}"
|
|
)
|
|
}
|
|
|
|
fn config(approvals: &str) -> Config {
|
|
let c = Config::parse(&text(approvals)).unwrap();
|
|
assert_eq!(c.problem(), None);
|
|
c
|
|
}
|
|
|
|
#[test]
|
|
fn without_the_section_everyone_allowed_may_answer() {
|
|
let c = config("");
|
|
assert_eq!(c.approvers(), [KYLE, HERMES]);
|
|
assert_eq!(c.first_approver(), Some(KYLE));
|
|
assert_eq!(
|
|
c.gateway_socket(),
|
|
PathBuf::from("/srv/bx/run/gateway/gateway.sock")
|
|
);
|
|
assert_eq!(
|
|
config("[approvals]\nusers = []\n").approvers(),
|
|
[KYLE, HERMES]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_list_narrows_who_may_answer() {
|
|
let c = config(&format!(
|
|
"[approvals]\nusers = [\"{HERMES}\"]\nsocket = \"/run/gw.sock\"\n"
|
|
));
|
|
assert_eq!(c.approvers(), [HERMES]);
|
|
assert_eq!(c.first_approver(), Some(HERMES));
|
|
assert_eq!(c.gateway_socket(), PathBuf::from("/run/gw.sock"));
|
|
}
|
|
|
|
#[test]
|
|
fn an_approver_must_be_heard() {
|
|
let c = Config::parse(&text(&format!(
|
|
"[approvals]\nusers = [\"{KYLE}\", \"{OTHER}\"]\n"
|
|
)))
|
|
.unwrap();
|
|
let why = c.problem().expect("refused");
|
|
assert_eq!(
|
|
why,
|
|
format!(
|
|
"[approvals] \"{OTHER}\" is not in [allow] users: an approver who is not heard could never answer"
|
|
)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn unknown_keys_are_errors() {
|
|
assert!(Config::parse(&text("[approvals]\napprovers = []\n")).is_err());
|
|
assert!(Config::parse(&text("[approvals]\nusers = []\nttl = 5\n")).is_err());
|
|
}
|