package main import ( "os" "path/filepath" "testing" ) func TestExplicitWorkspaceSupportFilesAreConfined(t *testing.T) { s := testServer(t) p := project(t, s) pr := s.projects[p] pr.Dedicated = true pr.WorkspacePath = t.TempDir() cert := filepath.Join(t.TempDir(), "HONOR.CER") key := filepath.Join(t.TempDir(), "key.jks") writeFixture(t, cert, "certificate") writeFixture(t, key, "key material") c := BuildEnvironment{WorkspaceFiles: map[string]map[string]string{pr.WorkspacePath: {"cer/HONOR.CER": cert, "work/app/key.jks": key}}} if e := s.prepareWorkspaceFiles(p, c); e != nil { t.Fatal(e) } root := filepath.Join(s.root, "projects", p) for relative, want := range map[string]string{"cer/HONOR.CER": "certificate", "work/app/key.jks": "key material"} { data, e := os.ReadFile(filepath.Join(root, filepath.FromSlash(relative))) if e != nil || string(data) != want { t.Fatal(relative, e) } } for _, target := range []string{"../escape.cer", "work/.git/hooks/key.jks", "work/public.cer", "work/build/key.jks", "state.json"} { c.WorkspaceFiles[pr.WorkspacePath] = map[string]string{target: cert} if e := s.prepareWorkspaceFiles(p, c); e == nil { t.Fatal("unsafe support target accepted", target) } } }