Skip to content

Commit

Permalink
fix(admin): allow to receive empty tags
Browse files Browse the repository at this point in the history
Previously Admin API crashed when tags=''. This commit
treats tags='' as empty.

KAG-5496
Fix #13591
  • Loading branch information
nowNick committed Sep 30, 2024
1 parent 7558b4d commit 26a3788
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-admin-api-for-empty-tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Fix for querying admin API entities with emtpy tags
type: bugfix
scope: Admin API
2 changes: 1 addition & 1 deletion kong/api/endpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ local function extract_options(args, schema, context)
args.ttl = nil
end

if schema.fields.tags and args.tags ~= nil and context == "page" then
if schema.fields.tags and args.tags ~= nil and args.tags ~= null and context == "page" then
local tags = args.tags
if type(tags) == "table" then
tags = tags[1]
Expand Down
12 changes: 12 additions & 0 deletions spec/02-integration/04-admin_api/14-tags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ describe("Admin API - tags", function()
})
end

bp.consumers:insert({ username = "utagged-consumer"})

assert(helpers.start_kong {
database = strategy,
})
Expand Down Expand Up @@ -73,6 +75,16 @@ describe("Admin API - tags", function()
end
end)

it("filter by emtpy 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(3, #json.data) -- both tagged and 1 untagged
end)

it("filter by multiple tags with AND", function()
local res = assert(client:send {
method = "GET",
Expand Down

0 comments on commit 26a3788

Please sign in to comment.