diff --git a/src/XML/fed/AbstractProofTokenType.php b/src/XML/fed/AbstractProofTokenType.php new file mode 100644 index 00000000..87352f07 --- /dev/null +++ b/src/XML/fed/AbstractProofTokenType.php @@ -0,0 +1,107 @@ +setElements([$child]); + $this->setAttributesNS($namespacedAttributes); + } + + + /** + * 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, SchemaViolationException::class); + Assert::maxCount($children, 1, SchemaViolationException::class); + + return new static( + array_pop($children), + self::getAttributesNSFromXML($xml), + ); + } + + + /** + * Add this AbstractProofTokenType 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->getAttributesNS() as $attr) { + $attr->toXML($e); + } + + /** @psalm-var \SimpleSAML\XML\SerializableElementInterface $child */ + foreach ($this->getElements() as $child) { + if (!$child->isEmptyElement()) { + $child->toXML($e); + } + } + + return $e; + } +} diff --git a/src/XML/fed/ProofToken.php b/src/XML/fed/ProofToken.php new file mode 100644 index 00000000..d55303ec --- /dev/null +++ b/src/XML/fed/ProofToken.php @@ -0,0 +1,14 @@ +SomeChunk', + ); + + $proofToken = new ProofToken( + new Chunk($child->documentElement), + [$attr1], + ); + + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($proofToken), + ); + } +} diff --git a/tests/WSSecurity/XML/fed/RequestPseudonymTest.php b/tests/WSSecurity/XML/fed/RequestPseudonymTest.php index ddee4fe7..fb8bea27 100644 --- a/tests/WSSecurity/XML/fed/RequestPseudonymTest.php +++ b/tests/WSSecurity/XML/fed/RequestPseudonymTest.php @@ -20,7 +20,7 @@ * Tests for fed:RequestPseudonym. * * @covers \SimpleSAML\WSSecurity\XML\fed\RequestPseudonym - * @covers \SimpleSAML\WSSecurity\XML\fed\AbstractRequestPseudonym + * @covers \SimpleSAML\WSSecurity\XML\fed\AbstractRequestPseudonymType * @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement * @package tvdijen/ws-security */ diff --git a/tests/resources/xml/fed_ProofToken.xml b/tests/resources/xml/fed_ProofToken.xml new file mode 100644 index 00000000..e718d8d5 --- /dev/null +++ b/tests/resources/xml/fed_ProofToken.xml @@ -0,0 +1,3 @@ + + SomeChunk +