跳到主要内容

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

浏览文件

screen_test.go

51 行 · 2.7 KB历史下载
1package maclogin
2
3import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8)
9
10func TestLockedConsoleBoundToOneUserAndSession(t *testing.T) {
11 const session = "607bceb6-c53f-4253-bad4-9c22b4ae7325"
12 const row = "<dict><key>kCGSSessionOnConsoleKey</key><true/><key>kCGSessionLoginDoneKey</key><true/><key>CGSSessionScreenIsLocked</key><true/><key>kCGSSessionUserIDKey</key><integer>502</integer><key>kCGSSessionUserNameKey</key><string>trial</string><key>CGSSessionUniqueSessionUUID</key><string>" + session + "</string></dict>"
13 const other = "<dict><key>kCGSSessionOnConsoleKey</key><false/></dict>"
14 makeProbe := func(header, rows string) string { return header + "\n<plist><array>" + rows + "</array></plist>" }
15 valid := makeProbe("502 trial 502", row)
16 for _, tc := range []struct{ label, input, want string }{
17 {"system login", "system-login", "system-login"},
18 {"locked", valid, "locked-" + session},
19 {"logged-out second user", makeProbe("502 trial 502", other+row), "locked-" + session},
20 {"unlocked", strings.Replace(valid, "ScreenIsLocked</key><true/>", "ScreenIsLocked</key><false/>", 1), ""},
21 {"missing lock value", strings.Replace(valid, "<key>CGSSessionScreenIsLocked</key><true/>", "", 1), ""},
22 {"wrong lock type", strings.Replace(valid, "ScreenIsLocked</key><true/>", "ScreenIsLocked</key><string>true</string>", 1), ""},
23 {"different console", makeProbe("503 other 502", row), ""},
24 {"different profile UID", makeProbe("503 trial 502", row), ""},
25 {"different registry UID", strings.Replace(valid, "<integer>502", "<integer>503", 1), ""},
26 {"different registry user", strings.Replace(valid, "<string>trial", "<string>other", 1), ""},
27 {"not logged in", strings.Replace(valid, "LoginDoneKey</key><true/>", "LoginDoneKey</key><false/>", 1), ""},
28 {"ambiguous", makeProbe("502 trial 502", row+row), ""},
29 {"missing session identity", strings.Replace(valid, session, "", 1), ""},
30 {"missing active flag", strings.Replace(valid, "<key>kCGSSessionOnConsoleKey</key><true/>", "", 1), ""},
31 {"bad plist", valid + "<", ""},
32 {"no session", makeProbe("502 trial 502", other), ""},
33 } {
34 t.Run(tc.label, func(t *testing.T) {
35 if got := permittedLoginScreen([]byte(tc.input), "trial"); got != tc.want {
36 t.Fatalf("allowed screen %q; want %q", got, tc.want)
37 }
38 })
39 }
40}
41
42func TestOffscreenViewMatchesDirectoryAliases(t *testing.T) {
43 instance := t.TempDir()
44 alias := filepath.Join(t.TempDir(), "lima-mac")
45 if err := os.Symlink(instance, alias); err != nil {
46 t.Skipf("symlink unavailable: %v", err)
47 }
48 if !sameGuestDirectory(alias, instance) || sameGuestDirectory(t.TempDir(), instance) || sameGuestDirectory(filepath.Join(alias, "absent"), filepath.Join(instance, "absent")) {
49 t.Fatal("offscreen view must be bound to an existing instance, including its socket path alias")
50 }
51}