跳到主要内容

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

浏览文件

windows_profile_test.go

91 行 · 3.1 KB历史下载
1package guestos
2
3import (
4 "context"
5 "encoding/json"
6 "os"
7 "path/filepath"
8 "testing"
9
10 "github.com/google/uuid"
11)
12
13func windowsBindingFixture(root string) WindowsProfile {
14 return WindowsProfile{Version: 1, VMID: uuid.MustParse("2a6f8208-3906-4e16-8233-2b9d28ecf7be"), GUIUserSID: "S-1-5-21-123-456-789-1001", GUIUser: "Guest", InstanceDirectory: filepath.Join(root, "vm"), RelayExecutable: filepath.Join(root, "agent.exe"), PairingFile: filepath.Join(root, "pairing.dpapi")}
15}
16
17func TestWindowsBindingPreservesIdentityAndHasNoSecretArgument(t *testing.T) {
18 root := t.TempDir()
19 binding := windowsBindingFixture(root)
20 if err := BindWindowsProfile(root, binding); err != nil {
21 t.Fatal(err)
22 }
23 loaded, err := LoadWindowsProfile(root)
24 if err != nil || *loaded != binding {
25 t.Fatalf("binding changed: %v", err)
26 }
27 cmd, err := WindowsRelayCommand(context.Background(), root, "export", "--paths-stdin")
28 if err != nil {
29 t.Fatal(err)
30 }
31 if len(cmd.Args) != 5 || cmd.Args[1] != "--relay-profile" || cmd.Args[2] != WindowsProfilePath(root) || cmd.Args[3] != "export" || cmd.Args[4] != "--paths-stdin" {
32 t.Fatal("relay command did not preserve the profile boundary")
33 }
34 different := binding
35 different.GUIUserSID = "S-1-5-21-123-456-789-1002"
36 if err := BindWindowsProfile(root, different); err == nil {
37 t.Fatal("another GUI user replaced the binding")
38 }
39 if _, err := WindowsRelayCommand(context.Background(), root, "export", `["C:\\private"]`); err == nil {
40 t.Fatal("paths accepted in argv")
41 }
42}
43
44func TestWindowsBindingRejectsUnknownFieldsAndUnsafeIdentity(t *testing.T) {
45 for _, kind := range []string{"system", "empty-vm", "relative", "relative-network", "unknown", "trailing"} {
46 t.Run(kind, func(t *testing.T) {
47 root := t.TempDir()
48 binding := windowsBindingFixture(root)
49 switch kind {
50 case "system":
51 binding.GUIUserSID = "S-1-5-18"
52 case "empty-vm":
53 binding.VMID = uuid.Nil
54 case "relative":
55 binding.PairingFile = "relative"
56 case "relative-network":
57 binding.NetworkPairingFile = "packet.dpapi"
58 }
59 data, _ := json.Marshal(binding)
60 if kind == "unknown" {
61 data = append(data[:len(data)-1], []byte(`,"secret":"must not be accepted"}`)...)
62 }
63 if kind == "trailing" {
64 data = append(data, []byte(` {}`)...)
65 }
66 if err := os.WriteFile(WindowsProfilePath(root), data, 0600); err != nil {
67 t.Fatal(err)
68 }
69 if _, err := LoadWindowsProfile(root); err == nil {
70 t.Fatal("unsafe binding accepted")
71 }
72 })
73 }
74}
75
76func TestWindowsBindingKeepsPacketPairingOutOfArguments(t *testing.T) {
77 root := t.TempDir()
78 binding := windowsBindingFixture(root)
79 binding.NetworkPairingFile = filepath.Join(root, "packet.dpapi")
80 if err := BindWindowsProfile(root, binding); err != nil {
81 t.Fatal(err)
82 }
83 loaded, err := LoadWindowsProfile(root)
84 if err != nil || loaded.NetworkPairingFile != binding.NetworkPairingFile {
85 t.Fatal("packet pairing binding lost")
86 }
87 cmd, err := WindowsRelayCommand(context.Background(), root, "network-stream")
88 if err != nil || len(cmd.Args) != 4 || cmd.Args[3] != "network-stream" {
89 t.Fatal("packet transport bypassed the protected profile")
90 }
91}