mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-03 20:47:35 +08:00
fix(standalone): require consumer's id to be the same as username (#3394)
We already did the same thing with the configuration from etcd.
This commit is contained in:
parent
d698220341
commit
c8d35cd73c
@ -97,13 +97,29 @@ local function check_consumer(consumer)
|
||||
end
|
||||
|
||||
|
||||
local function filter(consumer)
|
||||
if not consumer.value then
|
||||
return
|
||||
end
|
||||
|
||||
-- We expect the id is the same as username. Fix up it here if it isn't.
|
||||
consumer.value.id = consumer.value.username
|
||||
end
|
||||
|
||||
|
||||
function _M.init_worker()
|
||||
local err
|
||||
consumers, err = core.config.new("/consumers", {
|
||||
automatic = true,
|
||||
item_schema = core.schema.consumer,
|
||||
checker = check_consumer,
|
||||
})
|
||||
local config = core.config.new()
|
||||
local cfg = {
|
||||
automatic = true,
|
||||
item_schema = core.schema.consumer,
|
||||
checker = check_consumer,
|
||||
}
|
||||
if config.type ~= "etcd" then
|
||||
cfg.filter = filter
|
||||
end
|
||||
|
||||
consumers, err = core.config.new("/consumers", cfg)
|
||||
if not consumers then
|
||||
error("failed to create etcd instance for fetching consumers: " .. err)
|
||||
return
|
||||
|
@ -98,3 +98,32 @@ consumers:
|
||||
--- request
|
||||
GET /apisix/plugin/jwt/sign?key=user-key
|
||||
--- error_code: 200
|
||||
|
||||
|
||||
|
||||
=== TEST 4: consummer restriction
|
||||
--- apisix_yaml
|
||||
consumers:
|
||||
- username: jack
|
||||
plugins:
|
||||
key-auth:
|
||||
key: user-key
|
||||
routes:
|
||||
- id: 1
|
||||
methods:
|
||||
- POST
|
||||
uri: "/hello"
|
||||
plugins:
|
||||
key-auth:
|
||||
consumer-restriction:
|
||||
whitelist:
|
||||
- jack
|
||||
upstream:
|
||||
type: roundrobin
|
||||
nodes:
|
||||
"127.0.0.1:1980": 1
|
||||
#END
|
||||
--- more_headers
|
||||
apikey: user-key
|
||||
--- request
|
||||
POST /hello
|
||||
|
Loading…
Reference in New Issue
Block a user