-
Couldn't load subscription status.
- Fork 2.7k
change(jwt-auth): when algorithm is not RS256 or ES256, require the user to fill in secret
#12611
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
Changes from 3 commits
6686762
4f68110
d7de50d
88f22e9
5425a9c
a00b5a6
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 |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ __DATA__ | |
| content_by_lua_block { | ||
| local plugin = require("apisix.plugins.jwt-auth") | ||
| local core = require("apisix.core") | ||
| local conf = {key = "123"} | ||
| local conf = {key = "123", secret = "my-secret-key"} | ||
|
|
||
| local ok, err = plugin.check_schema(conf, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
|
|
@@ -50,7 +50,7 @@ __DATA__ | |
| } | ||
| } | ||
| --- response_body_like eval | ||
| qr/{"algorithm":"HS256","base64_secret":false,"exp":86400,"key":"123","lifetime_grace_period":0,"secret":"[a-zA-Z0-9+\\\/]+={0,2}"}/ | ||
| qr/{"algorithm":"HS256","base64_secret":false,"exp":86400,"key":"123","lifetime_grace_period":0,"secret":"my-secret-key"}/ | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -835,7 +835,7 @@ passed | |
| content_by_lua_block { | ||
| local plugin = require("apisix.plugins.jwt-auth") | ||
| local core = require("apisix.core") | ||
| local conf = {key = "123", algorithm = "HS512"} | ||
| local conf = {key = "123", algorithm = "HS512", secret = "my-secret-key"} | ||
|
|
||
| local ok, err = plugin.check_schema(conf, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
|
|
@@ -846,7 +846,7 @@ passed | |
| } | ||
| } | ||
| --- response_body_like eval | ||
| qr/{"algorithm":"HS512","base64_secret":false,"exp":86400,"key":"123","lifetime_grace_period":0,"secret":"[a-zA-Z0-9+\\\/]+={0,2}"}/ | ||
| qr/{"algorithm":"HS512","base64_secret":false,"exp":86400,"key":"123","lifetime_grace_period":0,"secret":"my-secret-key"}/ | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -1222,3 +1222,71 @@ hello world | |
| --- error_code: 400 | ||
| --- response_body | ||
| {"error_msg":"invalid plugins configuration: failed to check the configuration of plugin jwt-auth err: failed to validate dependent schema for \"algorithm\": value should match only one schema, but matches none"} | ||
|
|
||
|
|
||
|
|
||
| === TEST 52: secret is required when algorithm is not RS256 or ES256 | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local core = require("apisix.core") | ||
| local plugin = require("apisix.plugins.jwt-auth") | ||
| -- default algorithm is HS256 | ||
| local ok, err = plugin.check_schema({ | ||
| key = "123", | ||
| }, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
| ngx.say(err) | ||
| else | ||
| ngx.say("done") | ||
| end | ||
|
||
|
|
||
| ok, err = plugin.check_schema({ | ||
| key = "123", | ||
| algorithm = "HS256", | ||
| }, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
| ngx.say(err) | ||
| else | ||
| ngx.say("done") | ||
| end | ||
|
|
||
| ok, err = plugin.check_schema({ | ||
| key = "123", | ||
| algorithm = "HS512", | ||
| }, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
| ngx.say(err) | ||
| else | ||
| ngx.say("done") | ||
| end | ||
|
|
||
| ok, err = plugin.check_schema({ | ||
| key = "123", | ||
| algorithm = "RS256", | ||
| public_key = "-----BEGIN PUBLIC KEY-----\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKebDxlvQMGyEesAL1r1nIJBkSdqu3Hr\n7noq/0ukiZqVQLSJPMOv0oxQSutvvK3hoibwGakDOza+xRITB7cs2cECAwEAAQ==\n-----END PUBLIC KEY-----" | ||
| }, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
| ngx.say(err) | ||
| else | ||
| ngx.say("done") | ||
| end | ||
|
|
||
| ok, err = plugin.check_schema({ | ||
| key = "123", | ||
| algorithm = "ES256", | ||
| public_key = "-----BEGIN PUBLIC KEY-----\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKebDxlvQMGyEesAL1r1nIJBkSdqu3Hr\n7noq/0ukiZqVQLSJPMOv0oxQSutvvK3hoibwGakDOza+xRITB7cs2cECAwEAAQ==\n-----END PUBLIC KEY-----" | ||
| }, core.schema.TYPE_CONSUMER) | ||
| if not ok then | ||
| ngx.say(err) | ||
| else | ||
| ngx.say("done") | ||
| end | ||
| } | ||
| } | ||
| --- response_body | ||
| property "secret" is required when "algorithm" is "HS256" or "HS512" | ||
| property "secret" is required when "algorithm" is "HS256" or "HS512" | ||
| property "secret" is required when "algorithm" is "HS256" or "HS512" | ||
| done | ||
| done | ||
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.
Adjust to be consistent with the document
https://github.com/apache/apisix/pull/12611/files#diff-3cd5fc846614f1e59961d065c6f32dca0b2d6cc3ef549e7a961dd4b3694a74bc