more UI and change default local user permissions

This commit is contained in:
2026-03-19 22:22:24 +00:00
parent a997b184f5
commit a79666f5a6
4 changed files with 198 additions and 37 deletions

View File

@@ -1,6 +1,9 @@
package main
import "testing"
import (
"os/user"
"testing"
)
func TestParseCIFSMountEntries(t *testing.T) {
contents := `# comment
@@ -86,3 +89,56 @@ func TestUpdateFstabContentsAddEditDelete(t *testing.T) {
t.Fatalf("unexpected delete result:\nwant: %q\ngot: %q", wantDeleted, deleted)
}
}
func TestDefaultLocalMountOwnerGroupUsesCurrentUser(t *testing.T) {
getenv := func(string) string { return "" }
currentUser := func() (*user.User, error) {
return &user.User{Username: "alice", Gid: "1000"}, nil
}
lookupUser := func(string) (*user.User, error) {
t.Fatal("lookupUser should not be called without SUDO_USER")
return nil, nil
}
lookupGroupID := func(id string) (*user.Group, error) {
if id != "1000" {
t.Fatalf("unexpected group id lookup: %q", id)
}
return &user.Group{Name: "alice"}, nil
}
uid, gid := defaultLocalMountOwnerGroup(getenv, currentUser, lookupUser, lookupGroupID)
if uid != "alice" || gid != "alice" {
t.Fatalf("unexpected defaults: uid=%q gid=%q", uid, gid)
}
}
func TestDefaultLocalMountOwnerGroupUsesSudoUser(t *testing.T) {
getenv := func(key string) string {
switch key {
case "SUDO_USER":
return "carol"
case "SUDO_GID":
return "2000"
default:
return ""
}
}
currentUser := func() (*user.User, error) {
return &user.User{Username: "root", Gid: "0"}, nil
}
lookupUser := func(string) (*user.User, error) {
t.Fatal("lookupUser should not be called when SUDO_GID is set")
return nil, nil
}
lookupGroupID := func(id string) (*user.Group, error) {
if id != "2000" {
t.Fatalf("unexpected group id lookup: %q", id)
}
return &user.Group{Name: "developers"}, nil
}
uid, gid := defaultLocalMountOwnerGroup(getenv, currentUser, lookupUser, lookupGroupID)
if uid != "carol" || gid != "developers" {
t.Fatalf("unexpected defaults: uid=%q gid=%q", uid, gid)
}
}