@@ -212,18 +212,73 @@ def test_callback_phase_with_missing_claims
212212 }
213213 }
214214
215+ stub_id_token = lambda do |id_token |
216+ id_token . stubs ( :abc ) . returns ( "def" )
217+ end
218+
219+ catching_failures do
220+ test_callback_phase ( options : options , userinfo : false , stub_id_token : stub_id_token )
221+ expect_authentication_error (
222+ :claim_validation_error ,
223+ exception_class : OmniAuth ::Strategies ::OpenIDConnect ::Claims ::InvalidClaims ,
224+ message : "Expected acr claim, but it was missing"
225+ )
226+ end
227+ end
228+
229+ def test_callback_phase_with_missing_claim_values
230+ options = {
231+ claims : {
232+ id_token : {
233+ acr : {
234+ essential : true ,
235+ values : [ "phr" , "phrh" ]
236+ }
237+ }
238+ }
239+ }
240+
215241 stub_id_token = lambda do |id_token |
216242 id_token . stubs ( :acr ) . returns ( [ ] )
217243 end
218244
219- ex = assert_raises :: OpenIDConnect :: ResponseObject :: IdToken :: InvalidToken do
245+ catching_failures do
220246 test_callback_phase ( options : options , userinfo : false , stub_id_token : stub_id_token )
247+ expect_authentication_error (
248+ :claim_validation_error ,
249+ exception_class : OmniAuth ::Strategies ::OpenIDConnect ::Claims ::InvalidClaims ,
250+ message : 'Expected one of acr values ["phr", "phrh"], got []'
251+ )
252+ end
253+ end
254+
255+ def test_callback_phase_with_wrong_claim_values
256+ options = {
257+ claims : {
258+ id_token : {
259+ acr : {
260+ essential : true ,
261+ values : [ "phr" , "phrh" ]
262+ }
263+ }
264+ }
265+ }
266+
267+ stub_id_token = lambda do |id_token |
268+ id_token . stubs ( :acr ) . returns ( "abc" )
221269 end
222270
223- assert_equal ex . message , "Expected one of ACR values ['phr', 'phrh'] in []"
271+ catching_failures do
272+ test_callback_phase ( options : options , userinfo : false , stub_id_token : stub_id_token )
273+ expect_authentication_error (
274+ :claim_validation_error ,
275+ exception_class : OmniAuth ::Strategies ::OpenIDConnect ::Claims ::InvalidClaims ,
276+ message : 'Expected one of acr values ["phr", "phrh"], got "abc"'
277+ )
278+ end
224279 end
225280
226- def test_callback_phase_with_returned_claims
281+ def test_callback_phase_with_array_result
227282 options = {
228283 claims : {
229284 id_token : {
@@ -239,7 +294,84 @@ def test_callback_phase_with_returned_claims
239294 id_token . stubs ( :acr ) . returns ( [ "phr" ] )
240295 end
241296
242- test_callback_phase ( options : options , userinfo : true , stub_id_token : stub_id_token )
297+ catching_failures do
298+ # This is a regression test, we used to accept a claim response that was an array with one of the requested
299+ # values, when the specification merely asks to validate that the actual value EQUALS one of the requested values
300+ test_callback_phase ( options : options , userinfo : false , stub_id_token : stub_id_token )
301+ expect_authentication_error (
302+ :claim_validation_error ,
303+ exception_class : OmniAuth ::Strategies ::OpenIDConnect ::Claims ::InvalidClaims ,
304+ message : 'Expected one of acr values ["phr", "phrh"], got ["phr"]'
305+ )
306+ end
307+ end
308+
309+ def test_callback_phase_with_expected_claim_value
310+ options = {
311+ claims : {
312+ id_token : {
313+ acr : {
314+ essential : true ,
315+ values : [ "phr" , "phrh" ]
316+ }
317+ }
318+ }
319+ }
320+
321+ stub_id_token = lambda do |id_token |
322+ id_token . stubs ( :acr ) . returns ( "phr" )
323+ end
324+
325+ catching_failures do
326+ test_callback_phase ( options : options , userinfo : true , stub_id_token : stub_id_token )
327+ expect_no_authentication_error
328+ end
329+ end
330+
331+ def test_callback_phase_with_missing_essential_claims
332+ options = {
333+ claims : {
334+ id_token : {
335+ abc : {
336+ essential : true
337+ }
338+ }
339+ }
340+ }
341+
342+ stub_id_token = lambda do |id_token |
343+ id_token . stubs ( :def ) . returns ( "ghi" )
344+ end
345+
346+ catching_failures do
347+ test_callback_phase ( options : options , userinfo : false , stub_id_token : stub_id_token )
348+ expect_authentication_error (
349+ :claim_validation_error ,
350+ exception_class : OmniAuth ::Strategies ::OpenIDConnect ::Claims ::InvalidClaims ,
351+ message : "Expected abc claim, but it was missing"
352+ )
353+ end
354+ end
355+
356+ def test_callback_phase_with_present_essential_claims
357+ options = {
358+ claims : {
359+ id_token : {
360+ abc : {
361+ essential : true
362+ }
363+ }
364+ }
365+ }
366+
367+ stub_id_token = lambda do |id_token |
368+ id_token . stubs ( :abc ) . returns ( "def" )
369+ end
370+
371+ catching_failures do
372+ test_callback_phase ( options : options , userinfo : true , stub_id_token : stub_id_token )
373+ expect_no_authentication_error
374+ end
243375 end
244376
245377 def test_callback_phase_with_discovery
0 commit comments