Skip to content

Commit 889f012

Browse files
committed
Add ds:MgmtData element
1 parent 1d752e7 commit 889f012

File tree

8 files changed

+130
-13
lines changed

8 files changed

+130
-13
lines changed

src/XML/ds/KeyInfo.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public static function fromXML(DOMElement $xml): static
3939
$x509Data = X509Data::getChildrenOfClass($xml);
4040
//$pgpData = PGPData::getChildrenOfClass($xml);
4141
//$spkiData = SPKIData::getChildrenOfClass($xml);
42-
//$mgmtData = MgmtData::getChildrenOfClass($xml);
42+
$mgmtData = MgmtData::getChildrenOfClass($xml);
4343
$other = self::getChildElementsFromXML($xml);
4444

4545
$info = array_merge(
4646
$keyName,
4747
$keyValue,
4848
$retrievalMethod,
4949
$x509Data,
50-
//$pgpdata,
51-
//$spkidata,
52-
//$mgmtdata,
50+
//$pgpData,
51+
//$spkiData,
52+
$mgmtData,
5353
$other,
5454
);
5555

src/XML/ds/MgmtData.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\ds;
6+
7+
use SimpleSAML\XML\StringElementTrait;
8+
9+
/**
10+
* Class representing a ds:MgmtData element.
11+
*
12+
* @package simplesamlphp/xml-security
13+
*/
14+
final class MgmtData extends AbstractDsElement
15+
{
16+
use StringElementTrait;
17+
18+
19+
/**
20+
* @param string $content
21+
*/
22+
public function __construct(string $content)
23+
{
24+
$this->setContent($content);
25+
}
26+
}

src/XML/element.registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'KeyName' => '\SimpleSAML\XMLSecurity\XML\ds\KeyName',
1313
'KeyValue' => '\SimpleSAML\XMLSecurity\XML\ds\KeyValue',
1414
'Manifest' => '\SimpleSAML\XMLSecurity\XML\ds\Manifest',
15-
// 'MgmtData' => '\SimpleSAML\XMLSecurity\XML\ds\MgmtData',
15+
'MgmtData' => '\SimpleSAML\XMLSecurity\XML\ds\MgmtData',
1616
'Object' => '\SimpleSAML\XMLSecurity\XML\ds\DsObject',
1717
// 'PGPData' => '\SimpleSAML\XMLSecurity\XML\ds\PGPData',
1818
'Reference' => '\SimpleSAML\XMLSecurity\XML\ds\Reference',

src/XML/xenc/OriginatorKeyInfo.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType;
1212
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
1313
use SimpleSAML\XMLSecurity\XML\ds\KeyValue;
14+
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;
1415
use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod;
1516
use SimpleSAML\XMLSecurity\XML\ds\X509Data;
1617

@@ -52,17 +53,17 @@ public static function fromXML(DOMElement $xml): static
5253
$x509Data = X509Data::getChildrenOfClass($xml);
5354
//$pgpData = PGPData::getChildrenOfClass($xml);
5455
//$spkiData = SPKIData::getChildrenOfClass($xml);
55-
//$mgmtData = MgmtData::getChildrenOfClass($xml);
56+
$mgmtData = MgmtData::getChildrenOfClass($xml);
5657
$other = self::getChildElementsFromXML($xml);
5758

5859
$info = array_merge(
5960
$keyName,
6061
$keyValue,
6162
$retrievalMethod,
6263
$x509Data,
63-
//$pgpdata,
64-
//$spkidata,
65-
//$mgmtdata,
64+
//$pgpData,
65+
//$spkiData,
66+
$mgmtData,
6667
$other,
6768
);
6869

src/XML/xenc/RecipientKeyInfo.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType;
1212
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
1313
use SimpleSAML\XMLSecurity\XML\ds\KeyValue;
14+
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;
1415
use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod;
1516
use SimpleSAML\XMLSecurity\XML\ds\X509Data;
1617

