跳到主要内容

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

浏览文件

operations_test.go

75 行 · 2.6 KB历史下载
1package mobilelink
2
3import (
4 "net/url"
5 "strings"
6 "testing"
7)
8
9func TestSnapshotPollingQuery(t *testing.T) {
10 const id = "12345678-1234-4321-aaaa-123456789abc"
11 for _, tc := range []struct {
12 query string
13 want bool
14 }{
15 {"", true}, {"after=0", true}, {"after=18446744073709551615", true},
16 {"after=2&epoch=" + id, true}, {"epoch=" + id + "&after=2", true},
17 {"epoch=" + id, false}, {"after=2&epoch=", false}, {"after=2&epoch=" + strings.ToUpper(id), false},
18 {"after=2&epoch=12345678-1234-5321-aaaa-123456789abc", false},
19 {"after=2&epoch=12345678-1234-4321-0aaa-123456789abc", false},
20 {"after=-1&epoch=" + id, false}, {"after=0&after=1", false}, {"after=1&other=x", false},
21 {"after=1&epoch=" + id + "&epoch=" + id, false}, {"after=%31&epoch=" + id, false},
22 {"after=18446744073709551616", false},
23 } {
24 u := &url.URL{Path: "/api/mobile/cli/sessions/" + id, RawQuery: tc.query}
25 if got := allowed("GET", u); got != tc.want {
26 t.Errorf("poll query %q allowed=%v, want %v", tc.query, got, tc.want)
27 }
28 }
29}
30
31func TestBrowserFrameQuery(t *testing.T) {
32 const tag = "b542cd94286a2489bc2df1241b043c76"
33 const id = "12345678-1234-4321-aaaa-123456789abc"
34 for _, tc := range []struct {
35 method, surface, operation, query string
36 want bool
37 }{
38 {"GET", "browser", "frame", "after=" + tag, true},
39 {"GET", "browser", "frame", "after=" + tag + "&after=" + tag, false},
40 {"GET", "browser", "frame", "after=" + strings.ToUpper(tag), false},
41 {"POST", "browser", "action", "after=" + tag, false},
42 {"GET", "desktop", "frame", "after=" + tag, false},
43 } {
44 u := &url.URL{Path: "/api/mobile/" + tc.surface + "/" + id + "/" + tc.operation, RawQuery: tc.query}
45 if allowed(tc.method, u) != tc.want {
46 t.Errorf("unexpected result for %s %s", tc.method, u.RequestURI())
47 }
48 }
49}
50
51func TestSessionListMutations(t *testing.T) {
52 for _, operation := range []string{"metadata", "delete", "archive", "restore", "purge"} {
53 u := &url.URL{Path: "/api/mobile/cli/sessions/12345678-1234-4321-aaaa-123456789abc/" + operation}
54 if !allowed("POST", u) || allowed("GET", u) || allowed("DELETE", u) {
55 t.Fatal("mutation method boundary", operation)
56 }
57 u.RawQuery = "after=1"
58 if allowed("POST", u) {
59 t.Fatal("mutation query accepted", operation)
60 }
61 }
62}
63
64func TestArchivedSessionQuery(t *testing.T) {
65 u := &url.URL{Path: "/api/mobile/cli/sessions", RawQuery: "archived=true"}
66 if !allowed("GET", u) || allowed("POST", u) {
67 t.Fatal("archive query method")
68 }
69 for _, query := range []string{"archived=false", "archived=true&other=1", "archived=true&archived=true"} {
70 u.RawQuery = query
71 if allowed("GET", u) {
72 t.Fatal("unexpected archive query", query)
73 }
74 }
75}