跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

macos_attachments_test.go

62 行 · 2.2 KB历史下载
1package workbench
2
3import (
4 "bytes"
5 "encoding/json"
6 "os"
7 "os/exec"
8 "path/filepath"
9 "runtime"
10 "strings"
11 "testing"
12
13 "github.com/google/uuid"
14 "github.com/sylvinus/agent-vm/internal/cage"
15 "github.com/sylvinus/agent-vm/internal/guestos"
16)
17
18func TestMacOSAttachmentPathRejectsOtherUsersAndEscapes(t *testing.T) {
19 s := &Server{macosGuest: &guestos.MacOSProfile{User: "cage"}}
20 root := "/Users/cage/.local/share/cage/attachments/files/" + uuid.NewString() + "/" + uuid.NewString() + "/"
21 if !s.validMacOSAttachmentPath(root+"附件.txt", "附件.txt") {
22 t.Fatal("bound native attachment rejected")
23 }
24 for _, value := range []string{strings.Replace(root, "/cage/", "/another/", 1) + "附件.txt", root + "../附件.txt", root + "other.txt", "/Users/cage/.ssh/id_ed25519"} {
25 if s.validMacOSAttachmentPath(value, "附件.txt") {
26 t.Fatalf("unbound attachment accepted: %q", value)
27 }
28 }
29}
30
31func TestMacOSTerminalUsesSharedAttachmentReceiver(t *testing.T) {
32 if runtime.GOOS == "windows" {
33 t.Skip("shared macOS/Linux guest receiver requires POSIX UnixStreamServer")
34 }
35 if _, err := exec.LookPath("uv"); err != nil {
36 t.Skip("uv is required for the shared Python receiver")
37 }
38 home := t.TempDir()
39 contents := []byte("native attachment 中文\x00\x01")
40 var previous string
41 for attempt := 0; attempt < 2; attempt++ {
42 cmd := exec.Command("uv", "run", "--no-project", "python", "-I", "-c", cage.DesktopFileReceiver(), "--save-file", "file.bin")
43 cmd.Env = append(os.Environ(), "HOME="+home, "USERPROFILE="+home)
44 cmd.Stdin = bytes.NewReader(contents)
45 output, err := cmd.Output()
46 if err != nil {
47 t.Fatal(err)
48 }
49 var saved struct {
50 OK bool `json:"ok"`
51 Path string `json:"path"`
52 }
53 if json.Unmarshal(output, &saved) != nil || !saved.OK || !strings.HasPrefix(saved.Path, filepath.Join(home, ".local", "share", "cage", "attachments", "files")+string(os.PathSeparator)) {
54 t.Fatalf("receiver returned invalid attachment: %s", output)
55 }
56 actual, err := os.ReadFile(saved.Path)
57 if err != nil || !bytes.Equal(actual, contents) || saved.Path == previous {
58 t.Fatal("attachment bytes changed or duplicate name replaced a prior attachment")
59 }
60 previous = saved.Path
61 }
62}