Files
Claude e1d04978cd Line speeds: Break or Ctrl-X sends the rest of a slow screen at once
Telnet's Break, Interrupt Process and Abort Output and SSH's break
request (RFC 4335: OpenSSH's ~B, PuTTY's Special Command > Break) now
reach the terminal, and while a screen is slowed to a line speed the
keys are looked at every 100 ms for Ctrl-X. Either sends what is left
at the line's own speed up to the next prompt: skipped, but drawn
whole, so no escape sequence is cut and the screen is right. The next
key read slows things down again. Doors' keys are theirs, so they are
not polled while one runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRUrCtqbnHANimX37GK
2026-11-09 11:21:32 +00:00

143 lines
3.7 KiB
Go

package server
import (
"io"
"net"
"strings"
"testing"
"time"
"github.com/D-Modem/bbs/internal/bbs"
"golang.org/x/crypto/ssh"
)
// TestLineSpeed: an SSH caller picks a line speed on the profile and with
// Ctrl-B; it is kept, and the next call begins at it.
func TestLineSpeed(t *testing.T) {
e, addr, _ := startSSH(t, nil)
call := func() *dialog {
c, err := sshDial(t, addr, "alice", ssh.Password("alicepass1"))
if err != nil {
t.Fatal(err)
}
d := shell(t, c, "xterm-256color", 100, 40)
d.expect("Command: ")
return d
}
prefs := func() string {
u, _ := e.b.Store.UserByName("alice")
return u.Prefs
}
d := call()
d.send("P")
d.expect("line speed full")
d.expect("[B]aud: line speed (or Ctrl-B)")
d.send("B")
d.expect("Which? ")
d.send("a") // 56k
d.expect("Now at 56000 bit/s.")
d.expect("line speed 56000 bit/s")
if p := prefs(); p != "baud=56000" {
t.Errorf("kept %q", p)
}
d.send("Q")
d.expect("Command: ")
d = call()
d.send("P")
d.expect("line speed 56000 bit/s")
d.send("Q")
d.expect("Command: ")
d.send("\x02")
d.expect("Line speed\x1b[0m (now 56k):")
d.send("0")
d.expect("Full speed.")
d.expect("Command: ") // the prompt again
d.send("P")
d.expect("line speed full")
if p := prefs(); p != "baud=off" {
t.Errorf("kept %q", p)
}
}
// TestLineSpeedOff: with line_speeds = no, nor the profile's B nor Ctrl-B
// is there, and a speed kept is not used.
func TestLineSpeedOff(t *testing.T) {
e, addr, _ := startSSH(t, func(s *bbs.Settings) { s.LineSpeeds = false })
u, _ := e.b.Store.UserByName("alice")
if err := e.b.Store.SetPrefs(u.ID, "baud=300"); err != nil {
t.Fatal(err)
}
c, err := sshDial(t, addr, "alice", ssh.Password("alicepass1"))
if err != nil {
t.Fatal(err)
}
d := shell(t, c, "xterm-256color", 100, 40)
d.expect("Command: ")
d.send("\x02")
d.send("P")
d.expect("Terminal:")
d.expect("[Q]uit: ")
if strings.Contains(string(d.before), "ine speed") {
t.Errorf("line speeds offered: %q", d.before)
}
}
// TestLineSpeedModem: a modem caller's line has its speed; none is offered.
func TestLineSpeedModem(t *testing.T) {
e := start(t, nil, &Listener{Name: "menu", Kind: "raw", Address: "menu.sock", ANSI: "no",
Header: true, TrustUser: true, CreateUsers: true})
d := e.dial("menu.sock")
d.send("MODEM_USER=erin\nMODEM_AUTH=pam\nMODEM_RATE=26400/31200\n\n")
d.expect("Command: ")
d.send("P")
d.expect("Terminal:")
d.expect("[Q]uit: ")
if strings.Contains(string(d.before), "ine speed") {
t.Errorf("line speeds offered a modem caller: %q", d.before)
}
}
// TestLineSpeedSkip: at 300 bit/s an SSH Break (RFC 4335), or Ctrl-X,
// sends the rest of the screen at once.
func TestLineSpeedSkip(t *testing.T) {
e, addr, _ := startSSH(t, nil)
u, _ := e.b.Store.UserByName("alice")
if err := e.b.Store.SetPrefs(u.ID, "baud=300"); err != nil {
t.Fatal(err)
}
c, err := sshDial(t, addr, "alice", ssh.Password("alicepass1"))
if err != nil {
t.Fatal(err)
}
s, err := c.NewSession()
if err != nil {
t.Fatal(err)
}
if err := s.RequestPty("xterm-256color", 40, 100, ssh.TerminalModes{}); err != nil {
t.Fatal(err)
}
in, _ := s.StdinPipe()
out, _ := s.StdoutPipe()
if err := s.Shell(); err != nil {
t.Fatal(err)
}
a, b := net.Pipe()
go func() { io.Copy(a, out); a.Close() }()
go io.Copy(in, a)
t.Cleanup(func() { s.Close(); b.Close() })
d := &dialog{t: t, c: b}
// the main menu, some 1500 bytes: most of a minute at 300 bit/s
time.Sleep(300 * time.Millisecond)
if ok, err := s.SendRequest("break", true, ssh.Marshal(struct{ Ms uint32 }{500})); err != nil || !ok {
t.Fatalf("break: %v %v", ok, err)
}
d.expect("Command: ")
// and slow again after: the profile, skipped by Ctrl-X
d.send("P")
time.Sleep(300 * time.Millisecond)
d.send("\x18")
d.expect("[Q]uit: ")
}