Skip to content

Commit 3adb517

Browse files
committed
Support and parameters at getSPMetadata method
1 parent 278c51c commit 3adb517

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/Saml2/Settings.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,16 @@ public function shouldCompressResponses()
793793
* the 'encryption' KeyDescriptor will only be included if
794794
* $advancedSettings['security']['wantNameIdEncrypted'] or
795795
* $advancedSettings['security']['wantAssertionsEncrypted'] are enabled.
796+
* @param int|null $validUntil Metadata's valid time
797+
* @param int|null $cacheDuration Duration of the cache in seconds
796798
*
797799
* @return string SP metadata (xml)
798800
* @throws Exception
799801
* @throws Error
800802
*/
801-
public function getSPMetadata($alwaysPublishEncryptionCert = false)
803+
public function getSPMetadata($alwaysPublishEncryptionCert = false, $validUntil = null, $cacheDuration = null)
802804
{
803-
$metadata = Metadata::builder($this->_sp, $this->_security['authnRequestsSigned'], $this->_security['wantAssertionsSigned'], null, null, $this->getContacts(), $this->getOrganization());
805+
$metadata = Metadata::builder($this->_sp, $this->_security['authnRequestsSigned'], $this->_security['wantAssertionsSigned'], $validUntil, $cacheDuration, $this->getContacts(), $this->getOrganization());
804806

805807
$certNew = $this->getSPcertNew();
806808
if (!empty($certNew)) {

tests/src/OneLogin/Saml2/SettingsTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OneLogin\Saml2\Tests;
44

55
use OneLogin\Saml2\Error;
6+
use OneLogin\Saml2\Metadata;
67
use OneLogin\Saml2\Settings;
78
use OneLogin\Saml2\Utils;
89

@@ -474,6 +475,35 @@ public function getSPMetadataWithX509CertNewDataProvider()
474475
];
475476
}
476477

478+
/**
479+
* Tests the getSPMetadata method of the OneLogin_Saml2_Settings
480+
* Case ValidUntil CacheDuration
481+
*
482+
* @covers OneLogin\Saml2\Settings::getSPMetadata
483+
*/
484+
public function testGetSPMetadataTiming()
485+
{
486+
$settingsDir = TEST_ROOT .'/settings/';
487+
include $settingsDir.'settings1.php';
488+
489+
$settings = new Settings($settingsInfo);
490+
491+
$currentValidUntil = time() + Metadata::TIME_VALID;
492+
$currentValidUntilStr = gmdate('Y-m-d\TH:i:s\Z', $currentValidUntil);
493+
$defaultCacheDuration = Metadata::TIME_CACHED;
494+
495+
$metadata = $settings->getSPMetadata();
496+
$this->assertContains('validUntil="'.$currentValidUntilStr.'"', $metadata);
497+
$this->assertContains('cacheDuration="PT604800S"', $metadata);
498+
499+
$newValidUntil = 2524668343;
500+
$newValidUntilStr = gmdate('Y-m-d\TH:i:s\Z', $newValidUntil);
501+
$newCacheDuration = 1209600;
502+
$metadata2 = $settings->getSPMetadata(false, $newValidUntil, $newCacheDuration);
503+
$this->assertContains('validUntil="'.$newValidUntilStr.'"', $metadata2);
504+
$this->assertContains('cacheDuration="PT1209600S"', $metadata2);
505+
}
506+
477507
/**
478508
* Tests the getSPMetadata method of the Settings
479509
* Case signed metadata

0 commit comments

Comments
 (0)