From 4d548dd7642838d057d20ad9f874c45803200e34 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 24 Jan 2024 18:30:30 +0100 Subject: [PATCH] Add wst classes --- resources/schemas/ws-trust.xsd | 2 +- src/XML/wst/AbstractBinaryExchangeType.php | 114 ++++++++++++++++++ src/XML/wst/AbstractCancelTargetType.php | 96 +++++++++++++++ src/XML/wst/AbstractComputedKeyOpenEnum.php | 30 +++++ src/XML/wst/AbstractKeyTypeOpenEnum.php | 30 +++++ src/XML/wst/AbstractRenewTargetType.php | 96 +++++++++++++++ src/XML/wst/AbstractRenewingType.php | 107 ++++++++++++++++ src/XML/wst/AbstractStatusCodeOpenEnum.php | 30 +++++ src/XML/wst/AbstractStatusType.php | 99 +++++++++++++++ src/XML/wst/AbstractUseKeyType.php | 42 +++---- src/XML/wst/AbstractValidateTargetType.php | 96 +++++++++++++++ src/XML/wst/BinaryExchange.php | 14 +++ src/XML/wst/CancelTarget.php | 14 +++ src/XML/wst/Code.php | 14 +++ src/XML/wst/ComputedKey.php | 14 +++ src/XML/wst/KeyType.php | 14 +++ src/XML/wst/KeyTypeEnum.php | 2 +- src/XML/wst/Reason.php | 26 ++++ src/XML/wst/RenewTarget.php | 14 +++ src/XML/wst/Renewing.php | 14 +++ src/XML/wst/Status.php | 14 +++ src/XML/wst/ValidateTarget.php | 14 +++ .../WSSecurity/XML/wst/AuthenticatorTest.php | 20 +-- .../WSSecurity/XML/wst/BinaryExchangeTest.php | 62 ++++++++++ tests/WSSecurity/XML/wst/CancelTargetTest.php | 65 ++++++++++ tests/WSSecurity/XML/wst/CodeTest.php | 56 +++++++++ tests/WSSecurity/XML/wst/ComputedKeyTest.php | 60 +++++++++ tests/WSSecurity/XML/wst/DelegateToTest.php | 20 +-- tests/WSSecurity/XML/wst/EncryptionTest.php | 20 +-- .../XML/wst/KeyExchangeTokenTest.php | 20 +-- tests/WSSecurity/XML/wst/KeyTypeTest.php | 60 +++++++++ tests/WSSecurity/XML/wst/OnBehalfOfTest.php | 20 +-- tests/WSSecurity/XML/wst/ParticipantTest.php | 16 ++- tests/WSSecurity/XML/wst/ParticipantsTest.php | 33 ++--- tests/WSSecurity/XML/wst/PrimaryTest.php | 16 ++- .../XML/wst/ProofEncryptionTest.php | 20 +-- tests/WSSecurity/XML/wst/ReasonTest.php | 55 +++++++++ tests/WSSecurity/XML/wst/RenewTargetTest.php | 65 ++++++++++ tests/WSSecurity/XML/wst/RenewingTest.php | 70 +++++++++++ .../XML/wst/RequestedProofTokenTest.php | 20 +-- .../XML/wst/SignChallengeResponseTest.php | 23 ++-- .../WSSecurity/XML/wst/SignChallengeTest.php | 22 ++-- tests/WSSecurity/XML/wst/StatusTest.php | 64 ++++++++++ tests/WSSecurity/XML/wst/UseKeyTest.php | 22 ++-- .../WSSecurity/XML/wst/ValidateTargetTest.php | 65 ++++++++++ tests/resources/xml/wst_Authenticator.xml | 2 +- tests/resources/xml/wst_BinaryExchange.xml | 1 + tests/resources/xml/wst_CancelTarget.xml | 3 + tests/resources/xml/wst_Code.xml | 1 + tests/resources/xml/wst_ComputedKey.xml | 1 + tests/resources/xml/wst_DelegateTo.xml | 2 +- tests/resources/xml/wst_Encryption.xml | 2 +- tests/resources/xml/wst_KeyExchangeToken.xml | 2 +- tests/resources/xml/wst_KeyType.xml | 1 + tests/resources/xml/wst_OnBehalfOf.xml | 2 +- tests/resources/xml/wst_Participant.xml | 2 +- tests/resources/xml/wst_Participants.xml | 6 +- tests/resources/xml/wst_Primary.xml | 2 +- tests/resources/xml/wst_ProofEncryption.xml | 2 +- tests/resources/xml/wst_Reason.xml | 1 + tests/resources/xml/wst_RenewTarget.xml | 3 + tests/resources/xml/wst_Renewing.xml | 1 + .../resources/xml/wst_RequestedProofToken.xml | 2 +- tests/resources/xml/wst_SignChallenge.xml | 4 +- .../xml/wst_SignChallengeResponse.xml | 4 +- tests/resources/xml/wst_Status.xml | 4 + tests/resources/xml/wst_UseKey.xml | 2 +- tests/resources/xml/wst_ValidateTarget.xml | 3 + 68 files changed, 1667 insertions(+), 176 deletions(-) create mode 100644 src/XML/wst/AbstractBinaryExchangeType.php create mode 100644 src/XML/wst/AbstractCancelTargetType.php create mode 100644 src/XML/wst/AbstractComputedKeyOpenEnum.php create mode 100644 src/XML/wst/AbstractKeyTypeOpenEnum.php create mode 100644 src/XML/wst/AbstractRenewTargetType.php create mode 100644 src/XML/wst/AbstractRenewingType.php create mode 100644 src/XML/wst/AbstractStatusCodeOpenEnum.php create mode 100644 src/XML/wst/AbstractStatusType.php create mode 100644 src/XML/wst/AbstractValidateTargetType.php create mode 100644 src/XML/wst/BinaryExchange.php create mode 100644 src/XML/wst/CancelTarget.php create mode 100644 src/XML/wst/Code.php create mode 100644 src/XML/wst/ComputedKey.php create mode 100644 src/XML/wst/KeyType.php create mode 100644 src/XML/wst/Reason.php create mode 100644 src/XML/wst/RenewTarget.php create mode 100644 src/XML/wst/Renewing.php create mode 100644 src/XML/wst/Status.php create mode 100644 src/XML/wst/ValidateTarget.php create mode 100644 tests/WSSecurity/XML/wst/BinaryExchangeTest.php create mode 100644 tests/WSSecurity/XML/wst/CancelTargetTest.php create mode 100644 tests/WSSecurity/XML/wst/CodeTest.php create mode 100644 tests/WSSecurity/XML/wst/ComputedKeyTest.php create mode 100644 tests/WSSecurity/XML/wst/KeyTypeTest.php create mode 100644 tests/WSSecurity/XML/wst/ReasonTest.php create mode 100644 tests/WSSecurity/XML/wst/RenewTargetTest.php create mode 100644 tests/WSSecurity/XML/wst/RenewingTest.php create mode 100644 tests/WSSecurity/XML/wst/StatusTest.php create mode 100644 tests/WSSecurity/XML/wst/ValidateTargetTest.php create mode 100644 tests/resources/xml/wst_BinaryExchange.xml create mode 100644 tests/resources/xml/wst_CancelTarget.xml create mode 100644 tests/resources/xml/wst_Code.xml create mode 100644 tests/resources/xml/wst_ComputedKey.xml create mode 100644 tests/resources/xml/wst_KeyType.xml create mode 100644 tests/resources/xml/wst_Reason.xml create mode 100644 tests/resources/xml/wst_RenewTarget.xml create mode 100644 tests/resources/xml/wst_Renewing.xml create mode 100644 tests/resources/xml/wst_Status.xml create mode 100644 tests/resources/xml/wst_ValidateTarget.xml diff --git a/resources/schemas/ws-trust.xsd b/resources/schemas/ws-trust.xsd index 57793443..a91f053e 100644 --- a/resources/schemas/ws-trust.xsd +++ b/resources/schemas/ws-trust.xsd @@ -373,7 +373,7 @@ elementFormDefault='qualified' > - + diff --git a/src/XML/wst/AbstractBinaryExchangeType.php b/src/XML/wst/AbstractBinaryExchangeType.php new file mode 100644 index 00000000..0c16de65 --- /dev/null +++ b/src/XML/wst/AbstractBinaryExchangeType.php @@ -0,0 +1,114 @@ +setContent($content); + $this->setAttributesNS($namespacedAttributes); + } + + + /** + * Get the valueType property. + * + * @return string + */ + public function getValueType(): string + { + return $this->valueType; + } + + + /** + * Get the valueType property. + * + * @return string + */ + public function getEncodingType(): string + { + return $this->encodingType; + } + + + /** + * 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, + self::getAttribute($xml, 'ValueType'), + self::getAttribute($xml, 'EncodingType'), + 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('ValueType', $this->getValueType()); + $e->setAttribute('EncodingType', $this->getEncodingType()); + + foreach ($this->getAttributesNS() as $attr) { + $attr->toXML($e); + } + + return $e; + } +} diff --git a/src/XML/wst/AbstractCancelTargetType.php b/src/XML/wst/AbstractCancelTargetType.php new file mode 100644 index 00000000..034b84d2 --- /dev/null +++ b/src/XML/wst/AbstractCancelTargetType.php @@ -0,0 +1,96 @@ +setElements([$child]); + } + + + /** + * 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); + + $children = []; + foreach ($xml->childNodes as $child) { + if (!($child instanceof DOMElement)) { + continue; + } elseif ($child->namespaceURI === static::NS) { + continue; + } + + $children[] = new Chunk($child); + } + + Assert::minCount($children, 1, MissingElementException::class); + Assert::maxCount($children, 1, TooManyElementsException::class); + + return new static( + array_pop($children), + ); + } + + + /** + * Add this CancelTargetType to an XML element. + * + * @param \DOMElement $parent The element we should append this username token to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = parent::instantiateParentElement($parent); + + foreach ($this->getElements() as $child) { + if (!$child->isEmptyElement()) { + $child->toXML($e); + } + } + + return $e; + } +} diff --git a/src/XML/wst/AbstractComputedKeyOpenEnum.php b/src/XML/wst/AbstractComputedKeyOpenEnum.php new file mode 100644 index 00000000..f8e39403 --- /dev/null +++ b/src/XML/wst/AbstractComputedKeyOpenEnum.php @@ -0,0 +1,30 @@ +value; + } + + $this->setContent($content); + } +} diff --git a/src/XML/wst/AbstractKeyTypeOpenEnum.php b/src/XML/wst/AbstractKeyTypeOpenEnum.php new file mode 100644 index 00000000..d4f60d8e --- /dev/null +++ b/src/XML/wst/AbstractKeyTypeOpenEnum.php @@ -0,0 +1,30 @@ +value; + } + + $this->setContent($content); + } +} diff --git a/src/XML/wst/AbstractRenewTargetType.php b/src/XML/wst/AbstractRenewTargetType.php new file mode 100644 index 00000000..6164aba4 --- /dev/null +++ b/src/XML/wst/AbstractRenewTargetType.php @@ -0,0 +1,96 @@ +setElements([$child]); + } + + + /** + * 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); + + $children = []; + foreach ($xml->childNodes as $child) { + if (!($child instanceof DOMElement)) { + continue; + } elseif ($child->namespaceURI === static::NS) { + continue; + } + + $children[] = new Chunk($child); + } + + Assert::minCount($children, 1, MissingElementException::class); + Assert::maxCount($children, 1, TooManyElementsException::class); + + return new static( + array_pop($children), + ); + } + + + /** + * Add this RenewTargetType to an XML element. + * + * @param \DOMElement $parent The element we should append this username token to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = parent::instantiateParentElement($parent); + + foreach ($this->getElements() as $child) { + if (!$child->isEmptyElement()) { + $child->toXML($e); + } + } + + return $e; + } +} diff --git a/src/XML/wst/AbstractRenewingType.php b/src/XML/wst/AbstractRenewingType.php new file mode 100644 index 00000000..6063f4e6 --- /dev/null +++ b/src/XML/wst/AbstractRenewingType.php @@ -0,0 +1,107 @@ +allow; + } + + + /** + * @return bool|null + */ + public function getOk(): ?bool + { + return $this->ok; + } + + + /** + * Test if an object, at the state it's in, would produce an empty XML-element + * + * @return bool + */ + public function isEmptyElement(): bool + { + return empty($this->getAllow()) + && empty($this->getOk()); + } + + + /** + * 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); + + return new static( + self::getOptionalBooleanAttribute($xml, 'Allow', null), + self::getOptionalBooleanAttribute($xml, 'OK', null), + ); + } + + + /** + * Add this UseKeyType to an XML element. + * + * @param \DOMElement $parent The element we should append this username token to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = parent::instantiateParentElement($parent); + + if ($this->getAllow() !== null) { + $e->setAttribute('Allow', $this->getAllow() ? 'true' : 'false'); + } + + if ($this->getOk() !== null) { + $e->setAttribute('OK', $this->getOk() ? 'true' : 'false'); + } + + return $e; + } +} diff --git a/src/XML/wst/AbstractStatusCodeOpenEnum.php b/src/XML/wst/AbstractStatusCodeOpenEnum.php new file mode 100644 index 00000000..2bc6c536 --- /dev/null +++ b/src/XML/wst/AbstractStatusCodeOpenEnum.php @@ -0,0 +1,30 @@ +value; + } + + $this->setContent($content); + } +} diff --git a/src/XML/wst/AbstractStatusType.php b/src/XML/wst/AbstractStatusType.php new file mode 100644 index 00000000..add0dc0e --- /dev/null +++ b/src/XML/wst/AbstractStatusType.php @@ -0,0 +1,99 @@ +code; + } + + + /** + * @return \SimpleSAML\WSSecurity\XML\wst\Reason|null + */ + public function getReason(): ?Reason + { + return $this->reason; + } + + + /** + * 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); + + $code = Code::getChildrenOfClass($xml); + Assert::minCount($code, 1, MissingElementException::class); + Assert::maxCount($code, 1, TooManyElementsException::class); + + $reason = Reason::getChildrenOfClass($xml); + Assert::maxCount($reason, 1, TooManyElementsException::class); + + + return new static( + array_pop($code), + array_pop($reason), + ); + } + + + /** + * Add this UseKeyType to an XML element. + * + * @param \DOMElement $parent The element we should append this username token to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = parent::instantiateParentElement($parent); + + $this->getCode()->toXML($e); + $this->getReason()?->toXML($e); + + return $e; + } +} diff --git a/src/XML/wst/AbstractUseKeyType.php b/src/XML/wst/AbstractUseKeyType.php index a0a7482a..784d05dc 100644 --- a/src/XML/wst/AbstractUseKeyType.php +++ b/src/XML/wst/AbstractUseKeyType.php @@ -45,6 +45,27 @@ final public function __construct( } + /** + * @return string|null + */ + public function getSig(): ?string + { + return $this->Sig; + } + + + /** + * Test if an object, at the state it's in, would produce an empty XML-element + * + * @return bool + */ + public function isEmptyElement(): bool + { + return empty($this->getSig()) + && empty($this->getElements()); + } + + /** * Create an instance of this object from its XML representation. * @@ -77,27 +98,6 @@ public static function fromXML(DOMElement $xml): static } - /** - * @return string|null - */ - public function getSig(): ?string - { - return $this->Sig; - } - - - /** - * Test if an object, at the state it's in, would produce an empty XML-element - * - * @return bool - */ - public function isEmptyElement(): bool - { - return empty($this->getSig()) - && empty($this->getElements()); - } - - /** * Add this UseKeyType to an XML element. * diff --git a/src/XML/wst/AbstractValidateTargetType.php b/src/XML/wst/AbstractValidateTargetType.php new file mode 100644 index 00000000..7f6ae115 --- /dev/null +++ b/src/XML/wst/AbstractValidateTargetType.php @@ -0,0 +1,96 @@ +setElements([$child]); + } + + + /** + * 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); + + $children = []; + foreach ($xml->childNodes as $child) { + if (!($child instanceof DOMElement)) { + continue; + } elseif ($child->namespaceURI === static::NS) { + continue; + } + + $children[] = new Chunk($child); + } + + Assert::minCount($children, 1, MissingElementException::class); + Assert::maxCount($children, 1, TooManyElementsException::class); + + return new static( + array_pop($children), + ); + } + + + /** + * Add this ValidateTargetType to an XML element. + * + * @param \DOMElement $parent The element we should append this username token to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = parent::instantiateParentElement($parent); + + foreach ($this->getElements() as $child) { + if (!$child->isEmptyElement()) { + $child->toXML($e); + } + } + + return $e; + } +} diff --git a/src/XML/wst/BinaryExchange.php b/src/XML/wst/BinaryExchange.php new file mode 100644 index 00000000..c7af8330 --- /dev/null +++ b/src/XML/wst/BinaryExchange.php @@ -0,0 +1,14 @@ +setContent($content); + } +} diff --git a/src/XML/wst/RenewTarget.php b/src/XML/wst/RenewTarget.php new file mode 100644 index 00000000..fd8f81cd --- /dev/null +++ b/src/XML/wst/RenewTarget.php @@ -0,0 +1,14 @@ +Some' - )->documentElement); } @@ -54,8 +53,11 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + $combinedHash = new CombinedHash('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $authenticator = new Authenticator($combinedHash, [self::$chunk]); + $authenticator = new Authenticator($combinedHash, [$msgId]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/BinaryExchangeTest.php b/tests/WSSecurity/XML/wst/BinaryExchangeTest.php new file mode 100644 index 00000000..728006aa --- /dev/null +++ b/tests/WSSecurity/XML/wst/BinaryExchangeTest.php @@ -0,0 +1,62 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($binaryExchange), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/CancelTargetTest.php b/tests/WSSecurity/XML/wst/CancelTargetTest.php new file mode 100644 index 00000000..5766db12 --- /dev/null +++ b/tests/WSSecurity/XML/wst/CancelTargetTest.php @@ -0,0 +1,65 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($cancelTarget), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/CodeTest.php b/tests/WSSecurity/XML/wst/CodeTest.php new file mode 100644 index 00000000..8b966577 --- /dev/null +++ b/tests/WSSecurity/XML/wst/CodeTest.php @@ -0,0 +1,56 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($code), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/ComputedKeyTest.php b/tests/WSSecurity/XML/wst/ComputedKeyTest.php new file mode 100644 index 00000000..4cd7a4ee --- /dev/null +++ b/tests/WSSecurity/XML/wst/ComputedKeyTest.php @@ -0,0 +1,60 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($computedKey), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/DelegateToTest.php b/tests/WSSecurity/XML/wst/DelegateToTest.php index e6e2315e..7cbf76f3 100644 --- a/tests/WSSecurity/XML/wst/DelegateToTest.php +++ b/tests/WSSecurity/XML/wst/DelegateToTest.php @@ -5,9 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\DelegateTo; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use function dirname; @@ -23,25 +26,21 @@ */ final class DelegateToTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = DelegateTo::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_DelegateTo.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +52,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $delegateTo = new DelegateTo(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $delegateTo = new DelegateTo($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/EncryptionTest.php b/tests/WSSecurity/XML/wst/EncryptionTest.php index 01809d8a..4a603479 100644 --- a/tests/WSSecurity/XML/wst/EncryptionTest.php +++ b/tests/WSSecurity/XML/wst/EncryptionTest.php @@ -5,9 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\Encryption; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use function dirname; @@ -23,25 +26,21 @@ */ final class EncryptionTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = Encryption::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_Encryption.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +52,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $encryption = new Encryption(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $encryption = new Encryption($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/KeyExchangeTokenTest.php b/tests/WSSecurity/XML/wst/KeyExchangeTokenTest.php index ae6cd98a..4539d4e5 100644 --- a/tests/WSSecurity/XML/wst/KeyExchangeTokenTest.php +++ b/tests/WSSecurity/XML/wst/KeyExchangeTokenTest.php @@ -5,9 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\KeyExchangeToken; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use function dirname; @@ -23,25 +26,21 @@ */ final class KeyExchangeTokenTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = KeyExchangeToken::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_KeyExchangeToken.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +52,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $keyExchangeToken = new KeyExchangeToken([self::$chunk]); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $keyExchangeToken = new KeyExchangeToken([$msgId]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/KeyTypeTest.php b/tests/WSSecurity/XML/wst/KeyTypeTest.php new file mode 100644 index 00000000..d69c4bd4 --- /dev/null +++ b/tests/WSSecurity/XML/wst/KeyTypeTest.php @@ -0,0 +1,60 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($keyType), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/OnBehalfOfTest.php b/tests/WSSecurity/XML/wst/OnBehalfOfTest.php index 25bdcc01..8a0f3ea0 100644 --- a/tests/WSSecurity/XML/wst/OnBehalfOfTest.php +++ b/tests/WSSecurity/XML/wst/OnBehalfOfTest.php @@ -5,9 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\OnBehalfOf; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use function dirname; @@ -23,25 +26,21 @@ */ final class OnBehalfOfTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = OnBehalfOf::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_OnBehalfOf.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +52,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $onBehalfOf = new OnBehalfOf(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $onBehalfOf = new OnBehalfOf($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/ParticipantTest.php b/tests/WSSecurity/XML/wst/ParticipantTest.php index 6be695bb..53794f91 100644 --- a/tests/WSSecurity/XML/wst/ParticipantTest.php +++ b/tests/WSSecurity/XML/wst/ParticipantTest.php @@ -5,8 +5,10 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\Participant; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; @@ -25,9 +27,6 @@ final class ParticipantTest extends TestCase { use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ @@ -38,10 +37,6 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_Participant.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +48,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $participant = new Participant(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $participant = new Participant($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/ParticipantsTest.php b/tests/WSSecurity/XML/wst/ParticipantsTest.php index 34067b88..544ff04d 100644 --- a/tests/WSSecurity/XML/wst/ParticipantsTest.php +++ b/tests/WSSecurity/XML/wst/ParticipantsTest.php @@ -5,10 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\Participant; use SimpleSAML\WSSecurity\XML\wst\Participants; use SimpleSAML\WSSecurity\XML\wst\Primary; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; @@ -29,15 +31,6 @@ final class ParticipantsTest extends TestCase use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - - /** @var \SimpleSAML\XML\Chunk $primary */ - protected static Chunk $primary; - - /** @var \SimpleSAML\XML\Chunk $participant */ - protected static Chunk $participant; - /** */ @@ -50,18 +43,6 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_Participants.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); - - self::$primary = new Chunk(DOMDocumentFactory::fromString( - 'Primary' - )->documentElement); - - self::$participant = new Chunk(DOMDocumentFactory::fromString( - 'Participant' - )->documentElement); } @@ -73,10 +54,12 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $primary = new Primary(self::$primary); - $participant = new Participant(self::$participant); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); - $participants = new Participants($primary, [$participant], [self::$chunk]); + $primary = new Primary($msgId); + $participant = new Participant($msgId); + $participants = new Participants($primary, [$participant], [$msgId]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/PrimaryTest.php b/tests/WSSecurity/XML/wst/PrimaryTest.php index c59d3930..2cd30daf 100644 --- a/tests/WSSecurity/XML/wst/PrimaryTest.php +++ b/tests/WSSecurity/XML/wst/PrimaryTest.php @@ -5,8 +5,10 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\Primary; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; @@ -25,9 +27,6 @@ final class PrimaryTest extends TestCase { use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ @@ -38,10 +37,6 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_Primary.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +48,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $primary = new Primary(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $primary = new Primary($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/ProofEncryptionTest.php b/tests/WSSecurity/XML/wst/ProofEncryptionTest.php index 2f501bc0..d3605eb7 100644 --- a/tests/WSSecurity/XML/wst/ProofEncryptionTest.php +++ b/tests/WSSecurity/XML/wst/ProofEncryptionTest.php @@ -5,9 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\ProofEncryption; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use function dirname; @@ -23,25 +26,21 @@ */ final class ProofEncryptionTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = ProofEncryption::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_ProofEncryption.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +52,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $proofEncryption = new ProofEncryption(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $proofEncryption = new ProofEncryption($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/ReasonTest.php b/tests/WSSecurity/XML/wst/ReasonTest.php new file mode 100644 index 00000000..72d1a2c4 --- /dev/null +++ b/tests/WSSecurity/XML/wst/ReasonTest.php @@ -0,0 +1,55 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($reason), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/RenewTargetTest.php b/tests/WSSecurity/XML/wst/RenewTargetTest.php new file mode 100644 index 00000000..df2bfe6d --- /dev/null +++ b/tests/WSSecurity/XML/wst/RenewTargetTest.php @@ -0,0 +1,65 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($renewTarget), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/RenewingTest.php b/tests/WSSecurity/XML/wst/RenewingTest.php new file mode 100644 index 00000000..f22eb52f --- /dev/null +++ b/tests/WSSecurity/XML/wst/RenewingTest.php @@ -0,0 +1,70 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($renewing), + ); + } + + + /** + * Test creating an empty Renewing object from scratch. + */ + public function testMarshallingEmpty(): void + { + $renewing = new Renewing(); + + $this->assertTrue($renewing->isEmptyElement()); + } +} diff --git a/tests/WSSecurity/XML/wst/RequestedProofTokenTest.php b/tests/WSSecurity/XML/wst/RequestedProofTokenTest.php index b9df84ef..3f0a67dc 100644 --- a/tests/WSSecurity/XML/wst/RequestedProofTokenTest.php +++ b/tests/WSSecurity/XML/wst/RequestedProofTokenTest.php @@ -5,9 +5,12 @@ namespace SimpleSAML\Test\WSSecurity\XML\wst; use PHPUnit\Framework\TestCase; +use SimpleSAML\SOAP\Constants as SOAP; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; use SimpleSAML\WSSecurity\XML\wst\RequestedProofToken; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use function dirname; @@ -23,25 +26,21 @@ */ final class RequestedProofTokenTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = RequestedProofToken::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_RequestedProofToken.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -53,7 +52,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $requestedProofToken = new RequestedProofToken(self::$chunk); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $requestedProofToken = new RequestedProofToken($msgId); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/SignChallengeResponseTest.php b/tests/WSSecurity/XML/wst/SignChallengeResponseTest.php index db3eca1f..61e50585 100644 --- a/tests/WSSecurity/XML/wst/SignChallengeResponseTest.php +++ b/tests/WSSecurity/XML/wst/SignChallengeResponseTest.php @@ -5,11 +5,14 @@ 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\SignChallengeResponse; use SimpleSAML\WSSecurity\XML\wst\Challenge; 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; @@ -25,25 +28,21 @@ */ final class SignChallengeResponseTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = SignChallengeResponse::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_SignChallengeResponse.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -55,9 +54,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + $challenge = new Challenge('accepted'); - $attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1'); - $signChallengeResponse = new SignChallengeResponse($challenge, [self::$chunk], [$attr1]); + $attr2 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1'); + + $signChallengeResponse = new SignChallengeResponse($challenge, [$msgId], [$attr2]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/SignChallengeTest.php b/tests/WSSecurity/XML/wst/SignChallengeTest.php index caccf919..cf5f60ac 100644 --- a/tests/WSSecurity/XML/wst/SignChallengeTest.php +++ b/tests/WSSecurity/XML/wst/SignChallengeTest.php @@ -5,11 +5,14 @@ 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\SignChallenge; use SimpleSAML\WSSecurity\XML\wst\Challenge; 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; @@ -25,25 +28,21 @@ */ final class SignChallengeTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = SignChallenge::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_SignChallenge.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -55,9 +54,12 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + $challenge = new Challenge('accepted'); - $attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1'); - $signChallenge = new SignChallenge($challenge, [self::$chunk], [$attr1]); + $attr2 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1'); + $signChallenge = new SignChallenge($challenge, [$msgId], [$attr2]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/StatusTest.php b/tests/WSSecurity/XML/wst/StatusTest.php new file mode 100644 index 00000000..68f3f4d6 --- /dev/null +++ b/tests/WSSecurity/XML/wst/StatusTest.php @@ -0,0 +1,64 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($status), + ); + } +} diff --git a/tests/WSSecurity/XML/wst/UseKeyTest.php b/tests/WSSecurity/XML/wst/UseKeyTest.php index c74e390e..14e271d4 100644 --- a/tests/WSSecurity/XML/wst/UseKeyTest.php +++ b/tests/WSSecurity/XML/wst/UseKeyTest.php @@ -5,11 +5,14 @@ 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\XML\Chunk; +use SimpleSAML\WSSecurity\XML\wsa\MessageID; +use SimpleSAML\WSSecurity\XML\wst\UseKey; +use SimpleSAML\XML\Attribute as XMLAttribute; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\WSSecurity\XML\wst\UseKey; use function dirname; @@ -24,25 +27,21 @@ */ final class UseKeyTest extends TestCase { + use SchemaValidationTestTrait; use SerializableElementTestTrait; - /** @var \SimpleSAML\XML\Chunk $chunk */ - protected static Chunk $chunk; - /** */ public static function setUpBeforeClass(): void { + self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-trust.xsd'; + self::$testedClass = UseKey::class; self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 4) . '/resources/xml/wst_UseKey.xml', ); - - self::$chunk = new Chunk(DOMDocumentFactory::fromString( - 'Some' - )->documentElement); } @@ -54,7 +53,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $useKey = new UseKey(self::$chunk, C::NAMESPACE); + $attr1 = new XMLAttribute(SOAP::NS_SOAP_ENV_11, 'soapenv', 'mustUnderstand', '1'); + $msgId = new MessageID('uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de', [$attr1]); + + $useKey = new UseKey($msgId, C::NAMESPACE); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/WSSecurity/XML/wst/ValidateTargetTest.php b/tests/WSSecurity/XML/wst/ValidateTargetTest.php new file mode 100644 index 00000000..b2aa886c --- /dev/null +++ b/tests/WSSecurity/XML/wst/ValidateTargetTest.php @@ -0,0 +1,65 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($validateTarget), + ); + } +} diff --git a/tests/resources/xml/wst_Authenticator.xml b/tests/resources/xml/wst_Authenticator.xml index fd8ed15f..b97a0703 100644 --- a/tests/resources/xml/wst_Authenticator.xml +++ b/tests/resources/xml/wst_Authenticator.xml @@ -1,4 +1,4 @@ /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_BinaryExchange.xml b/tests/resources/xml/wst_BinaryExchange.xml new file mode 100644 index 00000000..b731f043 --- /dev/null +++ b/tests/resources/xml/wst_BinaryExchange.xml @@ -0,0 +1 @@ +phpunit diff --git a/tests/resources/xml/wst_CancelTarget.xml b/tests/resources/xml/wst_CancelTarget.xml new file mode 100644 index 00000000..4a39ab2a --- /dev/null +++ b/tests/resources/xml/wst_CancelTarget.xml @@ -0,0 +1,3 @@ + + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de + diff --git a/tests/resources/xml/wst_Code.xml b/tests/resources/xml/wst_Code.xml new file mode 100644 index 00000000..a1a3a15d --- /dev/null +++ b/tests/resources/xml/wst_Code.xml @@ -0,0 +1 @@ +http://docs.oasis-open.org/ws-sx/ws-trust/200512/status/invalid diff --git a/tests/resources/xml/wst_ComputedKey.xml b/tests/resources/xml/wst_ComputedKey.xml new file mode 100644 index 00000000..8e7049fa --- /dev/null +++ b/tests/resources/xml/wst_ComputedKey.xml @@ -0,0 +1 @@ +http://docs.oasis-open.org/ws-sx/ws-trust/200512/CK/PSHA1 diff --git a/tests/resources/xml/wst_DelegateTo.xml b/tests/resources/xml/wst_DelegateTo.xml index 32cce7b2..a22fc5ff 100644 --- a/tests/resources/xml/wst_DelegateTo.xml +++ b/tests/resources/xml/wst_DelegateTo.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_Encryption.xml b/tests/resources/xml/wst_Encryption.xml index d08de665..5385c750 100644 --- a/tests/resources/xml/wst_Encryption.xml +++ b/tests/resources/xml/wst_Encryption.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_KeyExchangeToken.xml b/tests/resources/xml/wst_KeyExchangeToken.xml index e4708d5b..13dc48e5 100644 --- a/tests/resources/xml/wst_KeyExchangeToken.xml +++ b/tests/resources/xml/wst_KeyExchangeToken.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_KeyType.xml b/tests/resources/xml/wst_KeyType.xml new file mode 100644 index 00000000..822b0a6f --- /dev/null +++ b/tests/resources/xml/wst_KeyType.xml @@ -0,0 +1 @@ +http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey diff --git a/tests/resources/xml/wst_OnBehalfOf.xml b/tests/resources/xml/wst_OnBehalfOf.xml index 3398ccd8..80ed9fe5 100644 --- a/tests/resources/xml/wst_OnBehalfOf.xml +++ b/tests/resources/xml/wst_OnBehalfOf.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_Participant.xml b/tests/resources/xml/wst_Participant.xml index 0ace408a..ca83497f 100644 --- a/tests/resources/xml/wst_Participant.xml +++ b/tests/resources/xml/wst_Participant.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_Participants.xml b/tests/resources/xml/wst_Participants.xml index 06402379..43ba480f 100644 --- a/tests/resources/xml/wst_Participants.xml +++ b/tests/resources/xml/wst_Participants.xml @@ -1,9 +1,9 @@ - Primary + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de - Participant + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_Primary.xml b/tests/resources/xml/wst_Primary.xml index 623b5d0f..633484c7 100644 --- a/tests/resources/xml/wst_Primary.xml +++ b/tests/resources/xml/wst_Primary.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_ProofEncryption.xml b/tests/resources/xml/wst_ProofEncryption.xml index f2b1fdca..6421a5dc 100644 --- a/tests/resources/xml/wst_ProofEncryption.xml +++ b/tests/resources/xml/wst_ProofEncryption.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_Reason.xml b/tests/resources/xml/wst_Reason.xml new file mode 100644 index 00000000..703fb825 --- /dev/null +++ b/tests/resources/xml/wst_Reason.xml @@ -0,0 +1 @@ +phpunit diff --git a/tests/resources/xml/wst_RenewTarget.xml b/tests/resources/xml/wst_RenewTarget.xml new file mode 100644 index 00000000..8cf8d4d0 --- /dev/null +++ b/tests/resources/xml/wst_RenewTarget.xml @@ -0,0 +1,3 @@ + + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de + diff --git a/tests/resources/xml/wst_Renewing.xml b/tests/resources/xml/wst_Renewing.xml new file mode 100644 index 00000000..141026a9 --- /dev/null +++ b/tests/resources/xml/wst_Renewing.xml @@ -0,0 +1 @@ + diff --git a/tests/resources/xml/wst_RequestedProofToken.xml b/tests/resources/xml/wst_RequestedProofToken.xml index e4429abf..5d196d8f 100644 --- a/tests/resources/xml/wst_RequestedProofToken.xml +++ b/tests/resources/xml/wst_RequestedProofToken.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_SignChallenge.xml b/tests/resources/xml/wst_SignChallenge.xml index af6587b4..aefc10f4 100644 --- a/tests/resources/xml/wst_SignChallenge.xml +++ b/tests/resources/xml/wst_SignChallenge.xml @@ -1,4 +1,4 @@ - + accepted - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_SignChallengeResponse.xml b/tests/resources/xml/wst_SignChallengeResponse.xml index 3c7934ab..bf179e44 100644 --- a/tests/resources/xml/wst_SignChallengeResponse.xml +++ b/tests/resources/xml/wst_SignChallengeResponse.xml @@ -1,4 +1,4 @@ - + accepted - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_Status.xml b/tests/resources/xml/wst_Status.xml new file mode 100644 index 00000000..a8431b05 --- /dev/null +++ b/tests/resources/xml/wst_Status.xml @@ -0,0 +1,4 @@ + + http://docs.oasis-open.org/ws-sx/ws-trust/200512/status/invalid + phpunit + diff --git a/tests/resources/xml/wst_UseKey.xml b/tests/resources/xml/wst_UseKey.xml index bd6760ce..63330cc4 100644 --- a/tests/resources/xml/wst_UseKey.xml +++ b/tests/resources/xml/wst_UseKey.xml @@ -1,3 +1,3 @@ - Some + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de diff --git a/tests/resources/xml/wst_ValidateTarget.xml b/tests/resources/xml/wst_ValidateTarget.xml new file mode 100644 index 00000000..6f7f79b2 --- /dev/null +++ b/tests/resources/xml/wst_ValidateTarget.xml @@ -0,0 +1,3 @@ + + uuid:d0ccf3cd-2dce-4c1a-a5d6-be8912ecd7de +