carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "os"
5 "path/filepath"
6 "testing"
7 "time"
8
9 "github.com/carlosframework/platform/internal/rollout"
10 "golang.org/x/sys/unix"
11)
12
13func TestPlan14RootFailureLegacySpecialFiles(t *testing.T) {
14 for _, kind := range []string{"fifo", "symlink", "regular", "absent"} {
15 t.Run(kind, func(t *testing.T) {
16 dir := t.TempDir()
17 path := filepath.Join(dir, rollout.FailureFile)
18 switch kind {
19 case "fifo":
20 if err := unix.Mkfifo(path, 0600); err != nil {
21 t.Fatal(err)
22 }
23 case "symlink":
24 target := filepath.Join(dir, "target")
25 if err := os.WriteFile(target, []byte("legacy"), 0600); err != nil {
26 t.Fatal(err)
27 }
28 if err := os.Symlink(target, path); err != nil {
29 t.Fatal(err)
30 }
31 case "regular":
32 if err := os.WriteFile(path, []byte("legacy"), 0600); err != nil {
33 t.Fatal(err)
34 }
35 }
36 done := make(chan error, 1)
37 go func() { _, err := rootFailureLegacy(dir); done <- err }()
38 select {
39 case err := <-done:
40 if (err == nil) != (kind == "regular" || kind == "absent") {
41 t.Fatal("unsafe legacy reader", kind, err)
42 }
43 case <-time.After(time.Second):
44 t.Fatal("legacy file blocked root")
45 }
46 })
47 }
48}
49