spacewander commented on a change in pull request #4849:
URL: https://github.com/apache/apisix/pull/4849#discussion_r692041307
##########
File path: t/plugin/uri-blocker.t
##########
@@ -332,3 +332,37 @@ GET /hello?name=;union%20select%20
GET /hello?cc=2
--- no_error_log
[error]
+
+
+
+=== TEST 16: invalid rejected_msg length or type
+--- config
+location /t {
+ content_by_lua_block {
+ local data = {
+ {
+ input =
'[[{"plugins":{"uri-blocker":{"block_rules":["^a"],"rejected_msg":""}},"uri":"/hello"}]]',
+ output = '{"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"}'
+ },
+ {
+ input =
'[[{"plugins":{"uri-blocker":{"block_rules":["^a"],"rejected_msg":true}},"uri":"/hello"}]]',
+ output = '{"error_msg":"failed to check the configuration of
plugin uri-blocker err: property \"rejected_msg\" validation failed: wrong
type: expected string, got boolean"}'
+ }
+ }
+
+ local t = require("lib.test_admin").test
+ for i in pairs(data) do
+ local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT,
data[i].input, data[i].output)
+
+ if code >= 300 and i == #data then
Review comment:
This will hide the previous failures. We should count the success cases
and check if the number is equal to the total one.
##########
File path: t/plugin/uri-blocker.t
##########
@@ -332,3 +332,37 @@ GET /hello?name=;union%20select%20
GET /hello?cc=2
--- no_error_log
[error]
+
+
+
+=== TEST 16: invalid rejected_msg length or type
+--- config
+location /t {
+ content_by_lua_block {
+ local data = {
+ {
+ input =
'[[{"plugins":{"uri-blocker":{"block_rules":["^a"],"rejected_msg":""}},"uri":"/hello"}]]',
+ output = '{"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"}'
+ },
+ {
+ input =
'[[{"plugins":{"uri-blocker":{"block_rules":["^a"],"rejected_msg":true}},"uri":"/hello"}]]',
+ output = '{"error_msg":"failed to check the configuration of
plugin uri-blocker err: property \"rejected_msg\" validation failed: wrong
type: expected string, got boolean"}'
+ }
+ }
+
+ local t = require("lib.test_admin").test
+ for i in pairs(data) do
+ local code, body = t('/apisix/admin/routes/1', ngx.HTTP_PUT,
data[i].input, data[i].output)
Review comment:
In fact, the arguments don't need to be string. You can pass table
directly. A long string is hard to read & edit.
--
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]