okaybase commented on a change in pull request #4849:
URL: https://github.com/apache/apisix/pull/4849#discussion_r692070516



##########
File path: t/plugin/uri-blocker.t
##########
@@ -332,3 +332,130 @@ GET /hello?name=;union%20select%20
 GET /hello?cc=2
 --- no_error_log
 [error]
+
+
+
+=== TEST 16: invalid rejected_msg length
+--- config
+location /t {
+    content_by_lua_block {
+        local t = require("lib.test_admin").test
+        local code, body = t('/apisix/admin/routes/1',
+            ngx.HTTP_PUT,
+            [[{
+                "plugins": {
+                    "uri-blocker": {
+                        "block_rules": ["^a"],
+                        "rejected_msg": ""
+                    }
+                },
+                "uri": "/hello"
+            }]]
+            )
+
+        if code >= 300 then
+            ngx.status = code
+        end
+        ngx.print(body)
+    }
+}
+--- request
+GET /t
+--- error_code: 400
+--- response_body
+{"error_msg":"failed to check the configuration of plugin uri-blocker err: 
property \"rejected_msg\" validation failed: string too short, expected at 
least 1, got 0"}
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: invalid rejected_msg type
+--- config
+location /t {
+    content_by_lua_block {
+        local t = require("lib.test_admin").test
+        local code, body = t('/apisix/admin/routes/1',
+            ngx.HTTP_PUT,
+            [[{
+                "plugins": {
+                    "uri-blocker": {
+                        "block_rules": ["^a"],
+                        "rejected_msg": true
+                    }
+                },
+                "uri": "/hello"
+            }]]
+            )
+
+        if code >= 300 then
+            ngx.status = code
+        end
+        ngx.print(body)
+    }
+}
+--- request
+GET /t
+--- error_code: 400
+--- response_body
+{"error_msg":"failed to check the configuration of plugin uri-blocker err: 
property \"rejected_msg\" validation failed: wrong type: expected string, got 
boolean"}
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: one block rule, with rejected_msg
+--- config
+location /t {
+    content_by_lua_block {
+        local t = require("lib.test_admin").test
+        local code, body = t('/apisix/admin/routes/1',
+            ngx.HTTP_PUT,
+            [[{
+                "plugins": {
+                    "uri-blocker": {
+                        "block_rules": ["aa"],
+                        "rejected_msg": "access is not allowed"
+                    }
+                },
+                "upstream": {
+                    "nodes": {
+                        "127.0.0.1:1980": 1
+                    },
+                    "type": "roundrobin"
+                },
+                "uri": "/hello"
+            }]],
+            [[{

Review comment:
       okay, got, thanks~




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to