carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package hostfloor
4
5import (
6 "os"
7 "path/filepath"
8 "testing"
9)
10
11func TestControllerDirectoryRefusesLinkedAncestor(t *testing.T) {
12 real := t.TempDir()
13 if err := os.Mkdir(filepath.Join(real, "data"), 0o755); err != nil {
14 t.Fatal(err)
15 }
16 alias := filepath.Join(t.TempDir(), "linked")
17 if err := os.Symlink(real, alias); err != nil {
18 t.Fatal(err)
19 }
20 data := filepath.Join(alias, "data")
21 if err := EnsureControllerDir(data, os.Getuid(), os.Getgid()); err == nil {
22 t.Fatal("created controller directory through symlinked ancestor")
23 }
24 if _, err := os.Stat(filepath.Join(real, "data", ".hostexec")); !os.IsNotExist(err) {
25 t.Fatalf("controller directory created: %v", err)
26 }
27 if err := os.Mkdir(filepath.Join(real, "data", ".hostexec"), 0o755); err != nil {
28 t.Fatal(err)
29 }
30 for _, strict := range []bool{false, true} {
31 if err := CheckParticipation(t.Context(), data, strict); err == nil {
32 t.Fatalf("participation accepted linked ancestor with requireDirectory=%v", strict)
33 }
34 }
35}
36