Skip to content

Commit

Permalink
Add wst classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 27, 2024
1 parent 48c192c commit 110a6ae
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 0 deletions.
99 changes: 99 additions & 0 deletions src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\wst;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\XsNamespace as NS;

/**
* A RequestSecurityTokenResponseCollectionType element
*
* @package tvdijen/ws-security
*/
abstract class AbstractRequestSecurityTokenResponseCollectionType extends AbstractWstElement
{
use ExtendableAttributesTrait;

/** @var string|\SimpleSAML\XML\XsNamespace */
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;


/**
* @param \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponse[] $requestSecurityTokenResponse
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
*/
final public function __construct(
protected array $requestSecurityTokenResponse,
array $namespacedAttributes
) {
Assert::minCount($requestSecurityTokenResponse, 1, MissingElementException::class);
Assert::allIsInstanceOf(
$requestSecurityTokenResponse,
RequestSecurityTokenResponse::class,
SchemaViolationException::class,
);

$this->setAttributesNS($namespacedAttributes);
}


/**
* Get the requestSecurityTokenResponse property.
*
* @return \SimpleSAML\WSSecurity\XMLwst\RequestSecurityTokenResponse[]

Check failure on line 50 in src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php

View workflow job for this annotation

GitHub Actions / Quality control

UndefinedDocblockClass

src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php:50:16: UndefinedDocblockClass: Docblock-defined class, interface or enum named SimpleSAML\WSSecurity\XMLwst\RequestSecurityTokenResponse does not exist (see https://psalm.dev/200)
*/
public function getRequestSecurityTokenResponse(): array
{
return $this->requestSecurityTokenResponse;
}


/**
* 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(
RequestSecurityTokenResponse::getChildrenOfClass($xml),
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);

foreach ($this->getRequestSecurityTokenResponse() as $r) {
$r->toXML($e);

Check failure on line 90 in src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php

View workflow job for this annotation

GitHub Actions / Quality control

UndefinedDocblockClass

src/XML/wst/AbstractRequestSecurityTokenResponseCollectionType.php:90:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named SimpleSAML\WSSecurity\XMLwst\RequestSecurityTokenResponse does not exist (see https://psalm.dev/200)
}

foreach ($this->getAttributesNS() as $attr) {
$attr->toXML($e);
}

return $e;
}
}
14 changes: 14 additions & 0 deletions src/XML/wst/RequestSecurityTokenResponseCollection.php
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 RequestSecurityTokenResponseCollection element
*
* @package tvdijen/ws-security
*/
final class RequestSecurityTokenResponseCollection extends AbstractRequestSecurityTokenResponseCollectionType
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\wst;

use PHPUnit\Framework\TestCase;
use SimpleSAML\SOAP\Constants as SOAP;
use SimpleSAML\Test\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\XML\wsa\MessageID;
use SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponse;
use SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponseCollection;
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\RequestSecurityTokenResponseCollectionTest
*
* @covers \SimpleSAML\WSSecurity\XML\wst\RequestSecurityTokenResponseCollection
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractRequestSecurityTokenResponseCollectionType
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractWstElement
*
* @package tvdijen/ws-security
*/
final class RequestSecurityTokenResponseCollectionTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd';

self::$testedClass = RequestSecurityTokenResponseCollection::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/wst_RequestSecurityTokenResponseCollection.xml',
);
}


// test marshalling


/**
* Test creating a RequestSecurityTokenResponseCollection object from scratch.
*/
public function testMarshalling(): void
{
$attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1');
$attr2 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1');
$attr3 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr2', 'testval2');
$msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]);

$requestSecurityTokenResponse = new RequestSecurityTokenResponse(C::NAMESPACE, [$msgId], [$attr2]);

$requestSecurityTokenResponseCollection = new RequestSecurityTokenResponseCollection(
[$requestSecurityTokenResponse],
[$attr3],
);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($requestSecurityTokenResponseCollection),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wst:RequestSecurityTokenResponseCollection xmlns:wst="http://docs.oasis-open.org/ws-sx/ws-trust/200512/" xmlns:ssp="urn:x-simplesamlphp:namespace" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ssp:attr2="testval2">
<wst:RequestSecurityTokenResponse Context="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">
<wsa:MessageID soapenv:mustUnderstand="1">uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de</wsa:MessageID>
</wst:RequestSecurityTokenResponse>
</wst:RequestSecurityTokenResponseCollection>

0 comments on commit 110a6ae

Please sign in to comment.