mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-11-28 16:54:14 +00:00
cover the message cap's lifecycle on WebSocket and WebRTC
The cap's header-only refusal was tested on the TCP codec and its reassembly bound on WebRTC, but not on WebSocket, which is the transport where a frame header buys an allocation, and neither transport had a test that lifting the cap lets a large message through again - the half of the lifecycle a server runs at authorization, and the one a forgotten restore would break silently. Two WebSocket tests build a loopback from a raw TcpStream with no handshake, write server-to-client frames by hand, and check that a header declaring one byte over the cap is refused before any payload exists, and that a message refused under a low cap arrives once the cap is lifted. A WebRTC test does the same lift. Each fails when the corresponding half of set_max_packet_length is made a no-op. The doc on Stream::set_max_packet_length now says the one thing the bound does not do: lowering it applies from the next frame on and does not discard one whose decoding or reassembly has already begun, so it has to be set before the first read of untrusted data. That is how the server uses it; the note is there so nothing later treats it as a switch that can be thrown at any time. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab
This commit is contained in:
1 parent
0eb175963c
commit
e999dcea24
3 files changed
+98
No files matched your search
@@ -2427,6 +2427,35 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc
|
||||
.expect("WebRTC loopback did not complete in time");
|
||||
}
|
||||
|
||||
// The other half of the same lifecycle: what was refused while the bound was low arrives once
|
||||
// it is lifted, which is what authorization does on the server.
|
||||
#[tokio::test]
|
||||
async fn test_webrtc_max_packet_length_restores() {
|
||||
let body = async {
|
||||
let (mut offerer, mut answerer) = connect_loopback().await;
|
||||
answerer.set_max_packet_length(16 * 1024);
|
||||
|
||||
offerer.send_raw(vec![0xCDu8; 8 * 1024]).await.unwrap();
|
||||
let got = answerer.next().await.unwrap().unwrap();
|
||||
assert_eq!(got.len(), 8 * 1024);
|
||||
|
||||
answerer.set_max_packet_length(usize::MAX);
|
||||
offerer.send_raw(vec![0xCDu8; 200_000]).await.unwrap();
|
||||
let got = timeout(Duration::from_secs(10), answerer.next())
|
||||
.await
|
||||
.expect("answerer.next() hung after the bound was lifted")
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(got.len(), 200_000, "lifting the bound lets a large message through again");
|
||||
|
||||
offerer.close().await;
|
||||
answerer.close().await;
|
||||
};
|
||||
timeout(Duration::from_secs(60), body)
|
||||
.await
|
||||
.expect("WebRTC loopback did not complete in time");
|
||||
}
|
||||
|
||||
// In-process offerer<->answerer loopback exercising the send/next data plane that the framing,
|
||||
// empty-message, and EOF fixes live in. Connects over host candidates (works offline; any
|
||||
// configured/default STUN just fails in the background without blocking the host pair).
|
||||
|
||||
Reference in new issue
Block a user