-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jwt) add a maximum_expiration config value
Support for limiting the expiration period on JWT tokens. In the JWT plugin you can set the property `maximum_expiration` to a positive integer, indicating the maximum number of seconds the `exp` claim in the token may be ahead in the future. From #3331 Signed-off-by: Thibault Charbonnier <[email protected]>
- Loading branch information
1 parent
1bee9b1
commit 6263443
Showing
7 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local validate_entity = require("kong.dao.schemas_validation").validate_entity | ||
local jwt_schema = require "kong.plugins.jwt.schema" | ||
|
||
|
||
describe("Plugin: jwt (schema)", function() | ||
it("validates 'maximum_expiration'", function() | ||
local ok, err = validate_entity({ | ||
maximum_expiration = 60, | ||
claims_to_verify = { "exp", "nbf" }, | ||
}, jwt_schema) | ||
|
||
assert.is_nil(err) | ||
assert.is_true(ok) | ||
end) | ||
|
||
describe("errors", function() | ||
it("when 'maximum_expiration' is negative", function() | ||
local ok, err = validate_entity({ | ||
maximum_expiration = -1, | ||
claims_to_verify = { "exp", "nbf" }, | ||
}, jwt_schema) | ||
|
||
assert.is_false(ok) | ||
assert.same({ | ||
maximum_expiration = "should be 0 or greater" | ||
}, err) | ||
|
||
local ok, err = validate_entity({ | ||
maximum_expiration = -1, | ||
claims_to_verify = { "nbf" }, | ||
}, jwt_schema) | ||
|
||
assert.is_false(ok) | ||
assert.same({ | ||
maximum_expiration = "should be 0 or greater" | ||
}, err) | ||
end) | ||
|
||
it("when 'maximum_expiration' is specified without 'exp' in 'claims_to_verify'", function() | ||
local ok, err, self_err = validate_entity({ | ||
maximum_expiration = 60, | ||
claims_to_verify = { "nbf" }, | ||
}, jwt_schema) | ||
|
||
assert.is_false(ok) | ||
assert.is_nil(err) | ||
assert.same({ | ||
message = "claims_to_verify must contain 'exp' when specifying maximum_expiration", | ||
schema = true, | ||
}, self_err) | ||
end) | ||
end) | ||
end) |