Skip to content

Commit f1e5b76

Browse files
committed
add a test function that handles a JWT with a non-existing kid
Signed-off-by: Hans Zandbelt <hans.zandbelt@zmartzone.eu>
1 parent dac8b33 commit f1e5b76

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/spec/bearer_token_verification_spec.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,33 @@ describe("when the JWK specifies a kid and the JWKS contains multiple keys", fun
163163
base_checks()
164164
end)
165165

166+
describe("when the JWK specifies a kid and the JWKS does not contain a key with that kid", function()
167+
test_support.start_server({
168+
verify_opts = {
169+
discovery = {
170+
jwks_uri = "http://127.0.0.1/jwk",
171+
}
172+
},
173+
jwk = test_support.load("/spec/jwks_with_two_keys.json"),
174+
token_header = {
175+
kid = "dcab",
176+
}
177+
})
178+
teardown(test_support.stop_server)
179+
local jwt = test_support.trim(http.request("http://127.0.0.1/jwt"))
180+
local _, status = http.request({
181+
url = "http://127.0.0.1/verify_bearer_token",
182+
headers = { authorization = "Bearer " .. jwt }
183+
})
184+
it("the token is invalid", function()
185+
assert.are.equals(401, status)
186+
end)
187+
it("an error is logged", function()
188+
assert.error_log_contains("RSA key with id dcab not found")
189+
end)
190+
191+
end)
192+
166193
describe("when the JWK specifies no kid and the JWKS contains multiple keys", function()
167194
test_support.start_server({
168195
verify_opts = {

0 commit comments

Comments
 (0)