Skip to content

Commit dc144d9

Browse files
committed
WIP: create fed classes
1 parent 3fe7246 commit dc144d9

File tree

10 files changed

+293
-0
lines changed

10 files changed

+293
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WSSecurity\XML\fed;
6+
7+
use DOMElement;
8+
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\XML\Base64ElementTrait;
10+
use SimpleSAML\XML\Exception\InvalidDOMElementException;
11+
use SimpleSAML\XML\ExtendableAttributesTrait;
12+
use SimpleSAML\XML\XsNamespace as NS;
13+
14+
/**
15+
* An AbstractReferenceDigestType element
16+
*
17+
* @package tvdijen/ws-security
18+
*/
19+
abstract class AbstractReferenceDigestType extends AbstractFedElement
20+
{
21+
use ExtendableAttributesTrait;
22+
use Base64ElementTrait;
23+
24+
/** The namespace-attribute for the xs:anyAttribute element */
25+
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER;
26+
27+
28+
/**
29+
* @param string $content
30+
* @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
31+
*/
32+
public function __construct(string $content, array $namespacedAttributes)
33+
{
34+
$this->setContent($content);
35+
$this->setAttributesNS($namespacedAttributes);
36+
}
37+
38+
39+
/**
40+
* Create a class from XML
41+
*
42+
* @param \DOMElement $xml
43+
* @return static
44+
*/
45+
public static function fromXML(DOMElement $xml): static
46+
{
47+
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
48+
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
49+
50+
return new static(
51+
$xml->textContent,
52+
self::getAttributesNSFromXML($xml),
53+
);
54+
}
55+
56+
57+
/**
58+
* Create XML from this class
59+
*
60+
* @param \DOMElement|null $parent
61+
* @return \DOMElement
62+
*/
63+
public function toXML(DOMElement $parent = null): DOMElement
64+
{
65+
$e = $this->instantiateParentElement($parent);
66+
$e->textContent = $this->getContent();
67+
68+
foreach ($this->getAttributesNS() as $attr) {
69+
$attr->toXML($e);
70+
}
71+
72+
return $e;
73+
}
74+
}

src/XML/fed/ReferenceDigest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WSSecurity\XML\fed;
6+
7+
/**
8+
* A ReferenceDigest element
9+
*
10+
* @package tvdijen/ws-security
11+
*/
12+
final class ReferenceDigest extends AbstractReferenceDigestType
13+
{
14+
}

src/XML/fed/ReferenceType.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WSSecurity\XML\fed;
6+
7+
/**
8+
* A ReferenceType element
9+
*
10+
* @package tvdijen/ws-security
11+
*/
12+
final class ReferenceType extends AbstractAttributeExtensibleURIType
13+
{
14+
}

