diff --git a/doc/architecture-design-cn.md b/doc/architecture-design-cn.md index 62ec73f1e204..49171cf5b1b7 100644 --- a/doc/architecture-design-cn.md +++ b/doc/architecture-design-cn.md @@ -369,20 +369,72 @@ APISIX 区别于其他 API 网关的一大特点是允许用户选择不同 Rout 如上图所示,作为 API 网关,需要知道 API Consumer(消费方)具体是谁,这样就可以对不同 API Consumer 配置不同规则。 +|字段|必选|说明| +|---|----|----| +|username|是|Consumer 名称。| +|plugins|否|该 Consumer 对应的插件配置,它的优先级是最高的:Consumer > Route > Service。对于具体插件配置,可以参考 [Plugins](#plugin) 章节。| + 在 APISIX 中,识别 Consumer 的过程如下图: -1. 授权认证:比如有 [key-auth](doc/plugins/key-auth.md)、[JWT](doc/plugins/jwt-auth-cn.md) 等。 +1. 授权认证:比如有 [key-auth](./plugins/key-auth.md)、[JWT](./plugins/jwt-auth-cn.md) 等。 2. 获取 consumer_id:通过授权认证,即可自然获取到对应的 Consumer `id`,它是 Consumer 对象的唯一识别标识。 3. 获取 Consumer 上绑定的 Plugin 或 Upstream 信息:完成对不同 Consumer 做不同配置的效果。 概括一下,Consumer 是某类服务的消费者,需与用户认证体系配合才能使用。 比如不同的 Consumer 请求同一个 API,网关服务根据当前请求用户信息,对应不同的 Plugin 或 Upstream 配置。 -此外,大家也可以参考 [key-auth](doc/plugins/key-auth.md) 认证授权插件的调用逻辑,辅助大家来进一步理解 Consumer 概念和使用。 +此外,大家也可以参考 [key-auth](./plugins/key-auth.md) 认证授权插件的调用逻辑,辅助大家来进一步理解 Consumer 概念和使用。 + +如何对某个 Consumer 开启指定插件,可以看下面例子: + +```shell +# 创建 Consumer ,指定认证插件 key-auth ,并开启特定插件 limit-count +$ curl http://127.0.0.1:9080/apisix/admin/consumers/1 -X PUT -d ' +{ + "username": "jack", + "plugins": { + "key-auth": { + "key": "auth-one" + }, + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "key": "remote_addr" + } + } +}' + +# 创建 Router,设置路由规则和启用插件配置 +$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' +{ + "plugins": { + "key-auth": {} + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uri": "/hello" +}' + +# 发测试请求,前两次返回正常,没达到限速阈值 +$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I +... -*注意*:目前 APISIX 的 Consumer 还不支持绑定插件或上游信息,如果大家对这个功能点感兴趣,欢迎在社区中反馈交流。 +$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I +... + +# 第三次测试返回 503,请求被限制 +$ curl http://127.0.0.1:9080/hello -H 'apikey: auth-one' -I +HTTP/1.1 503 Service Temporarily Unavailable +... + +``` [返回目录](#目录) diff --git a/doc/plugins/jwt-auth-cn.md b/doc/plugins/jwt-auth-cn.md index a419808f38bf..acd3285ab341 100644 --- a/doc/plugins/jwt-auth-cn.md +++ b/doc/plugins/jwt-auth-cn.md @@ -33,8 +33,8 @@ curl http://127.0.0.1:9080/apisix/admin/consumers -X PUT -d ' "username": "jack", "plugins": { "jwt-auth": { - "key": "your-consumer-key", - "secret": "secret-key" + "key": "user-key", + "secret": "my-secret-key" } } }' @@ -141,8 +141,7 @@ $ curl http://127.0.0.1:2379/v2/keys/apisix/routes/1 -X PUT -d value=' "methods": ["GET"], "uri": "/index.html", "id": 1, - "plugins": { - }, + "plugins": {}, "upstream": { "type": "roundrobin", "nodes": { diff --git a/doc/plugins/key-auth-cn.md b/doc/plugins/key-auth-cn.md index 7716887462dd..b20fec42f11c 100644 --- a/doc/plugins/key-auth-cn.md +++ b/doc/plugins/key-auth-cn.md @@ -28,7 +28,7 @@ curl http://127.0.0.1:9080/apisix/admin/consumers -X PUT -d ' "username": "jack", "plugins": { "key-auth": { - "key": "keykey" + "key": "auth-one" } } }' diff --git a/doc/plugins/key-auth.md b/doc/plugins/key-auth.md index 331c9668c834..480e47b10e78 100644 --- a/doc/plugins/key-auth.md +++ b/doc/plugins/key-auth.md @@ -25,12 +25,12 @@ Two steps are required: 1. creates a consumer object, and set the attributes of plugin `key-auth`. ```shell - curl http://127.0.0.1:9080/apisix/admin/consumers -X PUT -d ' +curl http://127.0.0.1:9080/apisix/admin/consumers -X PUT -d ' { "username": "jack", "plugins": { "key-auth": { - "key": "keykey" + "key": "auth-one" } } }' diff --git a/lua/apisix.lua b/lua/apisix.lua index 38fa37406151..35f390392c69 100644 --- a/lua/apisix.lua +++ b/lua/apisix.lua @@ -250,6 +250,7 @@ function _M.http_access_phase() core.table.clear(plugins) api_ctx.plugins = plugin.filter(global_rule, plugins) run_plugin("rewrite", plugins, api_ctx) + run_plugin("access", plugins, api_ctx) end core.tablepool.release("plugins", plugins) @@ -298,7 +299,7 @@ function _M.http_access_phase() end local changed - route, changed = plugin.merge_route(service, route) + route, changed = plugin.merge_service_route(service, route) api_ctx.matched_route = route if changed then @@ -338,6 +339,14 @@ function _M.http_access_phase() api_ctx.plugins = plugin.filter(route, plugins) run_plugin("rewrite", plugins, api_ctx) + if api_ctx.consumer then + local changed + route, changed = plugin.merge_consumer_route(route, api_ctx.consumer) + if changed then + core.table.clear(api_ctx.plugins) + api_ctx.plugins = plugin.filter(route, api_ctx.plugins) + end + end run_plugin("access", plugins, api_ctx) end @@ -375,7 +384,7 @@ function _M.grpc_access_phase() end local changed - route, changed = plugin.merge_route(service, route) + route, changed = plugin.merge_service_route(service, route) api_ctx.matched_route = route if changed then diff --git a/lua/apisix/admin/consumers.lua b/lua/apisix/admin/consumers.lua index c2ec6d20d3ed..4138dfd1d29d 100644 --- a/lua/apisix/admin/consumers.lua +++ b/lua/apisix/admin/consumers.lua @@ -1,5 +1,7 @@ -local core = require("apisix.core") +local core = require("apisix.core") local plugins = require("apisix.admin.plugins") +local plugin = require("apisix.plugin") +local pairs = pairs local _M = { version = 0.1, @@ -24,13 +26,26 @@ local function check_conf(consumer_name, conf) return nil, {error_msg = "invalid configuration: " .. err} end - if not conf.plugins then - return consumer_name - end - - ok, err = plugins.check_schema(conf.plugins) - if not ok then - return nil, {error_msg = "invalid configuration: " .. err} + if conf.plugins then + ok, err = plugins.check_schema(conf.plugins) + if not ok then + return nil, {error_msg = "invalid plugins configuration: " .. err} + end + + local count_auth_plugin = 0 + for name, conf in pairs(conf.plugins) do + local plugin_obj = plugin.get(name) + if plugin_obj.type == 'auth' then + count_auth_plugin = count_auth_plugin + 1 + if count_auth_plugin > 1 then + return nil, {error_msg = "only one auth plugin is allowed"} + end + end + end + + if count_auth_plugin == 0 then + return nil, {error_msg = "require one auth plugin"} + end end return consumer_name diff --git a/lua/apisix/consumer.lua b/lua/apisix/consumer.lua index 2f3ff8afac1c..ea6544ae1aea 100644 --- a/lua/apisix/consumer.lua +++ b/lua/apisix/consumer.lua @@ -1,38 +1,16 @@ -local lrucache = require("apisix.core.lrucache") -local schema = require("apisix.core.schema") -local config = require("apisix.core.config_etcd") -local insert_tab = table.insert +local core = require("apisix.core") +local plugin = require("apisix.plugin") +local error = error +local ipairs = ipairs +local pairs = pairs local consumers -local error = error -local ipairs = ipairs -local pairs = pairs local _M = { - version = 0.1, + version = 0.2, } - --[[ - { - "id": "ShunFeng", - "plugins": { - "key-auth": { - "key": "dddxxyyy" - } - } - } - to - - { - key-auth: [ - { - "key": "dddxxyyy", - "consumer_id": "ShunFeng" - } - ] - } - ]] local function plugin_consumer() local plugins = {} @@ -41,17 +19,23 @@ local function plugin_consumer() end for _, consumer in ipairs(consumers.values) do - for name, conf in pairs(consumer.value.plugins) do - if not plugins[name] then + for name, config in pairs(consumer.value.plugins or {}) do + local plugin_obj = plugin.get(name) + if plugin_obj and plugin_obj.type == "auth" + and not plugins[name] then plugins[name] = { nodes = {}, - conf_version = consumers.conf_version, + conf_version = consumers.conf_version } - end + local new_consumer = core.table.clone(consumer.value) + new_consumer.consumer_id = new_consumer.id + new_consumer.auth_conf = config + core.log.info("consumer:", core.json.delay_encode(new_consumer)) + core.table.insert(plugins[name].nodes, new_consumer) - insert_tab(plugins[name].nodes, - {consumer_id = consumer.value.id, conf = conf}) + break + end end end @@ -60,19 +44,18 @@ end function _M.plugin(plugin_name) - local plugin_conf = lrucache.global("/consumers", - consumers.conf_version, plugin_consumer) + local plugin_conf = core.lrucache.global("/consumers", + consumers.conf_version, plugin_consumer) return plugin_conf[plugin_name] end function _M.init_worker() local err - consumers, err = config.new("/consumers", - { - automatic = true, - item_schema = schema.consumer - }) + consumers, err = core.config.new("/consumers", { + automatic = true, + item_schema = core.schema.consumer + }) if not consumers then error("failed to create etcd instance for fetching consumers: " .. err) return diff --git a/lua/apisix/core.lua b/lua/apisix/core.lua index cdfe6ef11dd2..a5434284dc71 100644 --- a/lua/apisix/core.lua +++ b/lua/apisix/core.lua @@ -21,6 +21,5 @@ return { utils = require("apisix.core.utils"), etcd = require("apisix.core.etcd"), http = require("apisix.core.http"), - consumer = require("apisix.consumer"), tablepool= require("tablepool"), } diff --git a/lua/apisix/plugin.lua b/lua/apisix/plugin.lua index ee9ee3ffb4b0..4eb32271c002 100644 --- a/lua/apisix/plugin.lua +++ b/lua/apisix/plugin.lua @@ -280,57 +280,83 @@ function _M.stream_filter(user_route, plugins) end -local function merge_route(base_route_conf, route_conf) - local new_route_conf +local function merge_service_route(service_conf, route_conf) + local new_service_conf if route_conf.value.plugins then for name, conf in pairs(route_conf.value.plugins) do - if not new_route_conf then - new_route_conf = core.table.deepcopy(base_route_conf) + if not new_service_conf then + new_service_conf = core.table.deepcopy(service_conf) end - new_route_conf.value.plugins[name] = conf + new_service_conf.value.plugins[name] = conf end end local route_upstream = route_conf.value.upstream if route_upstream then - if not new_route_conf then - new_route_conf = core.table.deepcopy(base_route_conf) + if not new_service_conf then + new_service_conf = core.table.deepcopy(service_conf) end - new_route_conf.value.upstream = route_upstream + new_service_conf.value.upstream = route_upstream if route_upstream.checks then route_upstream.parent = route_conf end - new_route_conf.value.upstream_id = nil - return new_route_conf + new_service_conf.value.upstream_id = nil + return new_service_conf end if route_conf.value.upstream_id then - if not new_route_conf then - new_route_conf = core.table.deepcopy(base_route_conf) + if not new_service_conf then + new_service_conf = core.table.deepcopy(service_conf) end - new_route_conf.value.upstream_id = route_conf.value.upstream_id + new_service_conf.value.upstream_id = route_conf.value.upstream_id end - -- core.log.info("merged conf : ", core.json.delay_encode(new_route_conf)) - return new_route_conf or base_route_conf + -- core.log.info("merged conf : ", core.json.delay_encode(new_service_conf)) + return new_service_conf or service_conf end -function _M.merge_route(base_route_conf, route_conf) - core.log.info("service conf: ", core.json.delay_encode(base_route_conf)) - -- core.log.info("route conf : ", core.json.delay_encode(route_conf)) +function _M.merge_service_route(service_conf, route_conf) + core.log.info("service conf: ", core.json.delay_encode(service_conf)) + core.log.info("route conf: ", core.json.delay_encode(route_conf)) + + local flag = tostring(service_conf) .. tostring(route_conf) + local new_service_conf = merged_route(flag, nil, merge_service_route, + service_conf, route_conf) + + return new_service_conf, new_service_conf ~= service_conf +end + + +local function merge_consumer_route(route_conf, consumer_conf) + local new_route_conf - local flag = tostring(base_route_conf) .. tostring(route_conf) - local new_route_conf = merged_route(flag, nil, merge_route, - base_route_conf, route_conf) - if new_route_conf == base_route_conf then - return new_route_conf, false + if consumer_conf.plugins then + for name, conf in pairs(consumer_conf.plugins) do + if not new_route_conf then + new_route_conf = core.table.deepcopy(route_conf) + end + new_route_conf.value.plugins[name] = conf + end end - return new_route_conf, true + core.log.info("merged conf : ", core.json.delay_encode(new_route_conf)) + return new_route_conf or route_conf +end + + +function _M.merge_consumer_route(route_conf, consumer_conf) + core.log.info("route conf: ", core.json.delay_encode(route_conf)) + core.log.info("consumer conf: ", core.json.delay_encode(consumer_conf)) + + local flag = tostring(route_conf) .. tostring(consumer_conf) + local new_conf = merged_route(flag, nil, + merge_consumer_route, route_conf, consumer_conf) + + return new_conf, new_conf ~= route_conf end diff --git a/lua/apisix/plugins/jwt-auth.lua b/lua/apisix/plugins/jwt-auth.lua index 2d965a3d425b..fb6c754cb396 100644 --- a/lua/apisix/plugins/jwt-auth.lua +++ b/lua/apisix/plugins/jwt-auth.lua @@ -1,8 +1,9 @@ -local core = require("apisix.core") -local jwt = require("resty.jwt") -local ck = require("resty.cookie") -local ipairs= ipairs -local ngx = ngx +local core = require("apisix.core") +local jwt = require("resty.jwt") +local ck = require("resty.cookie") +local consumer = require("apisix.consumer") +local ipairs = ipairs +local ngx = ngx local ngx_time = ngx.time local plugin_name = "jwt-auth" @@ -24,6 +25,7 @@ local schema = { local _M = { version = 0.1, priority = 2510, + type = 'auth', name = plugin_name, schema = schema, } @@ -37,7 +39,8 @@ do core.table.clear(consumer_ids) for _, consumer in ipairs(consumers.nodes) do - consumer_ids[consumer.conf.key] = consumer + core.log.info("consumer node: ", core.json.delay_encode(consumer)) + consumer_ids[consumer.auth_conf.key] = consumer end return consumer_ids @@ -112,7 +115,11 @@ function _M.rewrite(conf, ctx) return 401, {message = "missing user key in JWT token"} end - local consumer_conf = core.consumer.plugin(plugin_name) + local consumer_conf = consumer.plugin(plugin_name) + if not consumer_conf then + return 401, {message = "Missing related consumer"} + end + local consumers = core.lrucache.plugin(plugin_name, "consumers_key", consumer_conf.conf_version, create_consume_cache, consumer_conf) @@ -123,12 +130,13 @@ function _M.rewrite(conf, ctx) end core.log.info("consumer: ", core.json.delay_encode(consumer)) - jwt_obj = jwt:verify_jwt_obj(consumer.conf.secret, jwt_obj) + jwt_obj = jwt:verify_jwt_obj(consumer.auth_conf.secret, jwt_obj) core.log.info("jwt object: ", core.json.delay_encode(jwt_obj)) if not jwt_obj.verified then return 401, {message = jwt_obj.reason} end + ctx.consumer = consumer ctx.consumer_id = consumer.consumer_id core.log.info("hit jwt-auth rewrite") end @@ -142,7 +150,7 @@ local function gen_token() local key = args.key - local consumer_conf = core.consumer.plugin(plugin_name) + local consumer_conf = consumer.plugin(plugin_name) if not consumer_conf then return core.response.exit(404) end @@ -157,16 +165,18 @@ local function gen_token() return core.response.exit(404) end + core.log.info("consumer: ", core.json.delay_encode(consumer)) + local jwt_token = jwt:sign( - consumer.conf.secret, + consumer.auth_conf.secret, { header={ typ = "JWT", - alg = consumer.conf.algorithm + alg = consumer.auth_conf.algorithm }, payload={ key = key, - exp = ngx_time() + consumer.conf.exp + exp = ngx_time() + consumer.auth_conf.exp } } ) diff --git a/lua/apisix/plugins/key-auth.lua b/lua/apisix/plugins/key-auth.lua index 2a7791645710..b328e9dd426e 100644 --- a/lua/apisix/plugins/key-auth.lua +++ b/lua/apisix/plugins/key-auth.lua @@ -1,6 +1,7 @@ -local core = require("apisix.core") +local core = require("apisix.core") +local consumer = require("apisix.consumer") local plugin_name = "key-auth" -local ipairs = ipairs +local ipairs = ipairs local schema = { @@ -14,6 +15,7 @@ local schema = { local _M = { version = 0.1, priority = 2500, + type = 'auth', name = plugin_name, schema = schema, } @@ -27,7 +29,8 @@ do core.table.clear(consumer_ids) for _, consumer in ipairs(consumers.nodes) do - consumer_ids[consumer.conf.key] = consumer + core.log.info("consumer node: ", core.json.delay_encode(consumer)) + consumer_ids[consumer.auth_conf.key] = consumer end return consumer_ids @@ -47,7 +50,11 @@ function _M.rewrite(conf, ctx) return 401, {message = "Missing API key found in request"} end - local consumer_conf = core.consumer.plugin(plugin_name) + local consumer_conf = consumer.plugin(plugin_name) + if not consumer_conf then + return 401, {message = "Missing related consumer"} + end + local consumers = core.lrucache.plugin(plugin_name, "consumers_key", consumer_conf.conf_version, create_consume_cache, consumer_conf) @@ -58,6 +65,7 @@ function _M.rewrite(conf, ctx) end core.log.info("consumer: ", core.json.delay_encode(consumer)) + ctx.consumer = consumer ctx.consumer_id = consumer.consumer_id core.log.info("hit key-auth rewrite") end diff --git a/lua/apisix/plugins/limit-count.lua b/lua/apisix/plugins/limit-count.lua index 53824d7df487..4ff8cb3c1fb8 100644 --- a/lua/apisix/plugins/limit-count.lua +++ b/lua/apisix/plugins/limit-count.lua @@ -38,7 +38,7 @@ local function create_limit_obj(conf) end -function _M.rewrite(conf, ctx) +function _M.access(conf, ctx) core.log.info("ver: ", ctx.conf_version) local lim, err = core.lrucache.plugin_ctx(plugin_name, ctx, create_limit_obj, conf) diff --git a/lua/apisix/schema_def.lua b/lua/apisix/schema_def.lua index faaf9cd610eb..af6ac43c0755 100644 --- a/lua/apisix/schema_def.lua +++ b/lua/apisix/schema_def.lua @@ -338,7 +338,7 @@ _M.consumer = { pattern = [[^[a-zA-Z0-9_]+$]] }, plugins = plugins_schema, - desc = {type = "string", maxLength = 256}, + desc = {type = "string", maxLength = 256} }, required = {"username"}, additionalProperties = false, diff --git a/t/admin/consumers.t b/t/admin/consumers.t index 23d202e01302..14bd0dc6ef22 100644 --- a/t/admin/consumers.t +++ b/t/admin/consumers.t @@ -16,8 +16,8 @@ __DATA__ content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/consumers', - ngx.HTTP_PUT, - [[{ + ngx.HTTP_PUT, + [[{ "username":"jack", "desc": "new consumer" }]], diff --git a/t/node/consumer-plugin.t b/t/node/consumer-plugin.t new file mode 100644 index 000000000000..a5f20581bd0b --- /dev/null +++ b/t/node/consumer-plugin.t @@ -0,0 +1,208 @@ +use t::APISIX 'no_plan'; + +repeat_each(1); +no_long_string(); +no_root_location(); +run_tests; + +__DATA__ + +=== TEST 1: add consumer with username and plugins +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/consumers', + ngx.HTTP_PUT, + [[{ + "username": "jack", + "plugins": { + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "key": "remote_addr" + }, + "key-auth": { + "key": "auth-one" + } + } + }]], + [[{ + "node": { + "value": { + "username": "jack", + "plugins": { + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "key": "remote_addr" + }, + "key-auth": { + "key": "auth-one" + } + } + } + }, + "action": "set" + }]] + ) + + ngx.status = code + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 2: enable key auth plugin using admin api +--- 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": { + "key-auth": {} + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + }, + "uri": "/hello" + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 3: invalid consumer +--- request +GET /hello +--- more_headers +apikey: 123 +--- error_code: 401 +--- response_body +{"message":"Invalid API key in request"} +--- no_error_log +[error] + + + +=== TEST 4: valid consumer +--- request +GET /hello +--- more_headers +apikey: auth-one +--- response_body +hello world +--- no_error_log +[error] + + + +=== TEST 5: up the limit +--- pipelined_requests eval +["GET /hello", "GET /hello", "GET /hello", "GET /hello"] +--- more_headers +apikey: auth-one +--- error_code eval +[200, 200, 503, 503] +--- no_error_log +[error] + + + +=== TEST 6: two auth plugins (not allow) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/consumers', + ngx.HTTP_PUT, + [[{ + "username": "jack", + "plugins": { + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "key": "remote_addr" + }, + "key-auth": { + "key": "auth-one" + }, + "jwt-auth": { + "key": "auth-one" + } + } + }]] + ) + + ngx.status = code + ngx.print(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body +{"error_msg":"only one auth plugin is allowed"} +--- no_error_log +[error] + + + +=== TEST 7: missing auth plugins (not allow) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/consumers', + ngx.HTTP_PUT, + [[{ + "username": "jack", + "plugins": { + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "key": "remote_addr" + } + } + }]] + ) + + ngx.status = code + ngx.print(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body +{"error_msg":"require one auth plugin"} +--- no_error_log +[error] diff --git a/t/node/global-rule.t b/t/node/global-rule.t index c4e3c2bb1503..0ec3ab0775d6 100644 --- a/t/node/global-rule.t +++ b/t/node/global-rule.t @@ -54,7 +54,26 @@ passed -=== TEST 2: /not_found +=== TEST 2: delete route(id: 1) +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/routes/1', ngx.HTTP_DELETE) + + ngx.say("passed") + } + } +--- request +GET /t +--- response_body +passed +--- no_error_log +[error] + + + +=== TEST 3: /not_found --- request GET /not_found --- error_code: 404 @@ -65,7 +84,7 @@ qr/404 Not Found/ -=== TEST 3: /not_found +=== TEST 4: /not_found --- request GET /hello --- error_code: 404 @@ -76,7 +95,7 @@ qr/404 Not Found/ -=== TEST 4: /not_found +=== TEST 5: /not_found --- request GET /hello --- error_code: 503 @@ -85,7 +104,7 @@ GET /hello -=== TEST 5: delete global rule +=== TEST 6: delete global rule --- config location /t { content_by_lua_block { diff --git a/t/node/merge-route.t b/t/node/merge-route.t index 916e6038bc1e..5516553a7890 100644 --- a/t/node/merge-route.t +++ b/t/node/merge-route.t @@ -215,5 +215,5 @@ location /t { --- request GET /t --- error_log eval -[qr/merge_route.*"time_window":60,"rejected_code":503/, -qr/merge_route.*"time_window":60,"rejected_code":503/] +[qr/merge_service_route.*"time_window":60,"rejected_code":503/, +qr/merge_service_route.*"time_window":60,"rejected_code":503/] diff --git a/t/plugin/jwt-auth.t b/t/plugin/jwt-auth.t index 25ef2da11f97..9747fc1c7df5 100644 --- a/t/plugin/jwt-auth.t +++ b/t/plugin/jwt-auth.t @@ -63,15 +63,15 @@ done content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/consumers', - ngx.HTTP_PUT, - [[{ + ngx.HTTP_PUT, + [[{ "username": "jack", "plugins": { - "jwt-auth": { - "key": "user-key", - "secret": "my-secret-key" - } + "jwt-auth": { + "key": "user-key", + "secret": "my-secret-key" } + } }]], [[{ "node": { @@ -108,18 +108,18 @@ passed content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', - ngx.HTTP_PUT, - [[{ - "plugins": { - "jwt-auth": {} - }, - "upstream": { - "nodes": { - "127.0.0.1:1980": 1 - }, - "type": "roundrobin" + ngx.HTTP_PUT, + [[{ + "plugins": { + "jwt-auth": {} + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 }, - "uri": "/hello" + "type": "roundrobin" + }, + "uri": "/hello" }]] ) diff --git a/t/plugin/key-auth.t b/t/plugin/key-auth.t index b4bb3d0236b5..fb6d545595a5 100644 --- a/t/plugin/key-auth.t +++ b/t/plugin/key-auth.t @@ -58,14 +58,14 @@ done content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/consumers', - ngx.HTTP_PUT, - [[{ + ngx.HTTP_PUT, + [[{ "username": "jack", "plugins": { - "key-auth": { - "key": "auth-one" - } + "key-auth": { + "key": "auth-one" } + } }]], [[{ "node": { @@ -101,18 +101,18 @@ passed content_by_lua_block { local t = require("lib.test_admin").test local code, body = t('/apisix/admin/routes/1', - ngx.HTTP_PUT, - [[{ - "plugins": { - "key-auth": {} - }, - "upstream": { - "nodes": { - "127.0.0.1:1980": 1 - }, - "type": "roundrobin" + ngx.HTTP_PUT, + [[{ + "plugins": { + "key-auth": {} + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 }, - "uri": "/hello" + "type": "roundrobin" + }, + "uri": "/hello" }]] )