-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 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,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\fed; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\StringElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
/** | ||
* An AbstractAttributeExtensibleURIType element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractAttributeExtensibleURIType extends AbstractFedElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
use StringElementTrait; | ||
|
||
/** The namespace-attribute for the xs:anyAttribute element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* @param string $content | ||
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes | ||
*/ | ||
public function __construct(string $content, array $namespacedAttributes) | ||
{ | ||
$this->setContent($content); | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Validate the content of the element. | ||
* | ||
* @param string $content The value to go in the XML textContent | ||
* @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure | ||
* @return void | ||
*/ | ||
protected function validateContent(string $content): void | ||
{ | ||
Assert::validURI($content, SchemaViolationException::class); | ||
} | ||
|
||
|
||
/** | ||
* Create a class from XML | ||
* | ||
* @param \DOMElement $xml | ||
* @return static | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); | ||
|
||
return new static( | ||
$xml->textContent, | ||
self::getAttributesNSFromXML($xml), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Create XML from this class | ||
* | ||
* @param \DOMElement|null $parent | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
$e->textContent = $this->getContent(); | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\fed; | ||
|
||
/** | ||
* A FederationID element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class FederationID extends AbstractAttributeExtensibleURIType | ||
{ | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\WSSecurity\XML\sp; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Test\WSSecurity\Constants as C; | ||
use SimpleSAML\WSSecurity\XML\fed\FederationID; | ||
use SimpleSAML\XML\Attribute as XMLAttribute; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
|
||
/** | ||
* Class \SimpleSAML\WSSecurity\XML\fed\FederationIDTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\fed\FederationID | ||
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractAttributeExtensibleURIType | ||
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class FederationIDTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-federation.xsd'; | ||
|
||
self::$testedClass = FederationID::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/fed_FederationID.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a FederationID object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$attr1 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1'); | ||
$federationID = new FederationID(C::NAMESPACE, [$attr1]); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($federationID), | ||
); | ||
} | ||
} |
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 @@ | ||
<fed:FederationID xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706" xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">urn:x-simplesamlphp:namespace</fed:FederationID> |