From 50c1a5d29b365f11f1c4dec105a0413abde0daf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Nowak?= Date: Mon, 30 Sep 2024 10:02:39 +0200 Subject: [PATCH] fix(admin): allow to receive empty tags Previously Admin API crashed when tags=''. This commit treats tags='' as empty. KAG-5496 Fix #13591 --- kong/api/endpoints.lua | 2 +- spec/02-integration/04-admin_api/14-tags_spec.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index 3129fe6ddbe7..acb26c3a7c97 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -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] diff --git a/spec/02-integration/04-admin_api/14-tags_spec.lua b/spec/02-integration/04-admin_api/14-tags_spec.lua index 37586104683d..468019dd49cf 100644 --- a/spec/02-integration/04-admin_api/14-tags_spec.lua +++ b/spec/02-integration/04-admin_api/14-tags_spec.lua @@ -36,6 +36,8 @@ describe("Admin API - tags", function() }) end + bp.consumers:insert({ username = "utagged-consumer"}) + assert(helpers.start_kong { database = strategy, }) @@ -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",