|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\Module\adfs\IdP; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use SimpleSAML\Configuration; |
| 10 | +use SimpleSAML\Module\adfs\IdP\MetadataBuilder; |
| 11 | +use SimpleSAML\WebServices\Federation\Constants as C_FED; |
| 12 | +use SimpleSAML\WebServices\Federation\XML\fed\AbstractSecurityTokenServiceType; |
| 13 | + |
| 14 | +use function dirname; |
| 15 | +use function strval; |
| 16 | + |
| 17 | +/** |
| 18 | + */ |
| 19 | +#[CoversClass(MetadataBuilder::class)] |
| 20 | +final class MetadataBuilderTest extends TestCase |
| 21 | +{ |
| 22 | + /** @var \SimpleSAML\Configuration */ |
| 23 | + protected Configuration $config; |
| 24 | + |
| 25 | + |
| 26 | + /** |
| 27 | + * The setup method that is run before any tests in this class. |
| 28 | + */ |
| 29 | + protected function setup(): void |
| 30 | + { |
| 31 | + parent::setUp(); |
| 32 | + |
| 33 | + $this->config = Configuration::loadFromArray( |
| 34 | + [ |
| 35 | + 'enable.adfs-idp' => true, |
| 36 | + 'module.enable' => ['adfs' => true], |
| 37 | + 'metadata.sources' => [ |
| 38 | + ['type' => 'flatfile', 'directory' => dirname(__DIR__, 2) . '/metadata'], |
| 39 | + ], |
| 40 | + ], |
| 41 | + '[ARRAY]', |
| 42 | + 'simplesaml', |
| 43 | + ); |
| 44 | + |
| 45 | + Configuration::setPreLoadedConfig($this->config, 'config.php'); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + /** |
| 50 | + * Test that the SecurityTokenService is typed as fed:SecurityTokenServiceType. |
| 51 | + * |
| 52 | + * The first constructor argument is the element's xsi:type, not its own name. Building it from |
| 53 | + * getLocalName()/NS/NS_PREFIX describes the element this serialises to — md:RoleDescriptor — |
| 54 | + * and so publishes a role descriptor that claims to be typed as itself. |
| 55 | + */ |
| 56 | + public function testSecurityTokenServiceCarriesItsXsiType(): void |
| 57 | + { |
| 58 | + $metadata = Configuration::loadFromArray( |
| 59 | + ['entityid' => 'urn:example:adfs'], |
| 60 | + 'adfs-idp-hosted', |
| 61 | + ); |
| 62 | + |
| 63 | + $xsiType = (new MetadataBuilder($this->config, $metadata)) |
| 64 | + ->getSecurityTokenService() |
| 65 | + ->getXsiType(); |
| 66 | + |
| 67 | + $this->assertEquals('fed:SecurityTokenServiceType', strval($xsiType)); |
| 68 | + $this->assertEquals( |
| 69 | + AbstractSecurityTokenServiceType::XSI_TYPE_NAME, |
| 70 | + $xsiType->getLocalName()->getValue(), |
| 71 | + ); |
| 72 | + |
| 73 | + // The prefix is lexical; what identifies the type is the namespace it resolves to. |
| 74 | + $namespaceURI = $xsiType->getNamespaceURI(); |
| 75 | + $this->assertNotNull($namespaceURI); |
| 76 | + $this->assertEquals(C_FED::NS_FED, $namespaceURI->getValue()); |
| 77 | + } |
| 78 | +} |
0 commit comments