carlos / platform Public

host: the escaped-name nudge test reads under its own control directory

TestClaimNudgeDropinHookTakesEscapedNames pointed the production hook's
trusted reader at /usr with the root-owner check. On the CI runner /usr
is not uid 0's as the test sees it, so the owner check answered "usr:
permission denied" before the escaped name was ever looked up. The test
now builds the control directory under t.TempDir and checks it against
its own uid, as TestClaimNudgeDropinReadsAnEscapedUnit does. It still
proves the escaped unit name is not refused: absent with no drop-in
directory, and, with the directory made, absent inside it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev e4c1f8aa102766c283d35d51b87f6b93cf07cf04 parent 25cce8e
1 file changed, +26 −6
  • internal/host/claimunit_nudge_linux_test.go +26 −6
diff --git a/internal/host/claimunit_nudge_linux_test.go b/internal/host/claimunit_nudge_linux_test.go
index 2cc0d5f5d..4ff96d516 100644
--- a/internal/host/claimunit_nudge_linux_test.go
+++ b/internal/host/claimunit_nudge_linux_test.go
@@ -18,22 +18,42 @@ import (
)
// TestClaimNudgeDropinHookTakesEscapedNames: the production hook, with
-// its root-owner check, pointed at a root-owned directory every box has
-// (/usr), reaches a dashed unit's drop-in directory and finds it absent;
-// rootstate's trusted open refused the escaped name before looking.
+// its owner check, pointed at a control directory the test owns, reaches a
+// dashed unit's drop-in directory and finds it absent, then, with the
+// directory made, reaches into it and finds the drop-in absent; rootstate's
+// trusted open refused the escaped name before looking. Hermetic: a real
+// root-owned directory (/usr) is not root's on every CI runner, where the
+// owner check answered permission denied.
//
// Not parallel: it swaps claimNudgeReader.
func TestClaimNudgeDropinHookTakesEscapedNames(t *testing.T) {
+ root, err := filepath.EvalSymlinks(t.TempDir())
+ if err != nil {
+ t.Fatal(err)
+ }
+ dir := filepath.Join(root, "system.control")
+ if err := os.Mkdir(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
old := claimNudgeReader
t.Cleanup(func() { claimNudgeReader = old })
- claimNudgeReader = instancectl.TrustedDropinReader{ControlDir: "/usr"}
+ claimNudgeReader = instancectl.TrustedDropinReader{ControlDir: dir, Owner: uint32(os.Getuid())}
for _, host := range []string{"shop.example", "shop-a.example"} {
unit := instancectl.UnitName(instancectl.RoleRun, host)
- path := filepath.Join("/usr", unit+".d", "50-IPAddressAllow.conf")
+ path := filepath.Join(dir, unit+".d", "50-IPAddressAllow.conf")
+ if _, err := readClaimNudgeDropin(path); !errors.Is(err, fs.ErrNotExist) {
+ t.Fatalf("readClaimNudgeDropin(%s) with no drop-in directory = %v, want not found", path, err)
+ }
+ if err := os.Mkdir(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
if _, err := readClaimNudgeDropin(path); !errors.Is(err, fs.ErrNotExist) {
- t.Fatalf("readClaimNudgeDropin(%s) = %v, want not found", path, err)
+ t.Fatalf("readClaimNudgeDropin(%s) with no drop-in = %v, want not found", path, err)
}
}
+ if unit := instancectl.UnitName(instancectl.RoleRun, "shop-a.example"); !strings.Contains(unit, `\x2d`) {
+ t.Fatalf("fixture: %s is not an escaped unit name", unit)
+ }
}
// TestClaimNudgeDropinReadsAnEscapedUnit (Task 15 review): the claim