Fix stale client rejection and terminal cursor mode
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
Codex
2026-06-11 14:14:15 -04:00
parent 8ffbb07bfa
commit 14cdd5fd56
3 changed files with 80 additions and 6 deletions
+41 -2
View File
@@ -8,8 +8,8 @@ use dosh::auth::{build_bootstrap, load_or_create_server_secret};
use dosh::config::load_server_config;
use dosh::crypto;
use dosh::protocol::{
self, AttachOk, BootstrapAttachRequest, CLIENT_TO_SERVER, Frame, Input, PacketKind, Resize,
ResumeRequest, SERVER_TO_CLIENT,
self, AttachOk, AttachReject, BootstrapAttachRequest, CLIENT_TO_SERVER, Frame, Input,
PacketKind, Resize, ResumeRequest, SERVER_TO_CLIENT,
};
fn free_udp_port() -> u16 {
@@ -176,6 +176,45 @@ fn collect_frame_text(socket: &UdpSocket, key: &[u8; 32], millis: u64) -> String
text
}
#[test]
fn unknown_live_client_gets_reject() {
let dir = tempfile::tempdir().unwrap();
let port = free_udp_port();
let config = write_server_config(&dir, port);
let mut server = start_server(&dir, &config);
let socket = std::net::UdpSocket::bind("127.0.0.1:0").unwrap();
socket
.set_read_timeout(Some(Duration::from_secs(2)))
.unwrap();
let client_id = crypto::random_16();
let key = crypto::random_32();
let packet = protocol::encode_encrypted(
PacketKind::Ping,
client_id,
1,
0,
&key,
CLIENT_TO_SERVER,
b"",
)
.unwrap();
socket
.send_to(&packet, format!("127.0.0.1:{port}"))
.unwrap();
let mut buf = [0u8; 65535];
let (n, _) = socket.recv_from(&mut buf).unwrap();
let packet = protocol::decode(&buf[..n]).unwrap();
let reject: AttachReject = protocol::from_body(&packet.body).unwrap();
let _ = server.kill();
let _ = server.wait();
assert_eq!(packet.header.kind, PacketKind::AttachReject);
assert_eq!(packet.header.conn_id, client_id);
assert_eq!(reject.reason, "unknown client");
}
#[test]
fn local_attach_only_smoke() {
let dir = tempfile::tempdir().unwrap();