add user management flow

This commit is contained in:
2026-03-19 18:18:54 +00:00
parent 38045b0a39
commit b7da60fb0a
3 changed files with 379 additions and 0 deletions

View File

@@ -136,6 +136,55 @@ func TestDetectSambaInstallPlanWithoutSudo(t *testing.T) {
}
}
func TestShareUserReferences(t *testing.T) {
doc := &Document{
Sections: []*Section{
BuildShareSection(nil, ShareConfig{
Name: "media",
Path: "/srv/media",
ValidUsers: []string{"alice", "bob"},
}),
BuildShareSection(nil, ShareConfig{
Name: "photos",
Path: "/srv/photos",
ValidUsers: []string{"alice"},
}),
},
}
refs := shareUserReferences(doc)
if len(refs) != 2 {
t.Fatalf("expected 2 refs, got %d", len(refs))
}
if refs[0].User != "alice" || strings.Join(refs[0].Shares, ",") != "media,photos" {
t.Fatalf("unexpected first ref: %+v", refs[0])
}
if refs[1].User != "bob" || strings.Join(refs[1].Shares, ",") != "media" {
t.Fatalf("unexpected second ref: %+v", refs[1])
}
}
func TestUnusedAccountCandidates(t *testing.T) {
entries := []PasswdEntry{
{Name: "alice", UID: 1001, Shell: "/usr/sbin/nologin"},
{Name: "bob", UID: 1002, Shell: "/bin/bash"},
{Name: "daemon", UID: 1, Shell: "/usr/sbin/nologin"},
{Name: "carol", UID: 1003, Shell: "/bin/false"},
}
active := map[string]struct{}{
"alice": {},
}
candidates := unusedAccountCandidates(entries, active)
if len(candidates) != 1 {
t.Fatalf("expected 1 candidate, got %d", len(candidates))
}
if candidates[0].Name != "carol" {
t.Fatalf("unexpected candidate: %+v", candidates[0])
}
}
type execErr string
func (e execErr) Error() string {