跳到主要内容

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

浏览文件

password_target_test.go

53 行 · 2.5 KB历史下载
1package maclogin
2
3import (
4 "testing"
5 "time"
6)
7
8func TestFirstAuthorizationUsesFreshSelectedSystemPanelBeforeAccessibility(t *testing.T) {
9 now := time.Now()
10 target := passwordTarget{maintenanceWindow: maintenanceFixture(), SelectionRequired: true}
11 selected := passwordSelection{Geometry: target.geometry(), X: 200, Y: 200, Clicked: now}
12 if !selected.permits(target, "trial", now.Add(time.Second)) {
13 t.Fatal("first authorization required the permission it is preparing")
14 }
15 for _, test := range []struct {
16 name string
17 change func(*passwordTarget, *passwordSelection)
18 }{
19 {"no selection", func(_ *passwordTarget, s *passwordSelection) { *s = passwordSelection{} }},
20 {"expired selection", func(_ *passwordTarget, s *passwordSelection) { s.Clicked = now.Add(-31 * time.Second) }},
21 {"future selection", func(_ *passwordTarget, s *passwordSelection) { s.Clicked = now.Add(time.Second) }},
22 {"outside panel", func(_ *passwordTarget, s *passwordSelection) { s.X = 159 }},
23 {"replaced window", func(w *passwordTarget, _ *passwordSelection) { w.Window++ }},
24 {"moved window", func(w *passwordTarget, _ *passwordSelection) { w.Rect[0]++ }},
25 {"another process", func(w *passwordTarget, _ *passwordSelection) { w.PID++ }},
26 {"another GUI session", func(w *passwordTarget, _ *passwordSelection) { w.Session = "1e128373-fcb9-42fd-88b2-2a6ca58cf3a1" }},
27 {"another app", func(w *passwordTarget, _ *passwordSelection) { w.Bundle = "com.apple.finder" }},
28 {"ordinary settings window", func(w *passwordTarget, _ *passwordSelection) { w.SelectionRequired = false }},
29 {"known non-password focus", func(w *passwordTarget, _ *passwordSelection) { w.Accessibility = true }},
30 } {
31 t.Run(test.name, func(t *testing.T) {
32 current, selection := target, selected
33 test.change(&current, &selection)
34 if selection.permits(current, "trial", now) {
35 t.Fatal("unverified password target accepted")
36 }
37 })
38 }
39}
40
41func TestAuthorizedAccessibilityRequiresSecureFocusForBothAppleHosts(t *testing.T) {
42 for _, bundle := range []string{"com.apple.systempreferences", "com.apple.authorizationhost"} {
43 target := passwordTarget{maintenanceWindow: maintenanceFixture(), Accessibility: true}
44 target.Bundle, target.PasswordFocused = bundle, true
45 if !(passwordSelection{}).permits(target, "trial", time.Now()) {
46 t.Fatalf("verified secure field rejected in %s", bundle)
47 }
48 target.PasswordFocused = false
49 if (passwordSelection{}).permits(target, "trial", time.Now()) {
50 t.Fatal("non-password field accepted")
51 }
52 }
53}