Skip to content

Commit

Permalink
fix(api) consumers endpoint filtering by custom id
Browse files Browse the repository at this point in the history
This issue was reported by @JoarSvensson on issue #4402.
  • Loading branch information
bungle committed Mar 26, 2019
1 parent cc70c38 commit caaa2de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kong/api/routes/consumers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ return {

-- Search by custom_id: /consumers?custom_id=xxx
if args.custom_id then
self.params.consumers = args.custom_id
local consumer, _, err_t = endpoints.select_entity(self, db, db.consumers.schema, "select_by_custom_id")
local opts = endpoints.extract_options(args, db.consumers.schema, "select")
local consumer, _, err_t = db.consumers:select_by_custom_id(args.custom_id, opts)
if err_t then
return endpoints.handle_error(err_t)
end
Expand Down
11 changes: 11 additions & 0 deletions spec/02-integration/04-admin_api/03-consumers_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit caaa2de

Please sign in to comment.