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 2022/03/08 03:37:07 UTC

[apisix] branch master updated: fix(proxy-mirror): pattern validation (#6529)

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 61a5908  fix(proxy-mirror): pattern validation (#6529)
61a5908 is described below

commit 61a590843ad095d3d878482930f118151a4ada8a
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Tue Mar 8 11:37:02 2022 +0800

    fix(proxy-mirror): pattern validation (#6529)
---
 apisix/plugins/proxy-mirror.lua |   3 +-
 t/plugin/proxy-mirror.t         | 106 +++++++++++++++++++---------------------
 2 files changed, 51 insertions(+), 58 deletions(-)

diff --git a/apisix/plugins/proxy-mirror.lua b/apisix/plugins/proxy-mirror.lua
index c1c5e9e..fcbfba0 100644
--- a/apisix/plugins/proxy-mirror.lua
+++ b/apisix/plugins/proxy-mirror.lua
@@ -25,8 +25,7 @@ local schema = {
     properties = {
         host = {
             type = "string",
-            pattern = [[^http(s)?:\/\/[a-zA-Z0-9][-a-zA-Z0-9]{0,62}]]
-                      .. [[(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:[0-9]{1,5})?$]],
+            pattern = [=[^http(s)?:\/\/([\da-zA-Z.-]+|\[[\da-fA-F:]+\])(:\d+)?$]=],
         },
         path = {
             type = "string",
diff --git a/t/plugin/proxy-mirror.t b/t/plugin/proxy-mirror.t
index 65ed9f6..a95c238 100644
--- a/t/plugin/proxy-mirror.t
+++ b/t/plugin/proxy-mirror.t
@@ -56,6 +56,14 @@ add_block_preprocessor(sub {
 _EOC_
 
     $block->set_value("http_config", $http_config);
+
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+
+    if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
+        $block->set_value("no_error_log", "[error]");
+    }
 });
 
 run_tests;
@@ -91,13 +99,9 @@ __DATA__
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 400
 --- response_body eval
 qr/failed to check the configuration of plugin proxy-mirror/
---- no_error_log
-[error]
 
 
 
@@ -130,13 +134,9 @@ qr/failed to check the configuration of plugin proxy-mirror/
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 400
 --- response_body eval
 qr/failed to check the configuration of plugin proxy-mirror/
---- no_error_log
-[error]
 
 
 
@@ -169,13 +169,9 @@ qr/failed to check the configuration of plugin proxy-mirror/
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 400
 --- response_body eval
 qr/failed to check the configuration of plugin proxy-mirror/
---- no_error_log
-[error]
 
 
 
@@ -208,13 +204,9 @@ qr/failed to check the configuration of plugin proxy-mirror/
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
---- no_error_log
-[error]
 
 
 
@@ -247,13 +239,9 @@ passed
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 400
 --- response_body eval
 qr/failed to check the configuration of plugin proxy-mirror/
---- no_error_log
-[error]
 
 
 
@@ -286,13 +274,9 @@ qr/failed to check the configuration of plugin proxy-mirror/
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
---- no_error_log
-[error]
 
 
 
@@ -336,13 +320,9 @@ uri: /hello
                ngx.say(body)
            }
         }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
---- no_error_log
-[error]
 
 
 
@@ -399,13 +379,9 @@ name: jake
                ngx.say(body)
            }
         }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
---- no_error_log
-[error]
 
 
 
@@ -438,13 +414,9 @@ host: 127.0.0.2
                ngx.say(body)
            }
         }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
---- no_error_log
-[error]
 
 
 
@@ -478,13 +450,9 @@ passed
                ngx.print(body)
            }
        }
---- request
-GET /t
 --- error_code: 400
 --- response_body
 {"error_msg":"failed to check the configuration of plugin proxy-mirror err: property \"sample_ratio\" validation failed: expected 10 to be at most 1"}
---- no_error_log
-[error]
 
 
 
@@ -518,13 +486,9 @@ GET /t
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
---- no_error_log
-[error]
 
 
 
@@ -569,8 +533,6 @@ qr/uri: \/hello\?sample_ratio=1/
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- error_code: 200
 --- response_body
 passed
@@ -596,10 +558,6 @@ passed
                 end
            }
        }
---- request
-GET /t
---- no_error_log
-[error]
 --- error_log_like eval
 qr/(uri: \/hello\?sample_ratio=0\.5){75,125}/
 
@@ -635,8 +593,6 @@ qr/(uri: \/hello\?sample_ratio=0\.5){75,125}/
                ngx.say(body)
            }
        }
---- request
-GET /t
 --- response_body
 passed
 
@@ -693,12 +649,50 @@ uri: /a?a=1
                 end
             }
        }
---- request
-GET /t
 --- grep_error_log eval
 qr/property \\"path\\" validation failed: failed to match pattern/
 --- grep_error_log_out
 property \"path\" validation failed: failed to match pattern
 property \"path\" validation failed: failed to match pattern
---- no_error_log
-[error]
+
+
+
+=== TEST 22: sanity check (host)
+--- config
+       location /t {
+           content_by_lua_block {
+               local t = require("lib.test_admin").test
+               for _, p in ipairs({
+                    "http://a",
+                    "http://ab.com",
+                    "http://[::1]",
+                    "http://[::1]:202",
+               }) do
+                    local code, body = t('/apisix/admin/routes/1',
+                        ngx.HTTP_PUT,
+                        [[{
+                            "plugins": {
+                                "proxy-mirror": {
+                                    "host": "]] .. p .. [["
+                                }
+                            },
+                            "upstream": {
+                                "nodes": {
+                                    "127.0.0.1:1980": 1
+                                },
+                                "type": "roundrobin"
+                            },
+                            "uri": "/hello"
+                        }]]
+                        )
+                    ngx.log(ngx.WARN, body)
+                end
+           }
+       }
+--- grep_error_log eval
+qr/(passed|property \\"host\\" validation failed: failed to match pattern)/
+--- grep_error_log_out
+passed
+passed
+passed
+passed