From 79fc3ac54e2a5c9c63138ccafdc4ee8d89937d9e Mon Sep 17 00:00:00 2001 From: An Tran Date: Thu, 28 Sep 2023 23:04:14 +1000 Subject: [PATCH] Add more unittest --- t/apicast-policy-buffering.t | 113 +++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/t/apicast-policy-buffering.t b/t/apicast-policy-buffering.t index cdd1c3e3e..3e9b9fbb4 100644 --- a/t/apicast-policy-buffering.t +++ b/t/apicast-policy-buffering.t @@ -1,6 +1,20 @@ use lib 't'; use Test::APIcast::Blackbox 'no_plan'; +require("http_proxy.pl"); + +sub large_body { + my $res = ""; + for (my $i=0; $i <= 1024; $i++) { + $res = $res . "1111111 1111111 1111111 1111111\n"; + } + return $res; +} + +$ENV{'LARGE_BODY'} = large_body(); + +require("policies.pl"); + run_tests(); __DATA__ @@ -50,3 +64,102 @@ GET /?user_key= "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n5\r\nhello\r\n0\r\n\r\n" --- response_body chomp hello + + +=== TEST 2: default configuration (buffered) with big file +--- configuration +{ + "services": [ + { + "backend_version": 1, + "proxy": { + "api_backend": "http://test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern": "/", "http_method": "POST", "metric_system_name": "hits", "delta": 2 } + ], + "policy_chain": [ + { + "name": "buffering", + "version": "builtin", + "configuration": {} + }, + { + "name": "apicast", + "version": "builtin", + "configuration": {} + } + ] + } + } + ] +} +--- backend +location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } +} +--- upstream +server_name test-upstream.lvh.me; + location / { + access_by_lua_block { + ngx.say("yay, api backend") + } + } +--- request eval +"POST /?user_key= \n" . $ENV{LARGE_BODY} +--- error_code: 200 +--- error_log env +a client request body is buffered to a temporary file +--- no_error_log + + +=== TEST 3: request buffering off (un-buffered) with big file +--- ONLY +--- configuration +{ + "services": [ + { + "backend_version": 1, + "proxy": { + "api_backend": "http://test-upstream.lvh.me:$TEST_NGINX_SERVER_PORT/", + "proxy_rules": [ + { "pattern": "/", "http_method": "POST", "metric_system_name": "hits", "delta": 2 } + ], + "policy_chain": [ + { + "name": "buffering", + "version": "builtin", + "configuration": { + "request_buffering": false + } + }, + { + "name": "apicast", + "version": "builtin", + "configuration": {} + } + ] + } + } + ] +} +--- backend +location /transactions/authrep.xml { + content_by_lua_block { + ngx.exit(200) + } +} +--- upstream +server_name test-upstream.lvh.me; + location / { + access_by_lua_block { + ngx.say("yay, api backend") + } + } +--- request eval +"POST /?user_key= \n" . $ENV{LARGE_BODY} +--- error_code: 200 +--- grep_error_log +a client request body is buffered to a temporary file +--- grep_error_log_out