bastion 0.53.2
ci / personal-data (push) Successful in 5s
ci / test (push) Successful in 3m4s
ci / fuzz (push) Successful in 3m45s

This commit is contained in:
Privatae
2026-10-20 04:42:14 +00:00
commit e4c9b69b46
471 changed files with 159794 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
//go:build !darwin && !windows
package main
// The startup check on a platform whose system service is the systemd unit:
// systemServiceInstalled answers no here, and that answer must not stop the
// check from recording whether this process is root. Tagged like
// sysservice_other.go, because the probe it drives is that file's.
import (
"os"
"strings"
"testing"
)
func TestTheStartupCheckRecordsRootWithNoServiceInstalled(t *testing.T) {
saved := systemService
oldHeld := machineAuthorityHeld
t.Cleanup(func() { systemService, machineAuthorityHeld = saved, oldHeld })
home := os.Getenv("HOME")
for _, c := range []struct {
name string
root bool
}{{"root", true}, {"an ordinary account", false}} {
t.Run(c.name, func(t *testing.T) {
systemService.installed, systemService.authority, systemService.err = false, false, nil
machineAuthorityHeld = func() bool { return c.root }
adoptSystemServiceState()
if systemService.installed {
t.Fatal("no service is installed on this platform, yet one was recorded")
}
if systemService.authority != c.root {
t.Fatalf("authority recorded as %v for %s", systemService.authority, c.name)
}
if got := os.Getenv("HOME"); got != home {
t.Fatalf("the state directory was moved: HOME is %q, was %q", got, home)
}
why := enrolServiceState()
if c.root && why != "" {
t.Fatalf("stepup-enroll --console-only must take root here, whose state the systemd unit reads; refused: %s", why)
}
if !c.root && !strings.Contains(why, "does not administer the machine") {
t.Fatalf("an ordinary account must still be refused; got %q", why)
}
})
}
}