Skip to main content
Version: 0.16.x-dev

Integration Test Example Device

The integration test example device (crates/snakeway-wasm-test-device) is a small WASM device that exercises every device capability. Snakeway's integration tests load it as a fixture, and it doubles as a working reference for authoring your own device.

note

This device exists for testing and learning. Its behavior is driven by the request path and a mode config value so that tests can trigger each capability on demand. It is not meant for production traffic.

Building

cargo component build --release --target wasm32-unknown-unknown -p snakeway-wasm-test-device

Configuration Example

wasm_devices = [
{
name = "test-device"
enable = true
path = "/path/to/snakeway_wasm_test_device.wasm"
fail_policy = "open"

config = {
mode = "inject"
echo_value = "hello-from-config"
}
}
]

Path-Driven Behavior

The on_request hook branches on the request path, so a test can trigger a specific capability by choosing the path:

PathBehavior
/blockReturns 403 Forbidden (an Action::Block).
/syntheticReturns a synthetic 299 response with body synthetic-ok.
/rewriteRewrites the route path to /api.
/set-headerSets the request header x-wasm-test: injected.
/append-headerAppends x-multi: a and x-multi: b.
/remove-headerRemoves the request header x-to-remove.
/config-echoReturns 200 with the value of the echo_value config key as the body.
any other pathContinues unmodified.

Mode-Driven Behavior

The remaining hooks branch on the mode config value:

HookmodeBehavior
on_stream_request_bodyreplaceReplaces each request body chunk with replaced.
on_stream_request_bodydropDrops each request body chunk.
before_proxyinjectSets the request header x-before-proxy: injected.
after_proxyset-statusOverrides the response status to 299.
after_proxy then on_responsestrip-response-headerSets x-remove-me on the response, then removes it, to exercise response-header removal.
on_responsetag-responseSets the response header x-wasm-response: tagged.

Independent of mode, on_stream_request_body blocks any request whose body contains the bytes BLOCK_BODY.

Config Keys

KeyDescription
modeSelects the behavior for the body, before_proxy, after_proxy, and on_response hooks.
echo_valueValue returned in the body by the /config-echo path.

See Also