@@ -234,16 +234,64 @@ describe("when the id token signature uses a symmetric algorithm", function()
234234end )
235235
236236describe (" when the id claims to be signed by an unsupported algorithm" , function ()
237- test_support .start_server ({
238- fake_id_token_signature = " true"
239- })
240- teardown (test_support .stop_server )
241- local _ , status = test_support .login ()
242- it (" login succeeds" , function ()
243- assert .are .equals (302 , status )
237+ describe (" and accept_unsupported_alg is not set" , function ()
238+ test_support .start_server ({
239+ fake_id_token_signature = " true" ,
240+ oidc_opts = {
241+ discovery = {
242+ id_token_signing_alg_values_supported = { " AB256" }
243+ }
244+ }
245+ })
246+ teardown (test_support .stop_server )
247+ local _ , status = test_support .login ()
248+ it (" login succeeds" , function ()
249+ assert .are .equals (302 , status )
250+ end )
251+ it (" an error is logged" , function ()
252+ assert .error_log_contains (" ignored id_token signature as algorithm 'AB256' is not supported" )
253+ end )
254+ end )
255+ describe (" and accept_unsupported_alg is true" , function ()
256+ test_support .start_server ({
257+ fake_id_token_signature = " true" ,
258+ oidc_opts = {
259+ discovery = {
260+ id_token_signing_alg_values_supported = { " AB256" }
261+ },
262+ accept_unsupported_alg = true
263+ }
264+ })
265+ teardown (test_support .stop_server )
266+ local _ , status = test_support .login ()
267+ it (" login succeeds" , function ()
268+ assert .are .equals (302 , status )
269+ end )
270+ it (" an error is logged" , function ()
271+ assert .error_log_contains (" ignored id_token signature as algorithm 'AB256' is not supported" )
272+ end )
244273 end )
245- it (" an error is logged" , function ()
246- assert .error_log_contains (" ignored id_token signature as algorithm 'AB256' is not supported" )
274+ describe (" and accept_unsupported_alg is false" , function ()
275+ test_support .start_server ({
276+ fake_id_token_signature = " true" ,
277+ oidc_opts = {
278+ discovery = {
279+ id_token_signing_alg_values_supported = { " AB256" }
280+ },
281+ accept_unsupported_alg = false
282+ }
283+ })
284+ teardown (test_support .stop_server )
285+ local _ , status = test_support .login ()
286+ it (" login has failed" , function ()
287+ assert .are .equals (401 , status )
288+ end )
289+ it (" an error message has been logged" , function ()
290+ assert .error_log_contains (" token is signed using algorithm \" AB256\" which is not supported by lua%-resty%-jwt" )
291+ end )
292+ it (" authenticate returns an error" , function ()
293+ assert .error_log_contains (" authenticate failed: token is signed using algorithm \" AB256\" which is not supported by lua%-resty%-jwt" )
294+ end )
247295 end )
248296end )
249297
@@ -264,3 +312,59 @@ describe("when the id token signature is invalid", function()
264312 end )
265313end )
266314
315+ describe (" when the id token signature uses the 'none' alg" , function ()
316+ describe (" and we are not willing to accept the none alg" , function ()
317+ test_support .start_server ({
318+ none_alg_id_token_signature = " true" ,
319+ })
320+ teardown (test_support .stop_server )
321+ local _ , status = test_support .login ()
322+ it (" login has failed" , function ()
323+ assert .are .equals (401 , status )
324+ end )
325+ it (" an error message has been logged" , function ()
326+ assert .error_log_contains (" id_token 'none' signature verification failed" )
327+ end )
328+ it (" authenticate returns an error" , function ()
329+ assert .error_log_contains (" authenticate failed: token uses \" none\" alg but accept_none_alg is not enabled" )
330+ end )
331+ end )
332+ describe (" and we are willing to accept the none alg" , function ()
333+ test_support .start_server ({
334+ none_alg_id_token_signature = " true" ,
335+ oidc_opts = {
336+ accept_none_alg = true ,
337+ }
338+ })
339+ teardown (test_support .stop_server )
340+ local _ , status = test_support .login ()
341+ it (" login succeeds" , function ()
342+ assert .are .equals (302 , status )
343+ end )
344+ it (" an message has been logged" , function ()
345+ assert .error_log_contains (" accept JWT with alg \" none\" and no signature" )
346+ end )
347+ end )
348+ end )
349+
350+ describe (" when the id token is signed by an algorithm not announced by discovery endpoint" , function ()
351+ test_support .start_server ({
352+ oidc_opts = {
353+ discovery = {
354+ id_token_signing_alg_values_supported = { " HS256" }
355+ }
356+ }
357+ })
358+ teardown (test_support .stop_server )
359+ local _ , status = test_support .login ()
360+ it (" login has failed" , function ()
361+ assert .are .equals (401 , status )
362+ end )
363+ it (" an error message has been logged" , function ()
364+ assert .error_log_contains (" token is signed by unexpected algorithm \" RS256\" " )
365+ end )
366+ it (" authenticate returns an error" , function ()
367+ assert .error_log_contains (" authenticate failed: token is signed by unexpected algorithm \" RS256\" " )
368+ end )
369+ end )
370+
0 commit comments