| 1 | //go:build windows |
| 2 | |
| 3 | package main |
| 4 | |
| 5 | import ( |
| 6 | "errors" |
| 7 | "testing" |
| 8 | |
| 9 | "golang.org/x/sys/windows" |
| 10 | |
| 11 | "reasonix/desktop/internal/instanceidentity" |
| 12 | ) |
| 13 | |
| 14 | func TestTrayIdentityRequiresVerifiedSignature(t *testing.T) { |
| 15 | id := instanceidentity.ForHome(t.TempDir()) |
| 16 | for _, tc := range []struct { |
| 17 | name, dev, exe string |
| 18 | failure error |
| 19 | wantGUID bool |
| 20 | calls int |
| 21 | }{ |
| 22 | {name: "signed", exe: "desktop.exe", wantGUID: true, calls: 1}, |
| 23 | {name: "unsigned", exe: "desktop.exe", failure: errors.New("unsigned"), calls: 1}, |
| 24 | {name: "unavailable", exe: "desktop.exe", failure: errors.New("access denied"), calls: 1}, |
| 25 | {name: "development", dev: "1", exe: "desktop.exe"}, {name: "missing executable"}, |
| 26 | } { |
| 27 | t.Run(tc.name, func(t *testing.T) { |
| 28 | calls := 0 |
| 29 | got := signedTrayIdentity(tc.dev, tc.exe, id, func(string) error { calls++; return tc.failure }) |
| 30 | if (got != "") != tc.wantGUID || calls != tc.calls { |
| 31 | t.Fatalf("guid=%q calls=%d", got, calls) |
| 32 | } |
| 33 | if got != "" { |
| 34 | if _, err := windows.GUIDFromString(got); err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | } |
| 38 | if got != "" && got != instanceidentity.TrayGUID(id) { |
| 39 | t.Fatal("wrong identity") |
| 40 | } |
| 41 | }) |
| 42 | } |
| 43 | } |
| 44 |