@@ -422,33 +422,78 @@ public function testGetSPMetadata()
422422 * Case with x509certNew
423423 *
424424 * @covers OneLogin_Saml2_Settings::getSPMetadata
425+ * @dataProvider testGetSPMetadataWithX509CertNewDataProvider
425426 */
426- public function testGetSPMetadataWithX509CertNew ()
427+ public function testGetSPMetadataWithX509CertNew ($ alwaysIncludeEncryption , $ wantNameIdEncrypted , $ wantAssertionsEncrypted , $ expectEncryptionKeyDescriptor )
427428 {
428429 $ settingsDir = TEST_ROOT .'/settings/ ' ;
429430 include $ settingsDir .'settings5.php ' ;
430431
431- $ settingsInfo ['security ' ]['wantNameIdEncrypted ' ] = false ;
432- $ settingsInfo ['security ' ]['wantAssertionsEncrypted ' ] = false ;
432+ $ settingsInfo ['security ' ]['wantNameIdEncrypted ' ] = $ wantNameIdEncrypted ;
433+ $ settingsInfo ['security ' ]['wantAssertionsEncrypted ' ] = $ wantAssertionsEncrypted ;
433434 $ settings = new OneLogin_Saml2_Settings ($ settingsInfo );
434- $ metadata = $ settings ->getSPMetadata ();
435+ $ metadata = $ settings ->getSPMetadata ($ alwaysIncludeEncryption );
435436
436- $ this ->assertEquals (2 , substr_count ($ metadata , "<md:KeyDescriptor " ));
437+ $ this ->assertEquals ($ expectEncryptionKeyDescriptor ? 4 : 2 , substr_count ($ metadata , "<md:KeyDescriptor " ));
437438
439+ // signing KeyDescriptor should always be included
438440 $ this ->assertEquals (2 , substr_count ($ metadata , '<md:KeyDescriptor use="signing" ' ));
439441
440- $ this ->assertEquals (0 , substr_count ($ metadata , '<md:KeyDescriptor use="encryption" ' ));
441-
442- $ settingsInfo ['security ' ]['wantNameIdEncrypted ' ] = true ;
443- $ settingsInfo ['security ' ]['wantAssertionsEncrypted ' ] = true ;
444- $ settings2 = new OneLogin_Saml2_Settings ($ settingsInfo );
445- $ metadata2 = $ settings2 ->getSPMetadata ();
446-
447- $ this ->assertEquals (4 , substr_count ($ metadata2 , "<md:KeyDescriptor " ));
448-
449- $ this ->assertEquals (2 , substr_count ($ metadata2 , '<md:KeyDescriptor use="signing" ' ));
442+ $ this ->assertEquals ($ expectEncryptionKeyDescriptor ? 2 : 0 , substr_count ($ metadata , '<md:KeyDescriptor use="encryption" ' ));
443+ }
450444
451- $ this ->assertEquals (2 , substr_count ($ metadata2 , '<md:KeyDescriptor use="encryption" ' ));
445+ public function testGetSPMetadataWithX509CertNewDataProvider ()
446+ {
447+ return [
448+ 'settings do not require encryption ' => [
449+ 'alwaysIncludeEncryption ' => false ,
450+ 'wantNameIdEncrypted ' => false ,
451+ 'wantAssertionsEncrypted ' => false ,
452+ 'expectEncryptionKeyDescriptor ' => false ,
453+ ],
454+ 'wantNameIdEncrypted setting enabled ' => [
455+ 'alwaysIncludeEncryption ' => false ,
456+ 'wantNameIdEncrypted ' => true ,
457+ 'wantAssertionsEncrypted ' => false ,
458+ 'expectEncryptionKeyDescriptor ' => true ,
459+ ],
460+ 'wantAssertionsEncrypted setting enabled ' => [
461+ 'alwaysIncludeEncryption ' => false ,
462+ 'wantNameIdEncrypted ' => false ,
463+ 'wantAssertionsEncrypted ' => true ,
464+ 'expectEncryptionKeyDescriptor ' => true ,
465+ ],
466+ 'both settings enabled ' => [
467+ 'alwaysIncludeEncryption ' => false ,
468+ 'wantNameIdEncrypted ' => true ,
469+ 'wantAssertionsEncrypted ' => true ,
470+ 'expectEncryptionKeyDescriptor ' => true ,
471+ ],
472+ 'metadata requested with encryption ' => [
473+ 'alwaysIncludeEncryption ' => true ,
474+ 'wantNameIdEncrypted ' => false ,
475+ 'wantAssertionsEncrypted ' => false ,
476+ 'expectEncryptionKeyDescriptor ' => true ,
477+ ],
478+ 'metadata requested with encryption and wantNameIdEncrypted setting enabled ' => [
479+ 'alwaysIncludeEncryption ' => true ,
480+ 'wantNameIdEncrypted ' => true ,
481+ 'wantAssertionsEncrypted ' => false ,
482+ 'expectEncryptionKeyDescriptor ' => true ,
483+ ],
484+ 'metadata requested with encryption and wantAssertionsEncrypted setting enabled ' => [
485+ 'alwaysIncludeEncryption ' => true ,
486+ 'wantNameIdEncrypted ' => false ,
487+ 'wantAssertionsEncrypted ' => true ,
488+ 'expectEncryptionKeyDescriptor ' => true ,
489+ ],
490+ 'metadata requested with encryption and both settings enabled ' => [
491+ 'alwaysIncludeEncryption ' => true ,
492+ 'wantNameIdEncrypted ' => true ,
493+ 'wantAssertionsEncrypted ' => true ,
494+ 'expectEncryptionKeyDescriptor ' => true ,
495+ ],
496+ ];
452497 }
453498
454499 /**
0 commit comments