Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for IDP Discovery endpoints
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<schema | ||
targetNamespace="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" | ||
xmlns:idpdisc="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" | ||
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" | ||
xmlns="http://www.w3.org/2001/XMLSchema" | ||
elementFormDefault="unqualified" | ||
attributeFormDefault="unqualified" | ||
blockDefault="substitution" | ||
version="2.0"> | ||
<annotation> | ||
<documentation> | ||
Document identifier: sstc-saml-idp-discovery | ||
Location: http://www.oasis-open.org/committees/documents.php?wg_abbrev=security | ||
Revision history: | ||
V1.0 (January 2007): | ||
Initial version. | ||
</documentation> | ||
</annotation> | ||
<import namespace="urn:oasis:names:tc:SAML:2.0:metadata" | ||
schemaLocation="saml-schema-metadata-2.0.xsd"/> | ||
<element name="DiscoveryResponse" type="md:IndexedEndpointType"/> | ||
</schema> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2\XML\idpdisc; | ||
|
||
use SimpleSAML\SAML2\Constants as C; | ||
use SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType; | ||
|
||
/** | ||
* Abstract class to be implemented by all the classes in this namespace | ||
* | ||
* @package simplesamlphp/saml2 | ||
* | ||
* @see http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-idp-discovery.html | ||
*/ | ||
final class DiscoveryResponse extends AbstractIndexedEndpointType | ||
{ | ||
/** @var string */ | ||
public const NS = C::NS_IDPDISC; | ||
|
||
/** @var string */ | ||
public const NS_PREFIX = 'idpdisc'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\SAML2\XML\idpdisc; | ||
|
||
use DOMDocument; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Assert\AssertionFailedException; | ||
use SimpleSAML\SAML2\XML\idpdisc\DiscoveryResponse; | ||
use SimpleSAML\Test\SAML2\Constants as C; | ||
use SimpleSAML\Test\XML\SchemaValidationTestTrait; | ||
use SimpleSAML\Test\XML\SerializableElementTestTrait; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingAttributeException; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SAML2\XML\idpdisc\DiscoveryResponseTest | ||
* | ||
* @covers \SimpleSAML\SAML2\XML\idpdisc\DiscoveryResponse | ||
* @covers \SimpleSAML\SAML2\XML\md\AbstractIndexedEndpointType | ||
* @covers \SimpleSAML\SAML2\XML\md\AbstractMdElement | ||
* @package simplesamlphp/saml2 | ||
*/ | ||
final class DiscoveryEndpointTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->schema = dirname(__FILE__, 5) . '/schemas/sstc-saml-idp-discovery.xsd'; | ||
|
||
$this->testedClass = DiscoveryResponse::class; | ||
|
||
$this->xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/idpdisc_DiscoveryResponse.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a DiscoveryResponse from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$discoResponse = new DiscoveryResponse(43, C::BINDING_HTTP_POST, C::LOCATION_A, false); | ||
|
||
$this->assertEquals( | ||
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement), | ||
strval($discoResponse), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Test that creating a DiscoveryResponse from scratch without specifying isDefault works. | ||
*/ | ||
public function testMarshallingWithoutIsDefault(): void | ||
{ | ||
$discoResponse = new DiscoveryResponse(43, C::BINDING_HTTP_POST, C::LOCATION_A); | ||
$this->xmlRepresentation->documentElement->removeAttribute('isDefault'); | ||
$this->assertEquals( | ||
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement), | ||
strval($discoResponse), | ||
); | ||
$this->assertNull($discoResponse->getIsDefault()); | ||
} | ||
|
||
|
||
// test unmarshalling | ||
|
||
|
||
/** | ||
* Test creating a DiscoveryResponse from XML. | ||
*/ | ||
public function testUnmarshalling(): void | ||
{ | ||
$discoResponse = DiscoveryResponse::fromXML($this->xmlRepresentation->documentElement); | ||
|
||
$this->assertEquals( | ||
$this->xmlRepresentation->saveXML($this->xmlRepresentation->documentElement), | ||
strval($discoResponse), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<idpdisc:DiscoveryResponse xmlns:idpdisc="urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol" Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://simplesamlphp.org/some/endpoint" index="43" isDefault="false" /> |