This is an automated email from the ASF dual-hosted git repository. wenming pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new f4dfcfb fix: we didn't initialize custom variable for admin access log (#2874) f4dfcfb is described below commit f4dfcfbb6b947a62abd4b20452c7668db789369b Author: 罗泽轩 <spacewander...@gmail.com> AuthorDate: Sat Nov 28 13:12:17 2020 +0800 fix: we didn't initialize custom variable for admin access log (#2874) * fix: we didn't initialize custom variable for admin access log * t --- .travis/apisix_cli_test.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++ apisix/cli/ngx_tpl.lua | 11 ++++++++--- t/APISIX.pm | 10 +++++++--- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/.travis/apisix_cli_test.sh b/.travis/apisix_cli_test.sh index 9ea1c7c..27ee20f 100755 --- a/.travis/apisix_cli_test.sh +++ b/.travis/apisix_cli_test.sh @@ -717,6 +717,53 @@ make stop echo "passed: access log with JSON format" +# check uninitialized variable in access log +git checkout conf/config.yaml + +rm logs/error.log +make init +make run + +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +make stop + +if [ ! $code -eq 200 ]; then + echo "failed: failed to access admin" + exit 1 +fi + +if grep 'using uninitialized "upstream_host" variable while logging request' logs/error.log; then + echo "failed: uninitialized variable found during writing access log" + exit 1 +fi + +echo "pass: uninitialized variable not found during writing access log" + +# port_admin set +echo ' +apisix: + port_admin: 9180 +' > conf/config.yaml + +rm logs/error.log +make init +make run + +code=$(curl -v -k -i -m 20 -o /dev/null -s -w %{http_code} http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1') +make stop + +if [ ! $code -eq 200 ]; then + echo "failed: failed to access admin" + exit 1 +fi + +if grep 'using uninitialized "upstream_host" variable while logging request' logs/error.log; then + echo "failed: uninitialized variable found during writing access log" + exit 1 +fi + +echo "pass: uninitialized variable not found during writing access log (port_admin set)" + # check etcd while enable auth git checkout conf/config.yaml diff --git a/apisix/cli/ngx_tpl.lua b/apisix/cli/ngx_tpl.lua index 893b84c..f5b6dda 100644 --- a/apisix/cli/ngx_tpl.lua +++ b/apisix/cli/ngx_tpl.lua @@ -283,6 +283,10 @@ http { {% end %} # admin configuration snippet ends + set $upstream_scheme 'http'; + set $upstream_host $host; + set $upstream_uri ''; + location /apisix/admin { {%if allow_admin then%} {% for _, allow_ip in ipairs(allow_admin) do %} @@ -372,6 +376,10 @@ http { {% end %} # http server configuration snippet ends + set $upstream_scheme 'http'; + set $upstream_host $host; + set $upstream_uri ''; + {% if with_module_status then %} location = /apisix/nginx_status { allow 127.0.0.0/24; @@ -421,11 +429,8 @@ http { location / { set $upstream_mirror_host ''; - set $upstream_scheme 'http'; - set $upstream_host $host; set $upstream_upgrade ''; set $upstream_connection ''; - set $upstream_uri ''; access_by_lua_block { apisix.http_access_phase() diff --git a/t/APISIX.pm b/t/APISIX.pm index b1361cb..0828f99 100644 --- a/t/APISIX.pm +++ b/t/APISIX.pm @@ -180,6 +180,7 @@ _EOC_ apisix.stream_init_worker() } + # fake server, only for test server { listen 1995; @@ -272,6 +273,8 @@ _EOC_ require("apisix").http_init_worker() } + log_format main escape=default '\$remote_addr - \$remote_user [\$time_local] \$http_host "\$request" \$status \$body_bytes_sent \$request_time "\$http_referer" "\$http_user_agent" \$upstream_addr \$upstream_status \$upstream_response_time "\$upstream_scheme://\$upstream_host\$upstream_uri"'; + # fake server, only for test server { listen 1980; @@ -346,6 +349,10 @@ _EOC_ apisix.http_ssl_phase() } + set \$upstream_scheme 'http'; + set \$upstream_host \$host; + set \$upstream_uri ''; + location = /apisix/nginx_status { allow 127.0.0.0/24; access_log off; @@ -360,11 +367,8 @@ _EOC_ location / { set \$upstream_mirror_host ''; - set \$upstream_scheme 'http'; - set \$upstream_host \$host; set \$upstream_upgrade ''; set \$upstream_connection ''; - set \$upstream_uri ''; set \$upstream_cache_zone off; set \$upstream_cache_key '';