mirror of
https://github.com/D-Modem/login.git
synced 2026-11-28 20:38:06 -08:00
The program is dmodem-login (like dmodemd and dmodem-ari), the Go module github.com/D-Modem/login, the site d-modem.github.io/login. Its files, units, sockets, PAM service, pppd plugin, environment (DMODEM_LOGIN_*) and nftables tables follow. An old installation keeps working: - make install puts a modemmenu link to dmodem-login, and a modemmenu.so link to the plugin, which also takes its old modemmenu-socket option - the default configuration, users file, state_dir and PAM service fall back to modemmenu's when only those are there (config.Legacy) docs/rename.md (Simplified Technical English) lists the new names and what an old installation must change (the -serve socket, the units, the /etc/modemmenu files, the old nftables tables). CI's bbs job moves a bbs that still imports github.com/D-Modem/menu to the new path. The pppd plugin builds clean with -Wall -Wextra on GCC and Clang. COMMERCIAL-LICENSE.md and CONTRIBUTING.md (legal text) are not changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B82eRTD8BSptdpaUWGcs65
135 lines
2.9 KiB
Go
135 lines
2.9 KiB
Go
// Copyright (C) 2026 D-Modem Authors
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package confedit
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/D-Modem/login/internal/config"
|
|
)
|
|
|
|
const sample = `; the file's comment
|
|
|
|
[general]
|
|
; the log
|
|
log = syslog ; or a file
|
|
banner = "\r\nHi\r\n"
|
|
attempts=3
|
|
|
|
; the menu
|
|
[menu]
|
|
title = Main
|
|
|
|
; a BBS
|
|
[item bbs]
|
|
key = B
|
|
label = Board
|
|
|
|
; the shell
|
|
[item shell]
|
|
key = S
|
|
`
|
|
|
|
// TestSet: values changed in place with their comments and quotes, new
|
|
// keys after their section's last, new sections at the end
|
|
func TestSet(t *testing.T) {
|
|
d := Parse(sample)
|
|
d.Set("general", "log", "/var/log/dmodem-login.log")
|
|
d.Set("general", "banner", "Hello")
|
|
d.Set("general", "attempts", "5")
|
|
d.Set("general", "motd", " spaced ")
|
|
d.Set("menu", "hotkeys", "yes")
|
|
d.Set("aol", "enabled", "yes")
|
|
d.Set("item bbs", "help", "a; b")
|
|
want := `; the file's comment
|
|
|
|
[general]
|
|
; the log
|
|
log = /var/log/dmodem-login.log ; or a file
|
|
banner = "Hello"
|
|
attempts=5
|
|
motd = " spaced "
|
|
|
|
; the menu
|
|
[menu]
|
|
title = Main
|
|
hotkeys = yes
|
|
|
|
; a BBS
|
|
[item bbs]
|
|
key = B
|
|
label = Board
|
|
help = a; b
|
|
|
|
; the shell
|
|
[item shell]
|
|
key = S
|
|
|
|
[aol]
|
|
enabled = yes
|
|
`
|
|
if got := d.String(); got != want {
|
|
t.Errorf("got\n%s\nwant\n%s", got, want)
|
|
}
|
|
// and the configuration reads what was set
|
|
p := filepath.Join(t.TempDir(), "c.conf")
|
|
os.WriteFile(p, []byte(d.String()), 0o600)
|
|
c, err := config.Parse(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, kv := range [][3]string{{"general", "log", "/var/log/dmodem-login.log"}, {"general", "motd", " spaced "},
|
|
{"general", "banner", "Hello"}, {"item bbs", "help", "a; b"}, {"aol", "enabled", "yes"}} {
|
|
if v := c.Section(kv[0]).Get(kv[1], "?"); v != kv[2] {
|
|
t.Errorf("[%s] %s = %q, want %q", kv[0], kv[1], v, kv[2])
|
|
}
|
|
if v, _ := d.Get(kv[0], kv[1]); v != kv[2] {
|
|
t.Errorf("Get [%s] %s = %q, want %q", kv[0], kv[1], v, kv[2])
|
|
}
|
|
}
|
|
for _, v := range []string{"a ; b", "x # y", `"q"`, ""} {
|
|
d.Set("general", "motd", v)
|
|
os.WriteFile(p, []byte(d.String()), 0o600)
|
|
c, _ := config.Parse(p)
|
|
if got := c.Section("general").Get("motd", "?"); got != v {
|
|
t.Errorf("motd %q read back as %q", v, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestRemove: a key and a section out, the next one's comment kept
|
|
func TestRemove(t *testing.T) {
|
|
d := Parse(sample)
|
|
d.Unset("general", "attempts")
|
|
d.RemoveSection("item bbs")
|
|
d.RenameSection("item shell", "item sh")
|
|
want := `; the file's comment
|
|
|
|
[general]
|
|
; the log
|
|
log = syslog ; or a file
|
|
banner = "\r\nHi\r\n"
|
|
|
|
; the menu
|
|
[menu]
|
|
title = Main
|
|
|
|
; the shell
|
|
[item sh]
|
|
key = S
|
|
`
|
|
if got := d.String(); got != want {
|
|
t.Errorf("got\n%s\nwant\n%s", got, want)
|
|
}
|
|
d.RemoveSection("item sh")
|
|
if got := d.String(); got != "; the file's comment\n\n[general]\n; the log\nlog = syslog ; or a file\nbanner = \"\\r\\nHi\\r\\n\"\n\n; the menu\n[menu]\ntitle = Main\n" {
|
|
t.Errorf("got\n%s", got)
|
|
}
|
|
if s := d.Sections(); len(s) != 2 || s[1] != "menu" {
|
|
t.Errorf("sections %q", s)
|
|
}
|
|
}
|