@@ -52,17 +53,17 @@ public static function fromXML(DOMElement $xml): static
5253
$x509Data = X509Data::getChildrenOfClass($xml);
5354
//$pgpData = PGPData::getChildrenOfClass($xml);
5455
//$spkiData = SPKIData::getChildrenOfClass($xml);
55-
//$mgmtData = MgmtData::getChildrenOfClass($xml);
56+
$mgmtData = MgmtData::getChildrenOfClass($xml);
5657
$other = self::getChildElementsFromXML($xml);
5758

5859
$info = array_merge(
5960
$keyName,
6061
$keyValue,
6162
$retrievalMethod,
6263
$x509Data,
63-
//$pgpdata,
64-
//$spkidata,
65-
//$mgmtdata,
64+
//$pgpData,
65+
//$spkiData,
66+
$mgmtData,
6667
$other,
6768
);
6869

tests/XML/ds/MgmtDataTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
11+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
12+
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
13+
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;
14+
15+
use function dirname;
16+
use function strval;
17+
18+
/**
19+
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\MgmtDataTest
20+
*
21+
* @package simplesamlphp/xml-security
22+
*/
23+
#[CoversClass(AbstractDsElement::class)]
24+
#[CoversClass(MgmtData::class)]
25+
final class MgmtDataTest extends TestCase
26+
{
27+
use SchemaValidationTestTrait;
28+
use SerializableElementTestTrait;
29+
30+
/**
31+
*/
32+
public static function setUpBeforeClass(): void
33+
{
34+
self::$testedClass = MgmtData::class;
35+
36+
self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd';
37+
38+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
39+
dirname(__FILE__, 3) . '/resources/xml/ds_MgmtData.xml',
40+
);
41+
}
42+
43+
44+
/**
45+
*/
46+
public function testMarshalling(): void
47+
{
48+
$mgmtData = new MgmtData('ManagementData');
49+
50+
$this->assertEquals(
51+
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
52+
strval($mgmtData),
53+
);
54+
}
55+
}

tests/XML/ds/SignatureMethodTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
1212
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
1313
use SimpleSAML\XMLSecurity\Constants as C;
14+
use SimpleSAML\XMLSecurity\Utils\XPath;
1415
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
1516
use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength;
1617
use SimpleSAML\XMLSecurity\XML\ds\SignatureMethod;
@@ -61,4 +62,36 @@ public function testMarshalling(): void
6162
strval($signatureMethod),
6263
);
6364
}
65+
66+
67+
/**
68+
*/
69+
public function testMarshallingElementOrder(): void
70+
{
71+
$hmacOutputLength = new HMACOutputLength('1234');
72+
73+
$chunk = new Chunk(DOMDocumentFactory::fromString(
74+
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
75+
)->documentElement);
76+
77+
$signatureMethod = new SignatureMethod(C::SIG_RSA_SHA256, $hmacOutputLength, [$chunk]);
78+
79+
$signatureMethodElement = $signatureMethod->toXML();
80+
81+
$xpCache = XPath::getXPath($signatureMethodElement);
82+
83+
$hmacOutputLength = XPath::xpQuery($signatureMethodElement, './ds:HMACOutputLength', $xpCache);
84+
$this->assertCount(1, $hmacOutputLength);
85+
86+
/** @var \DOMElement[] $signatureMethodElements */
87+
$signatureMethodElements = XPath::xpQuery(
88+
$signatureMethodElement,
89+
'./ds:HMACOutputLength/following-sibling::*',
90+
$xpCache,
91+
);
92+
93+
// Test ordering of SignatureMethod contents
94+
$this->assertCount(1, $signatureMethodElements);
95+
$this->assertEquals('ssp:Chunk', $signatureMethodElements[0]->tagName);
96+
}
6497
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ds:MgmtData xmlns:ds="http://www.w3.org/2000/09/xmldsig#">ManagementData</ds:MgmtData>

0 commit comments

Comments
 (0)