@@ -404,33 +404,74 @@ public function testGetSPMetadata()
404404 * Case with x509certNew
405405 *
406406 * @covers OneLogin\Saml2\Settings::getSPMetadata
407+ * @dataProvider getSPMetadataWithX509CertNewDataProvider
407408 */
408- public function testGetSPMetadataWithX509CertNew ()
409+ public function testGetSPMetadataWithX509CertNew ($ alwaysIncludeEncryption , $ wantNameIdEncrypted , $ wantAssertionsEncrypted , $ expectEncryptionKeyDescriptor )
409410 {
410411 $ settingsDir = TEST_ROOT .'/settings/ ' ;
411412 include $ settingsDir .'settings5.php ' ;
412-
413- $ settingsInfo ['security ' ]['wantNameIdEncrypted ' ] = false ;
414- $ settingsInfo ['security ' ]['wantAssertionsEncrypted ' ] = false ;
413+ $ settingsInfo ['security ' ]['wantNameIdEncrypted ' ] = $ wantNameIdEncrypted ;
414+ $ settingsInfo ['security ' ]['wantAssertionsEncrypted ' ] = $ wantAssertionsEncrypted ;
415415 $ settings = new Settings ($ settingsInfo );
416- $ metadata = $ settings ->getSPMetadata ();
417-
418- $ this ->assertEquals (2 , substr_count ($ metadata , "<md:KeyDescriptor " ));
419-
416+ $ metadata = $ settings ->getSPMetadata ($ alwaysIncludeEncryption );
417+ $ this ->assertEquals ($ expectEncryptionKeyDescriptor ? 4 : 2 , substr_count ($ metadata , "<md:KeyDescriptor " ));
418+ // signing KeyDescriptor should always be included
420419 $ this ->assertEquals (2 , substr_count ($ metadata , '<md:KeyDescriptor use="signing" ' ));
421-
422- $ this ->assertEquals (0 , substr_count ($ metadata , '<md:KeyDescriptor use="encryption" ' ));
423-
424- $ settingsInfo ['security ' ]['wantNameIdEncrypted ' ] = true ;
425- $ settingsInfo ['security ' ]['wantAssertionsEncrypted ' ] = true ;
426- $ settings2 = new Settings ($ settingsInfo );
427- $ metadata2 = $ settings2 ->getSPMetadata ();
428-
429- $ this ->assertEquals (4 , substr_count ($ metadata2 , "<md:KeyDescriptor " ));
430-
431- $ this ->assertEquals (2 , substr_count ($ metadata2 , '<md:KeyDescriptor use="signing" ' ));
432-
433- $ this ->assertEquals (2 , substr_count ($ metadata2 , '<md:KeyDescriptor use="encryption" ' ));
420+ $ this ->assertEquals ($ expectEncryptionKeyDescriptor ? 2 : 0 , substr_count ($ metadata , '<md:KeyDescriptor use="encryption" ' ));
421+ }
422+
423+ public function getSPMetadataWithX509CertNewDataProvider ()
424+ {
425+ return [
426+ 'settings do not require encryption ' => [
427+ 'alwaysIncludeEncryption ' => false ,
428+ 'wantNameIdEncrypted ' => false ,
429+ 'wantAssertionsEncrypted ' => false ,
430+ 'expectEncryptionKeyDescriptor ' => false ,
431+ ],
432+ 'wantNameIdEncrypted setting enabled ' => [
433+ 'alwaysIncludeEncryption ' => false ,
434+ 'wantNameIdEncrypted ' => true ,
435+ 'wantAssertionsEncrypted ' => false ,
436+ 'expectEncryptionKeyDescriptor ' => true ,
437+ ],
438+ 'wantAssertionsEncrypted setting enabled ' => [
439+ 'alwaysIncludeEncryption ' => false ,
440+ 'wantNameIdEncrypted ' => false ,
441+ 'wantAssertionsEncrypted ' => true ,
442+ 'expectEncryptionKeyDescriptor ' => true ,
443+ ],
444+ 'both settings enabled ' => [
445+ 'alwaysIncludeEncryption ' => false ,
446+ 'wantNameIdEncrypted ' => true ,
447+ 'wantAssertionsEncrypted ' => true ,
448+ 'expectEncryptionKeyDescriptor ' => true ,
449+ ],
450+ 'metadata requested with encryption ' => [
451+ 'alwaysIncludeEncryption ' => true ,
452+ 'wantNameIdEncrypted ' => false ,
453+ 'wantAssertionsEncrypted ' => false ,
454+ 'expectEncryptionKeyDescriptor ' => true ,
455+ ],
456+ 'metadata requested with encryption and wantNameIdEncrypted setting enabled ' => [
457+ 'alwaysIncludeEncryption ' => true ,
458+ 'wantNameIdEncrypted ' => true ,
459+ 'wantAssertionsEncrypted ' => false ,
460+ 'expectEncryptionKeyDescriptor ' => true ,
461+ ],
462+ 'metadata requested with encryption and wantAssertionsEncrypted setting enabled ' => [
463+ 'alwaysIncludeEncryption ' => true ,
464+ 'wantNameIdEncrypted ' => false ,
465+ 'wantAssertionsEncrypted ' => true ,
466+ 'expectEncryptionKeyDescriptor ' => true ,
467+ ],
468+ 'metadata requested with encryption and both settings enabled ' => [
469+ 'alwaysIncludeEncryption ' => true ,
470+ 'wantNameIdEncrypted ' => true ,
471+ 'wantAssertionsEncrypted ' => true ,
472+ 'expectEncryptionKeyDescriptor ' => true ,
473+ ],
474+ ];
434475 }
435476
436477 /**
0 commit comments