mirror of
https://github.com/D-Modem/login.git
synced 2026-11-28 20:38:06 -08:00
All of modemmenu was one package main in the repository's root. It is
now one module with the program and the pieces it is made of apart:
cmd/modemmenu/ the program (the login, the menu, access, limits,
the selections, -serve, AutoPPP, drop files, the
auth socket's server)
internal/config/ modemmenu.conf's sections and keys, {name} templates
internal/term/ the caller's line, terminal detection, PETSCII
internal/auth/ the backends and password changes
internal/telnet/ the telnet client of mode = telnet items
authd/ the auth socket's protocol and a client, for a BBS
to import (bbs's internal/menuauth is a copy of it)
samples/ the .conf, .users, .pam and .service samples
make builds ./cmd/modemmenu and installs the samples from samples/; the
docs, confref and the site's reference follow. The tests are where
their code is, none lost. TestSampleHasEveryKey now reads the keys of
internal/ too (and the exported Get, Bool...: it would have found none).
.gitignore's "modemmenu" ignored cmd/modemmenu/ as well: it is
/modemmenu now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRRbjf74j8oq9R3PXhA
70 lines
2.2 KiB
Go
70 lines
2.2 KiB
Go
// Copyright (C) 2026 D-Modem Authors
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// TestSpeed: {speed} from the connect rates
|
|
func TestSpeed(t *testing.T) {
|
|
for rate, want := range map[string]string{
|
|
"33600/33600": "33600 bit/s",
|
|
"33600/31200": "33600 bit/s down, 31200 bit/s up",
|
|
"50666/31200": "50666 bit/s down, 31200 bit/s up",
|
|
"2400": "2400 bit/s",
|
|
"": "",
|
|
"0/0": "",
|
|
"fast": "",
|
|
} {
|
|
s := newSession(rate, "", "", time.Now())
|
|
if got := s.Speed(); got != want {
|
|
t.Errorf("%q: %q, want %q", rate, got, want)
|
|
}
|
|
if got := s.vars(false)["speed"]; got != want {
|
|
t.Errorf("%q: {speed} %q, want %q", rate, got, want)
|
|
}
|
|
if env := strings.Join(s.environ(false), "\n"); !strings.Contains(env, "MODEM_SPEED="+want+"\n") {
|
|
t.Errorf("%q: no MODEM_SPEED=%s in\n%s", rate, want, env)
|
|
}
|
|
}
|
|
}
|
|
|
|
// the connect rate after the banner, before the login prompt
|
|
func TestConnectMessage(t *testing.T) {
|
|
dir := t.TempDir()
|
|
bin := filepath.Join(dir, "modemmenu")
|
|
if out, err := runGo("build", "-o", bin, "."); err != nil {
|
|
t.Fatalf("build: %v\n%s", err, out)
|
|
}
|
|
users := filepath.Join(dir, "users")
|
|
os.WriteFile(users, nil, 0o600)
|
|
conf := func(extra string) string {
|
|
p := filepath.Join(dir, fmt.Sprintf("c%d.conf", len(extra)))
|
|
os.WriteFile(p, []byte(fmt.Sprintf("[general]\nlog = none\nbanner = \"Test BBS\\r\\n\"\n%s\n[file]\npath = %s\n[item i]\ncommand = true\n", extra, users)), 0o600)
|
|
return p
|
|
}
|
|
for _, c := range []struct {
|
|
conf, rate, want string
|
|
}{
|
|
{conf(""), "DMODEM_RATE=33600/33600", "Test BBS\r\n\r\nConnected at 33600 bit/s.\r\n\r\nlogin: "},
|
|
{conf(""), "DMODEM_RATE=50666/31200", "Connected at 50666 bit/s down, 31200 bit/s up.\r\n"},
|
|
{conf(""), "DMODEM_RATE=", "Test BBS\r\n\r\nlogin: "},
|
|
{conf(`connect_message = "CONNECT {tx_rate}\r\n"`), "DMODEM_RATE=26400/24000", "Test BBS\r\nCONNECT 26400\r\n\r\nlogin: "},
|
|
{conf(`connect_message = ""`), "DMODEM_RATE=33600/33600", "Test BBS\r\n\r\nlogin: "},
|
|
} {
|
|
cl, cmd := callAs(t, bin, c.conf, c.rate)
|
|
got := cl.expect("login: ")
|
|
if !strings.Contains(got, c.want) {
|
|
t.Errorf("%s: %q, want %q in it", c.rate, got, c.want)
|
|
}
|
|
cmd.Process.Kill()
|
|
}
|
|
}
|