| 1 | package maclogin |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func 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(¤t, &selection) |
| 34 | if selection.permits(current, "trial", now) { |
| 35 | t.Fatal("unverified password target accepted") |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | func 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 | } |