src/XML/fed/SerialNo.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\WSSecurity\XML\fed;
6+
7+
/**
8+
* A SerialNo element
9+
*
10+
* @package tvdijen/ws-security
11+
*/
12+
final class SerialNo extends AbstractAttributeExtensibleURIType
13+
{
14+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\WSSecurity\XML\sp;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use SimpleSAML\Test\WSSecurity\Constants as C;
9+
use SimpleSAML\WSSecurity\XML\fed\ReferenceDigest;
10+
use SimpleSAML\XML\Attribute as XMLAttribute;
11+
use SimpleSAML\XML\DOMDocumentFactory;
12+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13+
14+
use function dirname;
15+
16+
/**
17+
* Class \SimpleSAML\WSSecurity\XML\fed\ReferenceDigestTest
18+
*
19+
* @covers \SimpleSAML\WSSecurity\XML\fed\ReferenceDigest
20+
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractReferenceDigestType
21+
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement
22+
*
23+
* @package tvdijen/ws-security
24+
*/
25+
final class ReferenceDigestTest extends TestCase
26+
{
27+
use SerializableElementTestTrait;
28+
29+
30+
/**
31+
*/
32+
public static function setUpBeforeClass(): void
33+
{
34+
self::$testedClass = ReferenceDigest::class;
35+
36+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
37+
dirname(__FILE__, 4) . '/resources/xml/fed_ReferenceDigest.xml',
38+
);
39+
}
40+
41+
42+
// test marshalling
43+
44+
45+
/**
46+
* Test creating a ReferenceDigest object from scratch.
47+
*/
48+
public function testMarshalling(): void
49+
{
50+
$attr1 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1');
51+
$referenceDigest = new ReferenceDigest('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=', [$attr1]);
52+
53+
$this->assertEquals(
54+
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
55+
strval($referenceDigest),
56+
);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\WSSecurity\XML\sp;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use SimpleSAML\Test\WSSecurity\Constants as C;
9+
use SimpleSAML\WSSecurity\XML\fed\ReferenceType;
10+
use SimpleSAML\XML\Attribute as XMLAttribute;
11+
use SimpleSAML\XML\DOMDocumentFactory;
12+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13+
14+
use function dirname;
15+
16+
/**
17+
* Class \SimpleSAML\WSSecurity\XML\fed\ReferenceTypeTest
18+
*
19+
* @covers \SimpleSAML\WSSecurity\XML\fed\ReferenceType
20+
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractAttributeExtensibleURIType
21+
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement
22+
*
23+
* @package tvdijen/ws-security
24+
*/
25+
final class ReferenceTypeTest extends TestCase
26+
{
27+
use SerializableElementTestTrait;
28+
29+
30+
/**
31+
*/
32+
public static function setUpBeforeClass(): void
33+
{
34+
self::$testedClass = ReferenceType::class;
35+
36+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
37+
dirname(__FILE__, 4) . '/resources/xml/fed_ReferenceType.xml',
38+
);
39+
}
40+
41+
42+
// test marshalling
43+
44+
45+
/**
46+
* Test creating a ReferenceType object from scratch.
47+
*/
48+
public function testMarshalling(): void
49+
{
50+
$attr1 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1');
51+
$referenceType = new ReferenceType(C::NAMESPACE, [$attr1]);
52+
53+
$this->assertEquals(
54+
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
55+
strval($referenceType),
56+
);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\WSSecurity\XML\sp;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use SimpleSAML\Test\WSSecurity\Constants as C;
9+
use SimpleSAML\WSSecurity\XML\fed\SerialNo;
10+
use SimpleSAML\XML\Attribute as XMLAttribute;
11+
use SimpleSAML\XML\DOMDocumentFactory;
12+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
13+
14+
use function dirname;
15+
16+
/**
17+
* Class \SimpleSAML\WSSecurity\XML\fed\SerialNoTest
18+
*
19+
* @covers \SimpleSAML\WSSecurity\XML\fed\SerialNo
20+
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractAttributeExtensibleURIType
21+
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement
22+
*
23+
* @package tvdijen/ws-security
24+
*/
25+
final class SerialNoTest extends TestCase
26+
{
27+
use SerializableElementTestTrait;
28+
29+
30+
/**
31+
*/
32+
public static function setUpBeforeClass(): void
33+
{
34+
self::$testedClass = SerialNo::class;
35+
36+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
37+
dirname(__FILE__, 4) . '/resources/xml/fed_SerialNo.xml',
38+
);
39+
}
40+
41+
42+
// test marshalling
43+
44+
45+
/**
46+
* Test creating a SerialNo object from scratch.
47+
*/
48+
public function testMarshalling(): void
49+
{
50+
$attr1 = new XMLAttribute(C::NAMESPACE, 'ssp', 'attr1', 'testval1');
51+
$serialNo = new SerialNo(C::NAMESPACE, [$attr1]);
52+
53+
$this->assertEquals(
54+
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
55+
strval($serialNo),
56+
);
57+
}
58+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<fed:ReferenceDigest xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706" xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</fed:ReferenceDigest>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<fed:ReferenceType xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706" xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">urn:x-simplesamlphp:namespace</fed:ReferenceType>

tests/resources/xml/fed_SerialNo.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<fed:SerialNo xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706" xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">urn:x-simplesamlphp:namespace</fed:SerialNo>

0 commit comments

Comments
 (0)