Files
Claude 3b86b397ad Rename modemmenu to dmodem-login, the repository to D-Modem/login
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
2026-11-23 05:04:16 +00:00

72 lines
2.0 KiB
Go

// Copyright (C) 2026 D-Modem Authors
// SPDX-License-Identifier: AGPL-3.0-only
//go:build pam
package auth
import (
"context"
"errors"
"os"
"strings"
"testing"
"github.com/D-Modem/login/internal/config"
)
// DMODEM_LOGIN_TEST_PAM=user:password of an account the PAM service
// dmodem-login (/etc/pam.d/dmodem-login) accepts; run as root for pam_unix
func TestPAM(t *testing.T) {
cred := os.Getenv("DMODEM_LOGIN_TEST_PAM")
if cred == "" {
t.Skip("DMODEM_LOGIN_TEST_PAM is not set")
}
user, pw, _ := strings.Cut(cred, ":")
a, err := NewSystem(&config.Section{Name: "system", Vals: map[string]string{}})
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
if err := a.Authenticate(ctx, user, pw); err != nil {
t.Errorf("right password: %v", err)
}
if err := a.Authenticate(ctx, user, pw+"x"); !errors.Is(err, ErrBadPassword) {
t.Errorf("wrong password: %v", err)
}
if err := a.Authenticate(ctx, "no-such-user-here", pw); !errors.Is(err, ErrNoUser) {
t.Errorf("unknown user: %v", err)
}
if err := a.Authenticate(ctx, "root", pw); !errors.Is(err, ErrNoUser) {
t.Errorf("root: %v", err)
}
}
// DMODEM_LOGIN_TEST_PAM, a password stack in /etc/pam.d/dmodem-login: the
// account's password changed and back
func TestPAMChangePassword(t *testing.T) {
cred := os.Getenv("DMODEM_LOGIN_TEST_PAM")
if cred == "" {
t.Skip("DMODEM_LOGIN_TEST_PAM is not set")
}
user, pw, _ := strings.Cut(cred, ":")
a, err := NewSystem(&config.Section{Name: "system", Vals: map[string]string{}})
if err != nil {
t.Fatal(err)
}
sa := a.(*System)
ctx := context.Background()
if err := sa.ChangePassword(ctx, nil, user, pw, pw+"-2"); err != nil {
t.Fatal(err)
}
if err := a.Authenticate(ctx, user, pw+"-2"); err != nil {
t.Errorf("the new password: %v", err)
}
if err := a.Authenticate(ctx, user, pw); err == nil {
t.Error("the old password still works")
}
if err := sa.ChangePassword(ctx, nil, user, pw+"-2", pw); err != nil {
t.Errorf("back: %v", err)
}
}