-
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
8 changed files
with
273 additions
and
3 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,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wst; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\WSSecurity\XML\wsse\SecurityTokenReference; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\MissingElementException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
|
||
use function array_pop; | ||
|
||
/** | ||
* Class defining the RequestedReferenceType element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractRequestedReferenceType extends AbstractWstElement | ||
{ | ||
/** | ||
* AbstractRequestedReferenceType constructor | ||
* | ||
* @param \SimpleSAML\WSSecurity\XML\wsse\SecurityTokenReference $securityTokenReference | ||
*/ | ||
final public function __construct( | ||
protected SecurityTokenReference $securityTokenReference | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the securityTokenReference property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsse\SecurityTokenReference | ||
*/ | ||
public function getSecurityTokenReference(): SecurityTokenReference | ||
{ | ||
return $this->securityTokenReference; | ||
} | ||
|
||
|
||
/** | ||
* Create an instance of this object from its XML representation. | ||
* | ||
* @param \DOMElement $xml | ||
* @return static | ||
* | ||
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException | ||
* if the qualified name of the supplied element is wrong | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); | ||
|
||
$securityTokenReference = SecurityTokenReference::getChildrenOfClass($xml); | ||
Assert::minCount($securityTokenReference, 1, MissingElementException::class); | ||
Assert::maxCount($securityTokenReference, 1, TooManyElementsException::class); | ||
|
||
return new static(array_pop($securityTokenReference)); | ||
} | ||
|
||
|
||
/** | ||
* Add this RequestedReferenceType to an XML element. | ||
* | ||
* @param \DOMElement $parent The element we should append this element to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = parent::instantiateParentElement($parent); | ||
|
||
$this->getSecurityTokenReference()->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
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\wst; | ||
|
||
/** | ||
* A RequestedAttachedReference element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestedAttachedReference extends AbstractRequestedReferenceType | ||
{ | ||
} |
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\wst; | ||
|
||
/** | ||
* A RequestedUnattachedReference element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestedUnattachedReference extends AbstractRequestedReferenceType | ||
{ | ||
} |
75 changes: 75 additions & 0 deletions
75
tests/WSSecurity/XML/wst/RequestedAttachedReferenceTest.php
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\WSSecurity\XML\wst; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Test\WSSecurity\Constants as C; | ||
use SimpleSAML\WSSecurity\XML\wsse\SecurityTokenReference; | ||
use SimpleSAML\WSSecurity\XML\wst\RequestedAttachedReference; | ||
use SimpleSAML\XML\Attribute as XMLAttribute; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
|
||
/** | ||
* Class \SimpleSAML\WSSecurity\XML\wst\RequestedAttachedReferenceTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\RequestedAttachedReference | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractRequestedReferenceType | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestedAttachedReferenceTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; | ||
|
||
self::$testedClass = RequestedAttachedReference::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/wst_RequestedAttachedReference.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a RequestedAttachedReference object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1'); | ||
$child = DOMDocumentFactory::fromString( | ||
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>', | ||
); | ||
|
||
$securityTokenReference = new SecurityTokenReference( | ||
'SomeID', | ||
'SomeUsage', | ||
[new Chunk($child->documentElement)], | ||
[$attr1], | ||
); | ||
|
||
$requestedAttachedReference = new RequestedAttachedReference($securityTokenReference); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($requestedAttachedReference), | ||
); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
tests/WSSecurity/XML/wst/RequestedUnattachedReferenceTest.php
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\WSSecurity\XML\wst; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Test\WSSecurity\Constants as C; | ||
use SimpleSAML\WSSecurity\XML\wsse\SecurityTokenReference; | ||
use SimpleSAML\WSSecurity\XML\wst\RequestedUnattachedReference; | ||
use SimpleSAML\XML\Attribute as XMLAttribute; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
|
||
/** | ||
* Class \SimpleSAML\WSSecurity\XML\wst\RequestedUnattachedReferenceTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\RequestedUnattachedReference | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractRequestedReferenceType | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class RequestedUnattachedReferenceTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; | ||
|
||
self::$testedClass = RequestedUnattachedReference::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/wst_RequestedUnattachedReference.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a RequestedUnattachedReference object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1'); | ||
$child = DOMDocumentFactory::fromString( | ||
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>', | ||
); | ||
|
||
$securityTokenReference = new SecurityTokenReference( | ||
'SomeID', | ||
'SomeUsage', | ||
[new Chunk($child->documentElement)], | ||
[$attr1], | ||
); | ||
|
||
$requestedUnattachedReference = new RequestedUnattachedReference($securityTokenReference); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($requestedUnattachedReference), | ||
); | ||
} | ||
} |
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,5 @@ | ||
<wst:RequestedAttachedReference xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/"> | ||
<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ssp="urn:x-simplesamlphp:namespace" wsse:Usage="SomeUsage" wsu:Id="SomeID" ssp:attr1="testval1"> | ||
<ssp:Chunk>SomeChunk</ssp:Chunk> | ||
</wsse:SecurityTokenReference> | ||
</wst:RequestedAttachedReference> |
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,5 @@ | ||
<wst:RequestedUnattachedReference xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/"> | ||
<wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ssp="urn:x-simplesamlphp:namespace" wsse:Usage="SomeUsage" wsu:Id="SomeID" ssp:attr1="testval1"> | ||
<ssp:Chunk>SomeChunk</ssp:Chunk> | ||
</wsse:SecurityTokenReference> | ||
</wst:RequestedUnattachedReference> |