From e02baebbef0268114d93474e41b1e7ed7f59e957 Mon Sep 17 00:00:00 2001 From: Yitian Huang Date: Mon, 25 Jan 2021 10:08:29 +0800 Subject: [PATCH] fix: validation for timeouts in upstream schema that can be zero (#3401) --- apisix/schema_def.lua | 6 +++--- t/admin/upstream2.t | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua index a15fa8336006..991ab430f20c 100644 --- a/apisix/schema_def.lua +++ b/apisix/schema_def.lua @@ -314,9 +314,9 @@ local upstream_schema = { timeout = { type = "object", properties = { - connect = {type = "number", minimum = 0}, - send = {type = "number", minimum = 0}, - read = {type = "number", minimum = 0}, + connect = {type = "number", exclusiveMinimum = 0}, + send = {type = "number", exclusiveMinimum = 0}, + read = {type = "number", exclusiveMinimum = 0}, }, required = {"connect", "send", "read"}, }, diff --git a/t/admin/upstream2.t b/t/admin/upstream2.t index f4e9366197fa..3ea83b571321 100644 --- a/t/admin/upstream2.t +++ b/t/admin/upstream2.t @@ -253,3 +253,36 @@ GET /index.html --- error_code: 502 --- error_log no valid upstream node + + + +=== TEST 9: upstream timeouts equal to zero +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/upstreams/1', + ngx.HTTP_PUT, + [[{ + "nodes": { + "127.0.0.1:8080": 1 + }, + "type": "roundrobin", + "timeout": { + "connect": 0, + "send": 0, + "read": 0 + } + }]] + ) + ngx.status = code + ngx.print(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body_like eval +qr/{"error_msg":"invalid configuration: property \\\"timeout\\\" validation failed: property \\\"(connect|send|read)\\\" validation failed: expected 0 to be sctrictly greater than 0"}/ +--- no_error_log +[error]