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.
This commit is contained in:
parent
cbbf3f6baa
commit
c9d85d9ae5
4 changed files with 105 additions and 18 deletions
39
tests/dispatch.rs
Normal file
39
tests/dispatch.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
//! 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);
|
||||
}
|
||||
Loading…
Reference in a new issue