Skip to content

Commit d6f7904

Browse files
authored
fix(upstreams) check upper bound on healthcheck time values (#3306)
Check for the upper bound of all `timeout` and `interval` fields in the health check configuration.
1 parent 8818de8 commit d6f7904

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

kong/dao/schemas/upstreams.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ local SLOTS_MIN, SLOTS_MAX = 10, 2^16
88
local SLOTS_MSG = "number of slots must be between " .. SLOTS_MIN .. " and " .. SLOTS_MAX
99

1010

11-
local function check_nonnegative(arg)
12-
if arg < 0 then
13-
return false, "must be greater than or equal to 0"
11+
local function check_seconds(arg)
12+
if arg < 0 or arg > 65535 then
13+
return false, "must be between 0 and 65535"
1414
end
1515
end
1616

@@ -108,9 +108,9 @@ local healthchecks_defaults = {
108108

109109

110110
local funcs = {
111-
timeout = check_nonnegative,
111+
timeout = check_seconds,
112112
concurrency = check_positive_int,
113-
interval = check_nonnegative,
113+
interval = check_seconds,
114114
successes = check_positive_int_or_zero,
115115
tcp_failures = check_positive_int_or_zero,
116116
timeouts = check_positive_int_or_zero,

spec/01-unit/007-entities_schemas_spec.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,15 @@ describe("Entities Schemas", function()
752752

753753
-- tests for failure
754754
local tests = {
755-
{{ active = { timeout = -1 }}, "greater than or equal to 0" },
755+
{{ active = { timeout = -1 }}, "between 0 and 65535" },
756+
{{ active = { timeout = 1e+42 }}, "between 0 and 65535" },
756757
{{ active = { concurrency = 0.5 }}, "must be an integer" },
757758
{{ active = { concurrency = 0 }}, "must be an integer" },
758759
{{ active = { concurrency = -10 }}, "must be an integer" },
759760
{{ active = { http_path = "" }}, "is empty" },
760761
{{ active = { http_path = "ovo" }}, "must be prefixed with slash" },
761-
{{ active = { healthy = { interval = -1 }}}, "greater than or equal to 0" },
762+
{{ active = { healthy = { interval = -1 }}}, "between 0 and 65535" },
763+
{{ active = { healthy = { interval = 1e+42 }}}, "between 0 and 65535" },
762764
{{ active = { healthy = { http_statuses = 404 }}}, "not an array" },
763765
{{ active = { healthy = { http_statuses = { "ovo" }}}}, "not a number" },
764766
{{ active = { healthy = { http_statuses = { -1 }}}}, "status code" },
@@ -768,7 +770,8 @@ describe("Entities Schemas", function()
768770
{{ active = { healthy = { successes = 0.5 }}}, "must be 0 (disabled), or an integer" },
769771
--{{ active = { healthy = { successes = 0 }}}, "must be an integer" },
770772
{{ active = { healthy = { successes = -1 }}}, "an integer between" },
771-
{{ active = { unhealthy = { interval = -1 }}}, "greater than or equal to 0" },
773+
{{ active = { unhealthy = { interval = -1 }}}, "between 0 and 65535" },
774+
{{ active = { unhealthy = { interval = 1e+42 }}}, "between 0 and 65535" },
772775
{{ active = { unhealthy = { http_statuses = 404 }}}, "not an array" },
773776
{{ active = { unhealthy = { http_statuses = { "ovo" }}}}, "not a number" },
774777
{{ active = { unhealthy = { http_statuses = { -1 }}}}, "status code" },

0 commit comments

Comments
 (0)