Skip to content

Commit

Permalink
Update jwt-auth4.t
Browse files Browse the repository at this point in the history
+ Removed external httpbin upstream in favor of local endpoint (/hello);
+ Cleaned code;
  • Loading branch information
mikyll committed Jun 4, 2024
1 parent 2af7e15 commit 92bd025
Showing 1 changed file with 42 additions and 31 deletions.
73 changes: 42 additions & 31 deletions t/plugin/jwt-auth4.t
Original file line number Diff line number Diff line change
Expand Up @@ -123,58 +123,70 @@ safe-jws
=== TEST 2: verify that key_claim_name can be used to validate the Consumer JWT with a different
claim than 'key'
=== TEST 2: enable jwt auth plugin (with custom key_claim_name) using admin api
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local t = require("lib.test_admin").test
-- prepare consumer
local csm_code, csm_body = t('/apisix/admin/consumers',
local code, body = t('/apisix/admin/routes/4',
ngx.HTTP_PUT,
[[{
"username": "mike",
"plugins": {
"jwt-auth": {
"key": "custom-user-key",
"secret": "custom-secret-key"
"secret": "custom-secret-key",
"key_claim_name": "iss"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
)
if csm_code >= 300 then
ngx.status = csm_code
ngx.say(csm_body)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
-- prepare route
local rot_code, rot_body = t('/apisix/admin/routes/3',
ngx.say(body)
}
}
--- response_body
passed
=== TEST 3: verify that key_claim_name can be used to validate the Consumer JWT
with a different claim than 'key'
--- 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,
[[{
"uri": "/anything/*",
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
},
"username": "mike",
"plugins": {
"jwt-auth": {
"key": "custom-user-key",
"secret": "custom-secret-key",
"key_claim_name": "iss"
"secret": "custom-secret-key"
}
}
}]]
)
if rot_code >= 300 then
ngx.status = rot_code
ngx.say("FAILED: Test /verify route creation - Body:" .. rot_body)
if csm_code >= 300 then
ngx.status = csm_code
ngx.say(csm_body)
return
end
Expand All @@ -185,19 +197,18 @@ claim than 'key'
if sign_code > 200 then
ngx.status = sign_code
ngx.say("FAILED: Test sign - Token: " .. token .. "\nBody: " .. sign_body)
ngx.say(sign_body)
return
end
-- verify JWT using the custom key_claim_name
ngx.req.set_header("Authorization", "Bearer " .. token)
local ver_code, ver_body, ver_extra = t('/anything/get?jwt=' .. token,
local ver_code, ver_body = t('/hello?jwt=' .. token,
ngx.HTTP_GET
)
if ver_code > 200 then
ngx.status = ver_code
ngx.say("FAILED: Test verify - Token: " .. token .. "\nBody: " .. ver_body .. "\nExtra: " .. ver_extra)
ngx.say(ver_body)
return
end
Expand Down

0 comments on commit 92bd025

Please sign in to comment.