onionwire/tests/dispatch.rs
Sirius DevOps c9d85d9ae5
Some checks failed
ci / test (push) Has been cancelled
release / aarch64 (push) Failing after 2m8s
feat: drop unknown typed frames instead of storing as chat
Classify decrypted plaintext before append_message so loc/prf/inv/rcp/png
and unknown xxx[space] prefixes never land in the message log.
2026-09-10 14:18:06 -04:00

39 lines
1,011 B
Rust

//! M6: typed-frame dispatcher — classify before append_message.
use onionwire::dispatch::{classify, Kind};
#[test]
fn chat_is_chat() {
assert_eq!(classify(b"hello wire"), Kind::Chat);
}
#[test]
fn loc_still_loc() {
assert_eq!(classify(b"loc abc.onion\n1\n00"), Kind::Loc);
}
#[test]
fn unknown_typed_prefix_is_drop() {
assert_eq!(classify(b"zzz not a real type"), Kind::Drop);
}
#[test]
fn short_or_binary_without_prefix_is_chat() {
assert_eq!(classify(b"hi"), Kind::Chat);
assert_eq!(classify(&[0xff, 0xfe]), Kind::Chat);
}
#[test]
fn known_prefixes_are_typed() {
assert_eq!(classify(b"prf name"), Kind::Profile);
assert_eq!(classify(b"inv 1"), Kind::Invoice);
assert_eq!(classify(b"rcp tx"), Kind::Receipt);
assert_eq!(classify(b"png 1"), Kind::Ping);
}
#[test]
fn uppercase_or_digit_prefix_is_chat() {
assert_eq!(classify(b"ZZZ not typed"), Kind::Chat);
assert_eq!(classify(b"ab1 leftover"), Kind::Chat);
assert_eq!(classify(b"abcd"), Kind::Chat);
}