-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: consumer key duplication check #12040
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
base: master
Are you sure you want to change the base?
Changes from all commits
ce80722
489a985
a3a4ac2
fa3caa8
ef0a8ea
80ce431
93a4b63
5e0fe0f
5660ad2
6cb6b78
02daa2c
3b2aa93
7d2d930
7fe1827
38430a0
95c2a92
de68197
b5efe91
f5f883d
e3af265
3717039
07b2eca
9caab8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ passed | |
"desc": "basic-auth for jack", | ||
"plugins": { | ||
"basic-auth": { | ||
"username": "the-user", | ||
"username": "the-new-user", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After adding the duplicate judgment, it cannot be added here again, so I made a modification. |
||
"password": "the-password" | ||
} | ||
} | ||
|
@@ -119,7 +119,7 @@ passed | |
"value":{ | ||
"desc":"basic-auth for jack", | ||
"id":"credential_a", | ||
"plugins":{"basic-auth":{"username":"the-user","password":"WvF5kpaLvIzjuk4GNIMTJg=="}} | ||
"plugins":{"basic-auth":{"username":"the-new-user","password":"WvF5kpaLvIzjuk4GNIMTJg=="}} | ||
}, | ||
"key":"/apisix/consumers/jack/credentials/credential_a" | ||
}]] | ||
|
@@ -492,3 +492,99 @@ GET /t | |
--- error_code: 400 | ||
--- response_body | ||
{"error_msg":"missing credential id"} | ||
|
||
|
||
|
||
=== TEST 17: create a consumer bar | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/consumers', ngx.HTTP_PUT, [[{ "username": "bar" }]]) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
|
||
|
||
|
||
=== TEST 18: create a credential with key-auth for the consumer bar | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/consumers/bar/credentials/credential_c', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"desc": "key-auth for bar", | ||
"plugins": { | ||
"key-auth": { | ||
"key": "the-key-bar" | ||
} | ||
} | ||
}]] | ||
) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
|
||
|
||
|
||
=== TEST 19: can not create a credential with duplicate key | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/consumers/bar/credentials/credential_d', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"desc": "key-auth for bar", | ||
"plugins": { | ||
"key-auth": { | ||
"key": "the-key-bar" | ||
} | ||
} | ||
}]] | ||
) | ||
|
||
ngx.status = code | ||
ngx.print(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- error_code: 400 | ||
--- response_body | ||
{"error_msg":"duplicate key found with consumer: bar"} | ||
|
||
|
||
|
||
=== TEST 20: can update credential credential_c with same key | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
|
||
-- update desc, keep same key | ||
local code, body = t('/apisix/admin/consumers/bar/credentials/credential_c', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"desc": "new description", | ||
"plugins": { | ||
"key-auth": { | ||
"key": "the-key-bar" | ||
} | ||
} | ||
}]] | ||
) | ||
|
||
ngx.status = code | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
--- error_code: 200 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,3 +314,5 @@ GET /t | |
} | ||
--- response_body | ||
all done | ||
--- error_log | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The testing of these changes is an expected change. These tests have an admin api call to the consumer and use a non-existent secret reference, which in the new logic triggers a secret lookup failure and an error log. It didn't break the original test path. |
||
failed to fetch secret value: no secret conf, secret_uri: $secret://aws/mysecret/jack/key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest putting the
check_deuplicate_key
function inapisix/consumer.lua