From 41d7dae4b3f6571ae59433be1b8551f19b3a2e02 Mon Sep 17 00:00:00 2001 From: levy liu <375636559@qq.com> Date: Wed, 19 Oct 2022 19:24:45 +0800 Subject: [PATCH] fix: workflow plugin should support operator (#8121) --- apisix/plugins/workflow.lua | 9 +++++- t/plugin/workflow.t | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/workflow.lua b/apisix/plugins/workflow.lua index a586a923b9b7..5adb5b455435 100644 --- a/apisix/plugins/workflow.lua +++ b/apisix/plugins/workflow.lua @@ -30,7 +30,14 @@ local schema = { case = { type = "array", items = { - type = "array", + anyOf = { + { + type = "array", + }, + { + type = "string", + }, + } }, minItems = 1, }, diff --git a/t/plugin/workflow.t b/t/plugin/workflow.t index e1bf77a1f26c..422577b27fbf 100644 --- a/t/plugin/workflow.t +++ b/t/plugin/workflow.t @@ -687,3 +687,63 @@ passed "GET /hello", "GET /hello1", "GET /hello", "GET /hello1"] --- error_code eval [200, 200, 200, 200, 200, 200, 503, 503] + + + +=== TEST 19: multiple conditions in one case +--- 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": { + "workflow": { + "rules": [ + { + "case": [ + "OR", + ["arg_foo", "==", "bar"], + ["uri", "==", "/hello"] + ], + "actions": [ + [ + "return", + { + "code": 403 + } + ] + ] + } + ] + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + + ngx.say(body) + } + } +--- response_body +passed + + + +=== TEST 20: trigger workflow +--- request +GET /hello +--- error_code: 403 +--- response_body +{"error_msg":"rejected by workflow"}