2026-09-10 14:18:06 -04:00
|
|
|
//! 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);
|
2026-09-12 22:53:58 -04:00
|
|
|
assert_eq!(classify(b"tip tx"), Kind::Tip);
|
2026-09-10 14:18:06 -04:00
|
|
|
assert_eq!(classify(b"png 1"), Kind::Ping);
|
|
|
|
|
}
|
|
|
|
|
|
chat: send and receive as ratchet frames through the outbox payload
Chat plaintext is ratchet-encrypted once, before the first delivery attempt,
and the frame is what the outbox stores and retries, so a retried message
re-sends identical bytes instead of advancing the sending chain twice.
- dispatch: Kind::Ratchet for the `rat ` prefix, matched before the unknown
[a-z]{3} prefix rule
- node: encode_chat_frame / ingest_chat_frame (the wire halves of Node::send
and handle_incoming), bootstrap derived from the peers' static prekey DH
because the Noise handshake is frozen and carries no ratchet key
- outbox: nullable outbox.payload + Outbox::send_payload; NULL payload keeps
the previous row-for-row behaviour
- store: additive outbox.payload migration, enqueue_outbox_payload,
OutboxEntry::payload
- add_friend_payload: a changed prekey clears the (prekey-bound) ratchet state
tests/ratchet_wire.rs (5) covers one frame per send, byte-identical retries,
out-of-order delivery, replay, tampering and fresh-friend both directions.
tests/tui_spec.rs and crates/onionwire-sdk/src/lib.rs only gained a
`payload: None` field in their OutboxEntry test fixtures: the card's required
field on a pub struct cannot be added without it.
2026-09-16 19:02:52 -04:00
|
|
|
#[test]
|
|
|
|
|
fn ratchet_frame_is_ratchet() {
|
|
|
|
|
// `rat ` is a typed prefix, not chat: the plaintext is a ratchet frame.
|
|
|
|
|
assert_eq!(classify(b"rat \x01rest-of-frame"), Kind::Ratchet);
|
|
|
|
|
// Matched before the unknown-lowercase-prefix rule, which would Drop it.
|
|
|
|
|
assert_eq!(classify(b"rat x"), Kind::Ratchet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn unknown_lowercase_prefix_still_drops() {
|
|
|
|
|
assert_eq!(classify(b"rax not a real type"), Kind::Drop);
|
|
|
|
|
assert_eq!(classify(b"rat"), Kind::Chat, "3 letters is not a prefix");
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-10 14:18:06 -04:00
|
|
|
#[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);
|
|
|
|
|
}
|