M9: oversized-message test sends only the frame header (no broken pipe on Linux)

This commit is contained in:
bflatastic 2026-10-12 11:25:52 +07:00
parent d74eeb4ab3
commit 7d078e9bd8
2 changed files with 12 additions and 5 deletions

View File

@ -332,7 +332,7 @@ fn messages_are_capped_by_what_the_connection_is_for() {
let mut raw = Raw::connect(addr);
raw.send(&ClientMsg::OpenPlugins(OpenPlugins { protocol: PROTOCOL, key: String::new(), client_version: String::new() }));
raw.next();
raw.send(&ClientMsg::Plugins(PluginReq::List { query: "q".repeat(200_000) }));
raw.send_header(200_000);
assert!(matches!(raw.next(), ServerMsg::Refused { reason } if reason.contains("too large") && reason.contains("KiB")));
drop(raw);
// A joined client whose batch is bigger than a file may be is told the limit.
@ -349,10 +349,7 @@ fn messages_are_capped_by_what_the_connection_is_for() {
let mut joined = Raw::connect(addr);
joined.send(&Client::hello(&file.id, &edit.token, "Big", ""));
while !matches!(joined.next(), ServerMsg::Welcome { .. }) {}
joined.send(&ClientMsg::Presence(figcraft_collab::Presence {
selection: Some((0..5_000_000u64).map(|i| NodeId(i + (1 << 40))).collect()),
..Default::default()
}));
joined.send_header(40 << 20);
let reason = loop {
if let ServerMsg::Refused { reason } = joined.next() {
break reason;

View File

@ -123,6 +123,16 @@ impl Raw {
self.0.send(Message::Binary(Bytes::from(message::encode(m).unwrap()))).unwrap();
}
/// Write just the header of a masked binary frame declaring `len` payload bytes: the server
/// refuses an oversized message from its header, before the client would push the payload
/// into a socket the server has already closed (a broken pipe on Linux).
pub fn send_header(&mut self, len: u64) {
let mut h = vec![0x82u8, 0x80 | 127];
h.extend_from_slice(&len.to_be_bytes());
h.extend_from_slice(&[1, 2, 3, 4]);
self.raw_write(&h);
}
/// Write raw bytes on the socket (a hand-made, partial frame).
pub fn raw_write(&mut self, bytes: &[u8]) {
use std::io::Write as _;