Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api) consumers endpoint filtering by custom id #4435

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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