| 1 | package builtin |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestSandboxWriteDenialClassifierRejectsOrdinaryFailures(t *testing.T) { |
| 9 | for _, tc := range []struct { |
| 10 | name string |
| 11 | out string |
| 12 | err error |
| 13 | }{ |
| 14 | {name: "python key error", out: "Traceback\nKeyError: 'observation_time'", err: errors.New("exit status 1")}, |
| 15 | {name: "http failure", out: "HTTP 403: permission denied", err: errors.New("exit status 22")}, |
| 16 | {name: "timeout", out: "curl: (28) operation timed out", err: errors.New("exit status 28")}, |
| 17 | {name: "sandbox startup", out: "", err: errors.New("sandbox helper failed to start")}, |
| 18 | } { |
| 19 | t.Run(tc.name, func(t *testing.T) { |
| 20 | if looksLikeSandboxWriteDenial(tc.out, tc.err) { |
| 21 | t.Fatal("ordinary failure was classified as a sandbox write denial") |
| 22 | } |
| 23 | }) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestSandboxWriteDenialClassifierAcceptsFilesystemFailures(t *testing.T) { |
| 28 | for _, out := range []string{ |
| 29 | "touch: /outside/file: Permission denied", |
| 30 | "bash: /outside/file: Permission denied", |
| 31 | "mkdir: cannot create directory '/outside': Read-only file system", |
| 32 | "open /outside/file: operation not permitted", |
| 33 | "PermissionError: [Errno 13] Permission denied: '/outside/file'", |
| 34 | } { |
| 35 | if !looksLikeSandboxWriteDenial(out, errors.New("exit status 1")) { |
| 36 | t.Fatalf("filesystem failure was not recognized: %q", out) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 |