Skip to content
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
10 changes: 8 additions & 2 deletions apisix/plugins/jwt-auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ local consumer_schema = {
type = "object",
-- can't use additionalProperties with dependencies
properties = {
key = {type = "string"},
secret = {type = "string"},
key = {
type = "string",
minLength = 1,
},
secret = {
type = "string",
minLength = 1,
},
algorithm = {
type = "string",
enum = {"HS256", "HS512", "RS256", "ES256"},
Expand Down
70 changes: 70 additions & 0 deletions t/plugin/jwt-auth4.t
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,73 @@ GET /t
--- more_headers
--- response_body
hello world



=== TEST 4: ensure secret is non empty
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin").test
-- prepare consumer with a custom key claim name
local csm_code, csm_body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "mike",
"plugins": {
"jwt-auth": {
"key": "custom-user-key",
"secret": ""
}
}
}]]
)
if csm_code == 200 then
ngx.status = 500
ngx.say("error")
return
end
ngx.status = csm_code
ngx.say(csm_body)
}
}
--- error_code: 400
--- response_body eval
qr/\\"secret\\" validation failed: string too short, expected at least 1, got 0/



=== TEST 5: ensure key is non empty
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin").test
-- prepare consumer with a custom key claim name
local csm_code, csm_body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "mike",
"plugins": {
"jwt-auth": {
"key": "",
"algorithm": "RS256",
"public_key": "somekey",
"private_key": "someprivkey"
}
}
}]]
)
if csm_code == 200 then
ngx.status = 500
ngx.say("error")
return
end
ngx.status = csm_code
ngx.say(csm_body)
}
}
--- error_code: 400
--- response_body eval
qr/\\"key\\" validation failed: string too short, expected at least 1, got 0/