|
20 | 20 | use DOMDocument; |
21 | 21 | use EngineBlock_Saml2_IdGenerator; |
22 | 22 | use Exception; |
| 23 | +use InvalidArgumentException; |
23 | 24 | use Mockery as m; |
24 | 25 | use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
25 | 26 | use OpenConext\EngineBlock\Metadata\ContactPerson; |
@@ -295,8 +296,48 @@ public function metadata_add_no_requested_attributes() |
295 | 296 | $this->assertStringNotContainsString($this->getRequestedAttributeXml('attribute3', false), $xml); |
296 | 297 | } |
297 | 298 |
|
298 | | - private function buildMetadataRenderer(string $addRequestedAttributes) |
| 299 | + #[Group('Metadata')] |
| 300 | + #[Test] |
| 301 | + public function a_negative_metadata_expiration_time_throws_an_invalid_argument_exception() |
| 302 | + { |
| 303 | + $this->expectException(InvalidArgumentException::class); |
| 304 | + $this->buildMetadataRenderer('all', -1); |
| 305 | + } |
| 306 | + |
| 307 | + #[Group('Metadata')] |
| 308 | + #[Test] |
| 309 | + public function a_zero_metadata_expiration_time_throws_an_invalid_argument_exception() |
299 | 310 | { |
| 311 | + $this->expectException(InvalidArgumentException::class); |
| 312 | + $this->buildMetadataRenderer('all', 0); |
| 313 | + } |
| 314 | + |
| 315 | + #[Group('Metadata')] |
| 316 | + #[Test] |
| 317 | + public function the_configured_metadata_expiration_time_is_reflected_in_the_valid_until_attribute() |
| 318 | + { |
| 319 | + $fixedTime = mktime(0, 0, 0, 1, 1, 2026); |
| 320 | + $expirationTime = 3600; |
| 321 | + |
| 322 | + $timeProvider = m::mock(TimeProvider::class); |
| 323 | + $timeProvider->shouldReceive('timestamp') |
| 324 | + ->andReturnUsing(function ($deltaSeconds) use ($fixedTime) { |
| 325 | + return gmdate(TimeProvider::TIMESTAMP_FORMAT, $fixedTime + $deltaSeconds); |
| 326 | + }); |
| 327 | + |
| 328 | + $renderer = $this->buildMetadataRenderer('all', $expirationTime, $timeProvider); |
| 329 | + |
| 330 | + $expectedValidUntil = gmdate(TimeProvider::TIMESTAMP_FORMAT, $fixedTime + $expirationTime); |
| 331 | + |
| 332 | + $spXml = $renderer->fromServiceProviderEntity($this->buildSp(), 'default'); |
| 333 | + $this->assertStringContainsString('validUntil="' . $expectedValidUntil . '"', $spXml); |
| 334 | + } |
| 335 | + |
| 336 | + private function buildMetadataRenderer( |
| 337 | + string $addRequestedAttributes, |
| 338 | + int $metadataExpirationTime = 86400, |
| 339 | + ?TimeProvider $timeProvider = null |
| 340 | + ) { |
300 | 341 | $basePath = realpath(__DIR__ . '/../../../../../'); |
301 | 342 |
|
302 | 343 | $privateKey = new X509PrivateKey($basePath . '/tests/resources/key/engineblock.pem'); |
@@ -339,8 +380,9 @@ private function buildMetadataRenderer(string $addRequestedAttributes) |
339 | 380 | $samlIdGenerator, |
340 | 381 | $keyPairFactory, |
341 | 382 | $documentSigner, |
342 | | - new TimeProvider(), |
343 | | - $addRequestedAttributes |
| 383 | + $timeProvider ?? new TimeProvider(), |
| 384 | + $addRequestedAttributes, |
| 385 | + $metadataExpirationTime |
344 | 386 | ); |
345 | 387 | } |
346 | 388 |
|
|
0 commit comments