From f22115b9a6ea334f83ef182c186854cdc3b17271 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 22 Nov 2024 13:51:17 -0300 Subject: [PATCH] tests(proxy-wasm) showcase that invalid characters in querystring are passed through. This matches the plain Nginx behavior, and showcased in one of the tests. --- .../111-proxy_set_http_request_header.t | 75 ++++++++++++++++++- .../hfuncs/130-proxy_dispatch_http.t | 28 +++++++ 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t b/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t index 24c2c4957..348c16d6c 100644 --- a/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t +++ b/t/03-proxy_wasm/hfuncs/111-proxy_set_http_request_header.t @@ -423,7 +423,78 @@ path: -=== TEST 16: proxy_wasm - set_http_request_header() sets ':method' +=== TEST 16: proxy_wasm - set_http_request_headers() setting ':path' with invalid querystring matches nginx behavior +See following test for a showcase of the nginx behavior. + +--- wasm_modules: hostcalls +--- http_config eval +qq{ + upstream test_upstream { + server unix:$ENV{TEST_NGINX_UNIX_SOCKET}; + } + + server { + listen unix:$ENV{TEST_NGINX_UNIX_SOCKET}; + + location / { + return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n'; + } + } +} +--- config + location /set_by_proxy_wasm { + proxy_wasm hostcalls 'test=/t/set_request_header name=:path value=/test?foo=bár%20bla'; + proxy_wasm hostcalls 'test=/t/log/request_path'; + proxy_pass http://test_upstream$uri$is_args$args; + } +--- request +GET /set_by_proxy_wasm +--- response_body +(/test?foo=bár%20bla) (/test) (?) (foo=bár%20bla) +--- error_log +path: /test +--- no_error_log +[error] +[crit] + + + +=== TEST 17: proxy_wasm - showcase that that path with invalid querystring passes through +This test is here just as documentation, but it showcases +the same behavior as set_http_request_headers(':path'); +see previous test for the proxy-wasm behavior. + +--- wasm_modules: hostcalls +--- http_config eval +qq{ + upstream test_upstream { + server unix:$ENV{TEST_NGINX_UNIX_SOCKET}; + } + + server { + listen unix:$ENV{TEST_NGINX_UNIX_SOCKET}; + + location / { + return 200 '(\$request_uri) (\$uri) (\$is_args) (\$args)\n'; + } + } +} +--- config + location /raw_nginx { + proxy_pass http://test_upstream$uri$is_args$args; + } +--- request +GET /raw_nginx?foo=bár%20bla +--- response_body +(/raw_nginx?foo=bár%20bla) (/raw_nginx) (?) (foo=bár%20bla) +--- no_error_log +[error] +[crit] +[alert] + + + +=== TEST 18: proxy_wasm - set_http_request_header() sets ':method' --- wasm_modules: hostcalls --- http_config eval qq{ @@ -453,7 +524,7 @@ POST -=== TEST 17: proxy_wasm - set_http_request_header() cannot set ':scheme' +=== TEST 19: proxy_wasm - set_http_request_header() cannot set ':scheme' --- wasm_modules: hostcalls --- http_config eval qq{ diff --git a/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t b/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t index 6d742d1cf..247d6a250 100644 --- a/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t +++ b/t/03-proxy_wasm/hfuncs/130-proxy_dispatch_http.t @@ -1357,3 +1357,31 @@ Hello back /dispatched?foo=bar /dispatched ? foo=bar --- no_error_log [error] [crit] + + + +=== TEST 52: proxy_wasm - dispatch_http_call() can use ':path' with querystring, passes through invalid characters +--- load_nginx_modules: ngx_http_echo_module +--- wasm_modules: hostcalls +--- config + location /dispatched { + return 200 "Hello back $request_uri $uri $is_args $args"; + } + + location /t { + proxy_wasm hostcalls 'on=request_body \ + test=/t/dispatch_http_call \ + host=127.0.0.1:$TEST_NGINX_SERVER_PORT \ + path=/dispatched?foo=bár%20bla \ + on_http_call_response=echo_response_body'; + echo failed; + } +--- request +GET /t + +Hello world +--- response_body +Hello back /dispatched?foo=bár%20bla /dispatched ? foo=bár%20bla +--- no_error_log +[error] +[crit]