From cf6b5266190b66761cefe018ab2604caeadcc990 Mon Sep 17 00:00:00 2001 From: Caio Casimiro Date: Thu, 16 Nov 2023 11:02:20 +0000 Subject: [PATCH] tests(proxy-wasm/assemblyscript) test cases for the SDK example filters --- t/03-proxy_wasm/sdks/003-assemblyscript_sdk.t | 141 ++++++++++++++++++ t/TestWasm.pm | 8 + 2 files changed, 149 insertions(+) create mode 100644 t/03-proxy_wasm/sdks/003-assemblyscript_sdk.t diff --git a/t/03-proxy_wasm/sdks/003-assemblyscript_sdk.t b/t/03-proxy_wasm/sdks/003-assemblyscript_sdk.t new file mode 100644 index 000000000..ec8726d37 --- /dev/null +++ b/t/03-proxy_wasm/sdks/003-assemblyscript_sdk.t @@ -0,0 +1,141 @@ +# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker: + +use strict; +use lib '.'; +use t::TestWasm; + +skip_valgrind('wasmtime'); +skip_no_nodejs(); + +plan tests => repeat_each() * (blocks() * 5); + +run_tests(); + +__DATA__ + +=== TEST 1: proxy_wasm AssemblyScript SDK - addheader example +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: assemblyscript_addheader +--- config + location /t { + proxy_wasm assemblyscript_addheader 'wasm'; + echo ok; + } +--- response_body +ok +--- response_headers +hello: wasm +--- no_error_log +[error] +[crit] + + + +=== TEST 2: proxy_wasm AssemblyScript SDK - auth example, authorized +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: assemblyscript_auth +--- tcp_listen: 12345 +--- tcp_reply eval +sub { + return ["HTTP/1.1 200 OK\r\n", + "Connection: close\r\n", + "Content-Length: 0\r\n", + "\r\n"]; +} +--- config + location /t { + proxy_wasm assemblyscript_auth '127.0.0.1:12345'; + echo ok; + } +--- response_body +ok +--- response_headers +hello: wasm! +--- no_error_log +[error] +[crit] + + + +=== TEST 3: proxy_wasm AssemblyScript SDK - auth example, unauthorized +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: assemblyscript_auth +--- tcp_listen: 12345 +--- tcp_reply eval +sub { + return ["HTTP/1.1 401 Unauthorized\r\n", + "Connection: close\r\n", + "Content-Length: 0\r\n", + "\r\n"]; +} +--- config + location /t { + proxy_wasm assemblyscript_auth '127.0.0.1:12345'; + echo ok; + } +--- error_code: 401 +--- no_error_log +[error] +[crit] +[emerg] +[stub] + + + +=== TEST 4: proxy_wasm AssemblyScript SDK - remove_headers example +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: assemblyscript_remove_headers +--- http_config + upstream test_upstream { + server unix:$TEST_NGINX_UNIX_SOCKET; + } + + server { + listen unix:$TEST_NGINX_UNIX_SOCKET; + + location / { + add_header foo bar; + echo ok; + } + } +--- config + location /t { + proxy_wasm assemblyscript_remove_headers 'foo'; + proxy_pass http://test_upstream/; + } +--- response_body +ok +--- raw_response_headers_unlike: foo: bar +--- no_error_log +[error] +[crit] + + + +=== TEST 5: proxy_wasm AssemblyScript SDK - singleton example +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: assemblyscript_remove_headers +--- http_config + upstream test_upstream { + server unix:$TEST_NGINX_UNIX_SOCKET; + } + + server { + listen unix:$TEST_NGINX_UNIX_SOCKET; + + location / { + add_header foo bar; + echo ok; + } + } +--- config + location /t { + proxy_wasm assemblyscript_remove_headers 'foo'; + proxy_pass http://test_upstream/; + } +--- response_body +ok +--- raw_response_headers_unlike: foo: bar +--- no_error_log +[error] +[crit] diff --git a/t/TestWasm.pm b/t/TestWasm.pm index 14638bec4..3bdb85813 100644 --- a/t/TestWasm.pm +++ b/t/TestWasm.pm @@ -30,6 +30,7 @@ our @EXPORT = qw( skip_no_ssl skip_no_debug skip_no_tinygo + skip_no_nodejs skip_valgrind ); @@ -83,6 +84,13 @@ sub skip_no_tinygo { } } +sub skip_no_nodejs { + my @files = glob($ENV{TEST_NGINX_CRATES_DIR} . '/assemblyscript_*.wasm'); + if (!@files && !defined($ENV{CI})) { + plan(skip_all => "Missing AssemblyScript .wasm bytecode files in $ENV{TEST_NGINX_CRATES_DIR}"); + } +} + sub load_nginx_modules (@) { splice @nginx_modules, 0, 0, @_; }