MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestParseWasmError

Function TestParseWasmError

pkg/policies/engine/wasm/errors_test.go:28–155  ·  view source on GitHub ↗

nolint:revive // Test error strings intentionally match real wazero error format

(t *testing.T)

Source from the content-addressed store, hash-verified

26
27//nolint:revive // Test error strings intentionally match real wazero error format
28func TestParseWasmError(t *testing.T) {
29 tests := []struct {
30 name string
31 input error
32 expectedCategory ErrorCategory
33 expectedMessage string
34 expectedHint string
35 }{
36 {
37 name: "HTTP request to disallowed hostname with full URL",
38 input: errors.New(`HTTP request to 'https://httpbin.org/json' is not allowed (recovered by wazero)
39wasm stack trace:
40 extism:host/env.http_request(i64,i64) i64
41 main.Execute() i32`),
42 expectedCategory: CategoryHTTPForbidden,
43 expectedMessage: "HTTP request blocked - hostname 'httpbin.org' is not in the allowed hosts list",
44 expectedHint: "Add the hostname using --allowed-hostnames flag",
45 },
46 {
47 name: "HTTP request to disallowed hostname without wazero message",
48 //nolint:revive // Test error string matches real wazero error format
49 input: errors.New(`HTTP request to 'https://evil.com/malware' is not allowed
50wasm stack trace:
51 ...`),
52 expectedCategory: CategoryHTTPForbidden,
53 expectedMessage: "HTTP request blocked - hostname 'evil.com' is not in the allowed hosts list",
54 expectedHint: "Add the hostname using --allowed-hostnames flag",
55 },
56 {
57 name: "Generic host not allowed",
58 //nolint:revive // Test error string matches real wazero error format
59 input: errors.New(`Host not allowed (recovered by wazero)
60wasm stack trace:
61 ...`),
62 expectedCategory: CategoryHTTPForbidden,
63 expectedMessage: "HTTP request blocked - hostname is not in the allowed hosts list",
64 expectedHint: "Add the hostname using --allowed-hostnames flag",
65 },
66 {
67 name: "Context deadline exceeded (timeout)",
68 //nolint:revive // Test error string matches real wazero error format
69 input: errors.New(`context deadline exceeded (recovered by wazero)
70wasm stack trace:
71 ...`),
72 expectedCategory: CategoryTimeout,
73 expectedMessage: "Policy execution timeout exceeded",
74 expectedHint: "Consider optimizing network calls, reducing data processing, or increasing the timeout",
75 },
76 {
77 name: "Out of memory error",
78 input: errors.New(`out of memory (recovered by wazero)
79wasm stack trace:
80 ...`),
81 expectedCategory: CategoryMemory,
82 expectedMessage: "Policy exceeded memory limits",
83 expectedHint: "Review data structures and avoid loading large files entirely into memory",
84 },
85 {

Callers

nothing calls this directly

Calls 2

parseWasmErrorFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected