From 1c6ae831da718b81498d97bbde1654d99bbd80f9 Mon Sep 17 00:00:00 2001 From: Aapo Talvensaari Date: Tue, 26 Mar 2019 13:01:07 +0200 Subject: [PATCH] fix(api) consumers endpoint filtering by custom id This issue was reported by @JoarSvensson on issue #4402. --- kong/api/endpoints.lua | 4 ++-- .../04-admin_api/03-consumers_routes_spec.lua | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/kong/api/endpoints.lua b/kong/api/endpoints.lua index a5d223f7f6e8..ad6dddfa4403 100644 --- a/kong/api/endpoints.lua +++ b/kong/api/endpoints.lua @@ -234,10 +234,10 @@ local function query_entity(context, self, db, schema, method) end if is_update then - return dao[method or context](dao, key, args, opts) + return dao[method or context](dao, method and key.id or key, args, opts) end - return dao[method or context](dao, key, opts) + return dao[method or context](dao, method and key.id or key, opts) end diff --git a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua index 51cffecd8882..beccdba92ed5 100644 --- a/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua +++ b/spec/02-integration/04-admin_api/03-consumers_routes_spec.lua @@ -255,6 +255,17 @@ describe("Admin API (#" .. strategy .. "): ", function() local body = assert.res_status(200, res) local json = cjson.decode(body) + assert.equal(1, #json.data) + assert.same(c, json.data[1]) + end) + it("allows filtering by uuid-like custom_id", function() + local custom_id = utils.uuid() + local c = bp.consumers:insert({ custom_id = custom_id }, { nulls = true }) + + local res = client:get("/consumers?custom_id=" .. custom_id) + local body = assert.res_status(200, res) + local json = cjson.decode(body) + assert.equal(1, #json.data) assert.same(c, json.data[1]) end)