| 1 | |
| 2 | |
| 3 | package maclogin |
| 4 | |
| 5 | import ( |
| 6 | "bufio" |
| 7 | "bytes" |
| 8 | "encoding/json" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | type passwordProbeInput struct{ bytes.Buffer } |
| 13 | |
| 14 | func (*passwordProbeInput) Close() error { return nil } |
| 15 | |
| 16 | func TestMaintenancePasswordProbeUsesFixedPrivateStreamRequest(t *testing.T) { |
| 17 | target := passwordTarget{maintenanceWindow: maintenanceFixture(), SelectionRequired: true} |
| 18 | first, err := json.Marshal(target) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | target.Window++ |
| 23 | second, err := json.Marshal(target) |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | input := &passwordProbeInput{} |
| 28 | output := append(append(append(first, '\n'), second...), '\n') |
| 29 | probe := passwordProbe{input: input, scanner: bufio.NewScanner(bytes.NewReader(output)), user: "trial"} |
| 30 | before, err := probe.target() |
| 31 | if err != nil || before.Accessibility || !before.SelectionRequired { |
| 32 | t.Fatal("private probe lost the AX-disabled authorization target") |
| 33 | } |
| 34 | after, err := probe.target() |
| 35 | if err != nil || before.geometry() == after.geometry() { |
| 36 | t.Fatal("per-key probe failed to observe a changed authorization panel") |
| 37 | } |
| 38 | if input.String() != "{\"action\":\"probe\"}\n{\"action\":\"probe\"}\n" { |
| 39 | t.Fatal("maintenance probe used a GUI socket command or extra request fields") |
| 40 | } |
| 41 | } |