Skip to content

Commit

Permalink
add prepare phase to create consumer & route
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspertian committed Mar 6, 2024
1 parent 76946f0 commit 0d4300c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions t/plugin/jwt-auth4.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,44 @@ __DATA__
local core = require("apisix.core")
local t = require("lib.test_admin").test
-- prepare consumer
local csm_code, csm_body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
[[{
"username": "jack",
"plugins": {
"jwt-auth": {
"key": "user-key",
"secret": "my-secret-key"
}
}
}]]
)
if csm_code >= 300 then
ngx.status = csm_code
ngx.say(csm_body)
return
end
-- prepare sign api
local rot_code, rot_body = t('/apisix/admin/routes/2',
ngx.HTTP_PUT,
[[{
"plugins": {
"public-api": {}
},
"uri": "/apisix/plugin/jwt/sign"
}]]
)
if rot_code >= 300 then
ngx.status = rot_code
ngx.say(rot_body)
return
end
-- generate jws
local code, err, sign = t('/apisix/plugin/jwt/sign?key=user-key&payload={"key":"letmein","exp":1234567890}',
ngx.HTTP_GET
)
Expand All @@ -61,13 +99,15 @@ __DATA__
return
end
-- get payload section from jws
local payload = string.match(sign,"^.+%.(.+)%..+$")
if not payload then
ngx.say("sign-failed")
return
end
-- check payload value
local res = core.json.decode(ngx.decode_base64(payload))
if res.key == 'user-key' and res.exp ~= 1234567890 then
Expand Down

0 comments on commit 0d4300c

Please sign in to comment.