-
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
7 changed files
with
196 additions
and
62 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,111 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wst; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Base64ElementTrait; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
use function array_map; | ||
use function explode; | ||
use function implode; | ||
|
||
/** | ||
* A BinarySecertType element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractBinarySecretType extends AbstractWstElement | ||
{ | ||
use Base64ElementTrait; | ||
use ExtendableAttributesTrait; | ||
|
||
/** @var string|\SimpleSAML\XML\XsNamespace */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* @param string $content | ||
* @param (\SimpleSAML\WSSecurity\XML\wst\BinarySecretTypeEnum|string)[]|null $Type | ||
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes | ||
*/ | ||
final public function __construct( | ||
string $content, | ||
protected ?array $Type = null, | ||
array $namespacedAttributes = [] | ||
) { | ||
if ($Type !== null) { | ||
$Type = array_map( | ||
function (BinarySecretTypeEnum|string $v): string { | ||
return ($v instanceof BinarySecretTypeEnum) ? $v->value : $v; | ||
}, | ||
$Type, | ||
); | ||
Assert::allValidURI($Type, SchemaViolationException::class); | ||
$this->Type = $Type; | ||
} | ||
|
||
$this->setContent($content); | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Get the Type property. | ||
* | ||
* @return (\SimpleSAML\WSSecurity\XML\wst\BinarySecretTypeEnum|string)[] | ||
Check failure on line 62 in src/XML/wst/AbstractBinarySecretType.php GitHub Actions / Quality controlInvalidNullableReturnType
|
||
*/ | ||
public function getType(): array | ||
{ | ||
return $this->Type; | ||
Check failure on line 66 in src/XML/wst/AbstractBinarySecretType.php GitHub Actions / Quality controlNullableReturnStatement
|
||
} | ||
|
||
|
||
/** | ||
* Convert XML into a class instance | ||
* | ||
* @param \DOMElement $xml The XML element we should load | ||
* @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); | ||
|
||
return new static( | ||
$xml->textContent, | ||
explode(' ', self::getAttribute($xml, 'Type')), | ||
self::getAttributesNSFromXML($xml), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Convert this element to XML. | ||
* | ||
* @param \DOMElement|null $parent The element we should append this element to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = $this->instantiateParentElement($parent); | ||
$e->textContent = $this->getContent(); | ||
|
||
$e->setAttribute('Type', implode(' ', $this->getType())); | ||
Check failure on line 103 in src/XML/wst/AbstractBinarySecretType.php GitHub Actions / Quality controlInvalidArgument
|
||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 BinarySecret element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class BinarySecret extends AbstractBinarySecretType | ||
{ | ||
} |
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,68 @@ | ||
<?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\wst\BinarySecret; | ||
use SimpleSAML\WSSecurity\XML\wst\BinarySecretTypeEnum; | ||
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\wst\BinarySecretTest | ||
* | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\BinarySecret | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractBinarySecretType | ||
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class BinarySecretTest extends TestCase | ||
{ | ||
use SchemaValidationTestTrait; | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; | ||
|
||
self::$testedClass = BinarySecret::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 4) . '/resources/xml/wst_BinarySecret.xml', | ||
); | ||
} | ||
|
||
|
||
// test marshalling | ||
|
||
|
||
/** | ||
* Test creating a BinarySecret object from scratch. | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$attr1 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1'); | ||
|
||
$binarySecret = new BinarySecret( | ||
'/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=', | ||
[BinarySecretTypeEnum::Nonce], | ||
[$attr1], | ||
); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($binarySecret), | ||
); | ||
} | ||
} |
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
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 @@ | ||
<wst:BinarySecret xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/" xmlns:ssp="urn:x-simplesamlphp:namespace" Type="http://docs.oasis-open.org/ws-sx/ws-trust/200512/Nonce" ssp:attr1="testval1">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</wst:BinarySecret> |