Skip to content

Commit

Permalink
fixup! fix(admin): reject AdminAPI call with empty tags
Browse files Browse the repository at this point in the history
PR Review fixes - improve error message: remove info about empty string
  • Loading branch information
nowNick committed Oct 30, 2024
1 parent 3818583 commit 4c7f8b0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ local function extract_options(db, args, schema, context)
end

if schema.fields.tags and args.tags ~= nil and context == "page" then
if args.tags == null then
local error_message = "tags cannot be null (or empty string)"
if args.tags == null or #args.tags == 0 then
local error_message = "cannot be null"
return nil, error_message, db[schema.name].errors:invalid_options({tags = error_message})
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ describe("Admin API (#" .. strategy .. "): ", function()
})
res = assert.res_status(400, res)
local json = cjson.decode(res)
assert.same("invalid option (tags: tags cannot be null (or empty string))", json.message)
assert.same("invalid option (tags: cannot be null)", json.message)
end)
end)
it("returns 405 on invalid method", function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ describe("Admin API: #" .. strategy, function()
})
res = assert.res_status(400, res)
local json = cjson.decode(res)
assert.same("invalid option (tags: tags cannot be null (or empty string))", json.message)
assert.same("invalid option (tags: cannot be null)", json.message)
end)

describe("empty results", function()
Expand Down
12 changes: 11 additions & 1 deletion spec/02-integration/04-admin_api/14-tags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ describe("Admin API - tags", function()
})
local body = assert.res_status(400, res)
local json = cjson.decode(body)
assert.same("invalid option (tags: tags cannot be null (or empty string))", json.message)
assert.same("invalid option (tags: cannot be null)", json.message)
end)

it("filter by empty string tag", function()
local res = assert(client:send {
method = "GET",
path = "/consumers?tags=''"
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.equals(0, #json.data)
end)

it("filter by multiple tags with AND", function()
Expand Down

0 comments on commit 4c7f8b0

Please sign in to comment.