| 1 | package cage |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestWindowsInitialDataDirectoryAndApplicationBoundary(t *testing.T) { |
| 10 | profile, root := newStorageFixture(t) |
| 11 | app := filepath.Join(root, "Cage") |
| 12 | backend := filepath.Join(app, "resources", "cage.exe") |
| 13 | writeStorageFixture(t, backend, []byte("backend")) |
| 14 | writeStorageFixture(t, filepath.Join(app, "Cage.exe"), []byte("launcher")) |
| 15 | if got := initialStorageDirectory(backend, "windows"); got != "" { |
| 16 | t.Fatalf("unmarked build default=%s", got) |
| 17 | } |
| 18 | writeStorageFixture(t, filepath.Join(app, "Cage.install-id"), []byte("io.github.lee-xeo.claude-cage")) |
| 19 | data := filepath.Join(app, "CageData") |
| 20 | if got := initialStorageDirectory(backend, "windows"); got != data { |
| 21 | t.Fatalf("default=%s want=%s", got, data) |
| 22 | } |
| 23 | for _, platform := range []string{"darwin", "linux"} { |
| 24 | if got := initialStorageDirectory(backend, platform); got != "" { |
| 25 | t.Fatalf("%s default changed to %s", platform, got) |
| 26 | } |
| 27 | } |
| 28 | if err := validateStorageTarget(profile, data, app, "windows"); err != nil { |
| 29 | t.Fatalf("reserved Windows data folder rejected: %v", err) |
| 30 | } |
| 31 | for _, target := range []string{app, filepath.Join(app, "resources", "data"), filepath.Join(app, "OtherData")} { |
| 32 | if err := validateStorageTarget(profile, target, app, "windows"); err == nil { |
| 33 | t.Fatalf("program boundary opened for %s", target) |
| 34 | } |
| 35 | } |
| 36 | if err := validateStorageTarget(profile, data, app, "darwin"); err == nil { |
| 37 | t.Fatal("Mac application directory allowed") |
| 38 | } |
| 39 | if err := os.Remove(filepath.Join(app, "Cage.install-id")); err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | if err := validateStorageTarget(profile, data, app, "windows"); err == nil { |
| 43 | t.Fatal("unmarked installation allowed data inside app") |
| 44 | } |
| 45 | } |