跳到主要内容

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

浏览文件

macos_mobile_test.go

72 行 · 3.0 KB历史下载
1package workbench
2
3import (
4 "context"
5 "net/http"
6 "path/filepath"
7 "strings"
8 "testing"
9
10 "github.com/sylvinus/agent-vm/internal/guestos"
11)
12
13func TestMacOSPhoneRequiresCurrentRoomAndAccountUnlock(t *testing.T) {
14 s := testServer(t)
15 s.macosGuest = &guestos.MacOSProfile{Instance: "mac", User: "cage"}
16 workspace := t.TempDir()
17 if err := writePrivate(filepath.Join(s.profile, "environment.json"), map[string]string{"directory": workspace}); err != nil {
18 t.Fatal(err)
19 }
20 room, cancel := context.WithCancel(context.Background())
21 t.Cleanup(cancel)
22 s.phones.record = &phoneRecord{}
23 s.phones.roomCtx, s.phones.roomProof = room, "current-private-room"
24 path := "/api/mobile/cli/projects"
25 for _, proof := range []string{"", "expired-private-room"} {
26 if response := windowsPhoneRequest(t, s, http.MethodGet, path, "", proof); response.Code != http.StatusForbidden {
27 t.Fatalf("untrusted phone admitted: %d", response.Code)
28 }
29 }
30 response := windowsPhoneRequest(t, s, http.MethodGet, path, "", s.phones.roomProof)
31 if response.Code != http.StatusOK || !strings.Contains(response.Body.String(), `"shared_sessions":true`) {
32 t.Fatalf("Mac phone could not read shared projects: %d %s", response.Code, response.Body.String())
33 }
34 if response := windowsPhoneRequest(t, s, http.MethodGet, "/api/settings", "", s.phones.roomProof); response.Code != http.StatusForbidden {
35 t.Fatal("phone proof allowed desktop administration")
36 }
37 s.account.trustedSession = true
38 if response := windowsPhoneRequest(t, s, http.MethodGet, path, "", s.phones.roomProof); response.Code != http.StatusLocked {
39 t.Fatal("phone inherited a desktop-only account unlock")
40 }
41 s.account.trustedSession = false
42 cancel()
43 if response := windowsPhoneRequest(t, s, http.MethodGet, path, "", s.phones.roomProof); response.Code != http.StatusForbidden {
44 t.Fatal("revoked phone retained access")
45 }
46}
47
48func TestMacOSPhoneMediaUsesBoundGuestProject(t *testing.T) {
49 s := testServer(t)
50 s.macosGuest = &guestos.MacOSProfile{Instance: "mac", User: "cage"}
51 workspace := t.TempDir()
52 guest := s.cliWorkspace(workspace)
53 name, err := mediaFileName(guest, guest, guest+"/images/example.png")
54 if err != nil || name != filepath.Join("images", "example.png") {
55 t.Fatalf("guest media did not resolve within host project: %q %v", name, err)
56 }
57 if _, err := mediaFileName(guest, guest, guest+"/../outside.png"); err == nil {
58 t.Fatal("guest media escaped its bound project")
59 }
60}
61
62func TestMacOSPhoneBrowserPreservesPublicNetworkDenial(t *testing.T) {
63 s := &Server{macosGuest: &guestos.MacOSProfile{User: "cage"}}
64 s.phones.browser.nativeBrowser = fixtureWindowsBrowserClient(t)
65 _, status, err := s.phoneSurfaceGuest(context.Background(), phoneBrowser, "", "frame", phoneSurfaceInput{ID: "550e8400-e29b-41d4-a716-446655440000"})
66 if err != nil || status != http.StatusForbidden {
67 t.Fatalf("native public-network denial changed: %d %v", status, err)
68 }
69 if !macOSWorkbenchRoute("/api/mobile/browser/550e8400-e29b-41d4-a716-446655440000/frame") {
70 t.Fatal("native phone browser route remains unavailable")
71 }
72}