| 1 | package guestos |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "os/exec" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | |
| 11 | func TestMacPasswordAcceptsVerifiedSettingsExtensions(t *testing.T) { |
| 12 | dir := t.TempDir() |
| 13 | harness := `import AppKit |
| 14 | struct Failure: Error { |
| 15 | let code: Int |
| 16 | let message: String |
| 17 | init(_ code: Int, _ message: String) { self.code = code; self.message = message } |
| 18 | } |
| 19 | func requireGuest() throws { throw Failure(1,"unused") } |
| 20 | func consoleUser() throws { throw Failure(1,"unused") } |
| 21 | @main struct Check { |
| 22 | @MainActor static func main() throws { try MacSetupPassword.selfTest() } |
| 23 | } |
| 24 | ` |
| 25 | input := filepath.Join(dir, "check.swift") |
| 26 | if err := os.WriteFile(input, []byte(harness), 0600); err != nil { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | program := filepath.Join(dir, "password-check") |
| 30 | source := filepath.Join("..", "..", "scripts", "guest-os", "macos-setup-password.swift") |
| 31 | if output, err := exec.CommandContext(t.Context(), "xcrun", "swiftc", "-parse-as-library", source, input, "-o", program).CombinedOutput(); err != nil { |
| 32 | t.Fatalf("compile password policy: %v\n%s", err, output) |
| 33 | } |
| 34 | if output, err := exec.CommandContext(t.Context(), program).CombinedOutput(); err != nil { |
| 35 | t.Fatalf("password policy: %v\n%s", err, output) |
| 36 | } |
| 37 | } |