| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package clipboard |
| 9 |
|
| 10 |
import ( |
| 11 |
"testing" |
| 12 |
) |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
func TestCopyViaOsascriptSuccess(t *testing.T) { |
| 17 |
if testing.Short() { |
| 18 |
t.Skip("skipping osascript integration test in short mode") |
| 19 |
} |
| 20 |
|
| 21 |
ctx := t.Context() |
| 22 |
const want = "s3cr3t-pass" |
| 23 |
|
| 24 |
if err := copyViaOsascript(ctx, want); err != nil { |
| 25 |
t.Fatalf("copyViaOsascript returned error: %v", err) |
| 26 |
} |
| 27 |
|
| 28 |
got, err := readAll(ctx) |
| 29 |
if err != nil { |
| 30 |
t.Fatalf("readAll failed: %v", err) |
| 31 |
} |
| 32 |
if string(got) != want { |
| 33 |
t.Errorf("clipboard = %q, want %q", got, want) |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
func TestCopyViaOsascriptSpecialChars(t *testing.T) { |
| 41 |
if testing.Short() { |
| 42 |
t.Skip("skipping osascript integration test in short mode") |
| 43 |
} |
| 44 |
|
| 45 |
ctx := t.Context() |
| 46 |
const want = `p@$$w0rd "quoted" & <tags>` |
| 47 |
|
| 48 |
if err := copyViaOsascript(ctx, want); err != nil { |
| 49 |
t.Fatalf("copyViaOsascript returned error: %v", err) |
| 50 |
} |
| 51 |
|
| 52 |
got, err := readAll(ctx) |
| 53 |
if err != nil { |
| 54 |
t.Fatalf("readAll failed: %v", err) |
| 55 |
} |
| 56 |
if string(got) != want { |
| 57 |
t.Errorf("clipboard = %q, want %q", got, want) |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
func TestWriteAllSecretFallback(t *testing.T) { |
| 65 |
if testing.Short() { |
| 66 |
t.Skip("skipping osascript integration test in short mode") |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
orig := osascriptPath |
| 72 |
osascriptPath = "/nonexistent-osascript-binary" |
| 73 |
t.Cleanup(func() { osascriptPath = orig }) |
| 74 |
|
| 75 |
ctx := t.Context() |
| 76 |
const want = "fallback-test-pass" |
| 77 |
|
| 78 |
if err := writeAll(ctx, []byte(want), true); err != nil { |
| 79 |
t.Fatalf("writeAll (secret, fallback) returned error: %v", err) |
| 80 |
} |
| 81 |
|
| 82 |
got, err := readAll(ctx) |
| 83 |
if err != nil { |
| 84 |
t.Fatalf("readAll failed: %v", err) |
| 85 |
} |
| 86 |
if string(got) != want { |
| 87 |
t.Errorf("clipboard = %q, want %q", got, want) |
| 88 |
} |
| 89 |
} |