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 e75fe68
Show file tree
Hide file tree
Showing 4 changed files with 5 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
2 changes: 1 addition & 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,7 @@ 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 multiple tags with AND", function()
Expand Down

0 comments on commit e75fe68

Please sign in to comment.