You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2020/11/12 06:41:29 UTC

[apisix] branch master updated: chore: sort the request headers output by the _M.uri and _M.old_uri function in t/lib/server.lua (#2696)

This is an automated email from the ASF dual-hosted git repository.

spacewander 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 2ba28ff  chore: sort the request headers output by the _M.uri and _M.old_uri  function in t/lib/server.lua (#2696)
2ba28ff is described below

commit 2ba28ff6a7a1823c3ea37e2cdcd7427d4244f3d9
Author: Firstsawyou <52...@users.noreply.github.com>
AuthorDate: Thu Nov 12 14:37:51 2020 +0800

    chore: sort the request headers output by the _M.uri and _M.old_uri  function in t/lib/server.lua (#2696)
    
    fix #2636
---
 t/lib/server.lua        | 22 ++++++++++++++++++----
 t/node/merge-route.t    |  2 +-
 t/plugin/hmac-auth.t    | 39 ++++++++++++++++++---------------------
 t/plugin/proxy-mirror.t |  6 +++---
 4 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/t/lib/server.lua b/t/lib/server.lua
index 67e7932..12883ac 100644
--- a/t/lib/server.lua
+++ b/t/lib/server.lua
@@ -101,8 +101,15 @@ function _M.uri()
     -- ngx.sleep(1)
     ngx.say("uri: ", ngx.var.uri)
     local headers = ngx.req.get_headers()
-    for k, v in pairs(headers) do
-        ngx.say(k, ": ", v)
+
+    local keys = {}
+    for k in pairs(headers) do
+        table.insert(keys, k)
+    end
+    table.sort(keys)
+
+    for _, key in ipairs(keys) do
+        ngx.say(key, ": ", headers[key])
     end
 end
 _M.uri_plugin_proxy_rewrite = _M.uri
@@ -112,8 +119,15 @@ function _M.old_uri()
     -- ngx.sleep(1)
     ngx.say("uri: ", ngx.var.uri)
     local headers = ngx.req.get_headers()
-    for k, v in pairs(headers) do
-        ngx.say(k, ": ", v)
+
+    local keys = {}
+    for k in pairs(headers) do
+        table.insert(keys, k)
+    end
+    table.sort(keys)
+
+    for _, key in ipairs(keys) do
+        ngx.say(key, ": ", headers[key])
     end
 end
 
diff --git a/t/node/merge-route.t b/t/node/merge-route.t
index 0ce1faa..1e1b23f 100644
--- a/t/node/merge-route.t
+++ b/t/node/merge-route.t
@@ -394,8 +394,8 @@ passed
 GET /uri
 --- response_body
 uri: /uri
-host: localhost
 connection: close
+host: localhost
 x-real-ip: 127.0.0.1
 --- no_error_log
 [error]
diff --git a/t/plugin/hmac-auth.t b/t/plugin/hmac-auth.t
index 7e14db4..072ef64 100644
--- a/t/plugin/hmac-auth.t
+++ b/t/plugin/hmac-auth.t
@@ -1004,7 +1004,7 @@ location /t {
 
         local headers_arr = ngx_re.split(body, "\n")
         for i, v in ipairs(headers_arr) do
-            if i ~= 4 then      -- skip date
+            if i ~= 4 and i ~= 6 then      -- skip date and user-agent field
                 ngx.say(v)
             end
         end
@@ -1014,14 +1014,13 @@ location /t {
 GET /t
 --- response_body
 uri: /uri
-host: 127.0.0.1
-content-type: application/x-www-form-urlencoded
-x-real-ip: 127.0.0.1
 content-length: 52
+content-type: application/x-www-form-urlencoded
+host: 127.0.0.1
+x-custom-header-a: asld$%dfasf
 x-custom-header-b: 23879fmsldfk
 x-hmac-access-key: my-access-key4
-user-agent: lua-resty-http/0.14 (Lua) ngx_lua/10017
-x-custom-header-a: asld$%dfasf
+x-real-ip: 127.0.0.1
 --- no_error_log
 [error]
 
@@ -1120,7 +1119,7 @@ location /t {
 
         local headers_arr = ngx_re.split(body, "\n")
         for i, v in ipairs(headers_arr) do
-            if i ~= 4 then      -- skip date
+            if i ~= 4 and i ~= 6 then      -- skip date and user-agent field
                 ngx.say(v)
             end
         end
@@ -1130,14 +1129,13 @@ location /t {
 GET /t
 --- response_body
 uri: /uri
-host: 127.0.0.1
-content-type: application/x-www-form-urlencoded
-x-real-ip: 127.0.0.1
 content-length: 52
+content-type: application/x-www-form-urlencoded
+host: 127.0.0.1
+x-custom-header-a: asld$%dfasf
 x-custom-header-b: 23879fmsldfk
 x-hmac-access-key: my-access-key4
-user-agent: lua-resty-http/0.14 (Lua) ngx_lua/10017
-x-custom-header-a: asld$%dfasf
+x-real-ip: 127.0.0.1
 --- no_error_log
 [error]
 
@@ -1233,10 +1231,10 @@ location /t {
         if code >= 300 then
             ngx.status = code
         end
-        
+
         local headers_arr = ngx_re.split(body, "\n")
         for i, v in ipairs(headers_arr) do
-            if i ~= 4 and i ~= 12 then      -- skip date and x-hmac-signature
+            if i ~= 4 and i ~= 6 and i ~= 11 then      -- skip date, user-agent and x-hmac-signature field
                 ngx.say(v)
             end
         end
@@ -1246,16 +1244,15 @@ location /t {
 GET /t
 --- response_body
 uri: /uri
-host: 127.0.0.1
-content-type: application/x-www-form-urlencoded
-x-real-ip: 127.0.0.1
-user-agent: lua-resty-http/0.14 (Lua) ngx_lua/10017
 content-length: 52
-x-hmac-signed-headers: x-custom-header-a;x-custom-header-b
+content-type: application/x-www-form-urlencoded
+host: 127.0.0.1
+x-custom-header-a: asld$%dfasf
 x-custom-header-b: 23879fmsldfk
-x-hmac-algorithm: hmac-sha256
 x-hmac-access-key: my-access-key4
-x-custom-header-a: asld$%dfasf
+x-hmac-algorithm: hmac-sha256
+x-hmac-signed-headers: x-custom-header-a;x-custom-header-b
+x-real-ip: 127.0.0.1
 --- no_error_log
 [error]
 
diff --git a/t/plugin/proxy-mirror.t b/t/plugin/proxy-mirror.t
index e265a3d..8bdf676 100644
--- a/t/plugin/proxy-mirror.t
+++ b/t/plugin/proxy-mirror.t
@@ -357,11 +357,11 @@ api-key2: world
 name: jake
 --- response_body
 uri: /uri
-host: 127.0.0.2
-x-real-ip: 127.0.0.1
-name: jake
 api-key: hello
 api-key2: world
+host: 127.0.0.2
+name: jake
+x-real-ip: 127.0.0.1
 --- error_log
 api-key: hello
 api-key2: world