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

92 lines
3.1 KiB
Go

// Copyright (C) 2026 D-Modem Authors
// SPDX-License-Identifier: AGPL-3.0-only
package auth
import (
"context"
"errors"
"os"
"testing"
"github.com/D-Modem/login/internal/config"
"github.com/go-ldap/ldap/v3"
)
// DMODEM_LOGIN_TEST_LDAP=ldap://host:port of a server with
// uid=lduser,ou=people,dc=example,dc=com, password ldpass
func TestLDAP(t *testing.T) {
url := os.Getenv("DMODEM_LOGIN_TEST_LDAP")
if url == "" {
t.Skip("DMODEM_LOGIN_TEST_LDAP is not set")
}
for _, vals := range []map[string]string{
{"url": url, "search_base": "ou=people,dc=example,dc=com"},
{"url": url, "bind_dn": "uid={user},ou=people,dc=example,dc=com"},
} {
a, err := NewLDAP(&config.Section{Name: "ldap", Vals: vals})
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
if err := a.Authenticate(ctx, "lduser", "ldpass"); err != nil {
t.Errorf("%v: right password: %v", vals, err)
}
if err := a.Authenticate(ctx, "lduser", "wrong"); err == nil {
t.Errorf("%v: wrong password accepted", vals)
}
if err := a.Authenticate(ctx, "lduser", ""); err == nil {
t.Errorf("%v: empty password accepted", vals)
}
if err := a.Authenticate(ctx, "nobody*)(uid=*", "ldpass"); !errors.Is(err, ErrNoUser) {
t.Errorf("%v: unknown user: %v", vals, err)
}
}
}
// TestADPassword: unicodePwd's encoding, and AD's change request
func TestADPassword(t *testing.T) {
// "pw" in quotes, UTF-16LE
if got := adPassword("pw"); got != "\x22\x00p\x00w\x00\x22\x00" {
t.Errorf("% x", got)
}
if got := adPassword("é"); got != "\x22\x00\xe9\x00\x22\x00" {
t.Errorf("% x", got)
}
m := adPasswordChange("cn=a,dc=x", "old", "new")
if len(m.Changes) != 2 || m.Changes[0].Operation != ldap.DeleteAttribute ||
m.Changes[1].Operation != ldap.AddAttribute ||
m.Changes[1].Modification.Vals[0] != adPassword("new") {
t.Errorf("modify %+v", m.Changes)
}
}
// DMODEM_LOGIN_TEST_LDAP, with ou=groups,dc=example,dc=com holding
// cn=sysops (groupOfNames, member lduser) and cn=dialup (posixGroup,
// memberUid lduser) and cn=other (without lduser)
func TestLDAPGroups(t *testing.T) {
url := os.Getenv("DMODEM_LOGIN_TEST_LDAP")
if url == "" {
t.Skip("DMODEM_LOGIN_TEST_LDAP is not set")
}
for _, vals := range []map[string]string{
{"url": url, "search_base": "ou=people,dc=example,dc=com", "group_base": "ou=groups,dc=example,dc=com"},
{"url": url, "bind_dn": "uid={user},ou=people,dc=example,dc=com", "group_base": "ou=groups,dc=example,dc=com"},
} {
a, err := NewLDAP(&config.Section{Name: "ldap", Vals: vals})
if err != nil {
t.Fatal(err)
}
la := a.(*LDAP)
for group, want := range map[string]bool{"sysops": true, "dialup": true, "other": false, "nothere": false} {
if in, err := la.MemberOf("lduser", "ldpass", group); err != nil || in != want {
t.Errorf("%v: lduser in %s: %v %v, want %v", vals, group, in, err, want)
}
}
}
a, _ := NewLDAP(&config.Section{Name: "ldap", Vals: map[string]string{"url": url, "search_base": "ou=people,dc=example,dc=com"}})
if _, err := a.(*LDAP).MemberOf("lduser", "ldpass", "sysops"); !errors.Is(err, ErrNoUser) {
t.Errorf("without group_base: %v", err)
}
}