跳到主要内容

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

浏览文件

terminal_login_link_test.go

58 行 · 1.9 KB历史下载
1package workbench
2
3import (
4 "encoding/json"
5 "net/http"
6 "net/http/httptest"
7 "testing"
8 "time"
9)
10
11func TestTerminalLoginLinkUsesGuestPrivateBrowser(t *testing.T) {
12 const address = "https://claude.ai/oauth/authorize?state=fixture"
13 s := testServer(t)
14 s.ready = true
15 terminal := newTerminalSession(nil)
16 terminal.id = "1234567890abcdef"
17 s.terminals.sessions = map[string]*terminalSession{terminal.id: terminal}
18 finished := make(chan struct{})
19 guest := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
20 var in struct{ URL, Login string }
21 if err := json.NewDecoder(r.Body).Decode(&in); err != nil || in.Login != terminal.id {
22 t.Error("incorrect login request")
23 }
24 switch r.URL.Path {
25 case "/login-open":
26 if in.URL != address {
27 t.Error("lost authorization parameters")
28 }
29 _, _ = w.Write([]byte(`{"id":"tab","url":"private"}`))
30 case "/login-finish":
31 if in.URL != "" {
32 t.Error("cleanup exposed URL")
33 }
34 _, _ = w.Write([]byte(`{"ok":true}`))
35 close(finished)
36 default:
37 t.Error("unexpected browser route")
38 }
39 }))
40 defer guest.Close()
41 s.browserControl = localBrowserClient(t, s.lifetimeContext(), guest)
42 defer s.browserControl.close()
43 for _, invalid := range []string{"http://claude.ai/oauth/authorize?x=1", "https://claude.ai:90/oauth/authorize?x=1", "https://[email protected]/oauth/authorize?x=1", "https://claude.ai/redirect?x=1", "https://claude.ai/oauth/authorize"} {
44 if claudeAuthorizationURL(invalid) {
45 t.Fatalf("accepted %q", invalid)
46 }
47 }
48 w := request(s, "POST", "/api/terminals/"+terminal.id+"/login-link", s.origin, `{"url":"`+address+`"}`, true)
49 if w.Code != 200 || w.Body.String() != "{\"id\":\"tab\"}\n" {
50 t.Fatalf("%d %s", w.Code, w.Body.String())
51 }
52 close(terminal.done)
53 select {
54 case <-finished:
55 case <-time.After(2 * time.Second):
56 t.Fatal("closing the terminal retained its login tab")
57 }
58}