chanlog: filter each log channel by snomask category; repeatable so different snomasks route to different channels

This commit is contained in:
Jean Chevronnet 2026-08-21 17:11:27 +00:00
parent 7cb9256ff5
commit b8e24e2071
No known key found for this signature in database
GPG key ID: 439666D63A9477E4
3 changed files with 64 additions and 18 deletions

View file

@ -1034,7 +1034,7 @@ impl Server {
for o in opers {
self.deliver_server_notice(o, msg, &jval);
}
crate::modules::chanlog::tee(self, msg);
crate::modules::chanlog::tee(self, cat, msg);
crate::modules::syslog::tee(self, msg);
crate::modules::log_json::tee(self, msg);
}
@ -1655,6 +1655,30 @@ mod tests {
assert!(joined.contains("XLINE: Z-line on 192.0.2.5 expired"), "expire: {joined}");
}
#[test]
fn chanlog_routes_by_snomask() {
use crate::channels::{Channel, Member};
let mut s = srv();
// #xlog takes only x-line (x) notices; #all takes every category
s.raw_config.insert("chanlog".to_string(), vec!["#xlog x".to_string(), "#all".to_string()]);
let rx = add_user(&mut s, 1, "logbot");
for name in ["#xlog", "#all"] {
let mut c = Channel::new(name);
c.members.insert(1, Member::default());
s.channels.insert(name.to_string(), c);
}
s.snotice_c('x', "XLINEMSG");
s.snotice_c('c', "CONNMSG");
let lines: Vec<String> = std::iter::from_fn(|| rx.try_recv().ok()).collect();
let logged = |chan: &str, needle: &str| {
lines.iter().any(|l| l.contains(&format!("NOTICE {chan} :")) && l.contains(needle))
};
assert!(logged("#xlog", "XLINEMSG"), "x-line notice goes to #xlog: {lines:?}");
assert!(logged("#all", "XLINEMSG"), "x-line notice goes to #all: {lines:?}");
assert!(!logged("#xlog", "CONNMSG"), "connect notice filtered out of #xlog: {lines:?}");
assert!(logged("#all", "CONNMSG"), "connect notice goes to #all: {lines:?}");
}
#[test]
fn banned_user_message_shows_expiry() {
let mut s = srv();