more UI and change default local user permissions
This commit is contained in:
58
app_test.go
58
app_test.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user