package nodefiles import ( "os" "path/filepath" "testing" ) func TestPlatformConfigurationCannotBeReadOrReplaced(t *testing.T) { root := t.TempDir() if err := os.Mkdir(filepath.Join(root, ".sea-runtime"), 0700); err != nil { t.Fatal(err) } original := []byte("PLATFORM_CONFIGURATION_SENTINEL") for _, name := range []string{".user.ini", ".sea-runtime/launch.env"} { if err := os.WriteFile(filepath.Join(root, name), original, 0600); err != nil { t.Fatal(err) } } if err := os.WriteFile(filepath.Join(root, "ordinary.txt"), []byte("ordinary"), 0600); err != nil { t.Fatal(err) } for _, name := range []string{".user.ini", ".sea-runtime/launch.env", "new/../.sea-runtime/launch.env"} { for _, operation := range []string{"read", "stat", "write", "remove", "mkdir"} { out := Execute(root, Request{Operation: operation, Path: name, Data: []byte("replaced"), Overwrite: true}) if out.Error != "denied" { t.Fatalf("%s %s: %+v", operation, name, out) } } } if out := Execute(root, Request{Operation: "rename", Path: "ordinary.txt", To: ".user.ini"}); out.Error != "denied" { t.Fatalf("rename onto protected file accepted: %+v", out) } for _, name := range []string{".user.ini", ".sea-runtime/launch.env"} { content, err := os.ReadFile(filepath.Join(root, name)) if err != nil || string(content) != string(original) { t.Fatal("platform file changed", name, err) } } if out := Execute(root, Request{Operation: "read", Path: "ordinary.txt"}); out.Error != "" || string(out.Data) != "ordinary" { t.Fatal("ordinary file read blocked", out.Error) } // Trash is still accessible only through its dedicated API, including emptying. if err := os.Mkdir(filepath.Join(root, ".sea-trash"), 0700); err != nil { t.Fatal(err) } if out := Execute(root, Request{Operation: "empty_trash", Path: ".sea-trash"}); out.Error != "" { t.Fatal("dedicated trash cleanup blocked", out.Error) } }