Skip to content

Commit

Permalink
Add ds:MgmtData element
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 30, 2024
1 parent 1d752e7 commit 889f012
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/XML/ds/KeyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public static function fromXML(DOMElement $xml): static
$x509Data = X509Data::getChildrenOfClass($xml);
//$pgpData = PGPData::getChildrenOfClass($xml);
//$spkiData = SPKIData::getChildrenOfClass($xml);
//$mgmtData = MgmtData::getChildrenOfClass($xml);
$mgmtData = MgmtData::getChildrenOfClass($xml);
$other = self::getChildElementsFromXML($xml);

$info = array_merge(
$keyName,
$keyValue,
$retrievalMethod,
$x509Data,
//$pgpdata,
//$spkidata,
//$mgmtdata,
//$pgpData,
//$spkiData,
$mgmtData,
$other,
);

Expand Down
26 changes: 26 additions & 0 deletions src/XML/ds/MgmtData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\XML\ds;

use SimpleSAML\XML\StringElementTrait;

/**
* Class representing a ds:MgmtData element.
*
* @package simplesamlphp/xml-security
*/
final class MgmtData extends AbstractDsElement
{
use StringElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
2 changes: 1 addition & 1 deletion src/XML/element.registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'KeyName' => '\SimpleSAML\XMLSecurity\XML\ds\KeyName',
'KeyValue' => '\SimpleSAML\XMLSecurity\XML\ds\KeyValue',
'Manifest' => '\SimpleSAML\XMLSecurity\XML\ds\Manifest',
// 'MgmtData' => '\SimpleSAML\XMLSecurity\XML\ds\MgmtData',
'MgmtData' => '\SimpleSAML\XMLSecurity\XML\ds\MgmtData',
'Object' => '\SimpleSAML\XMLSecurity\XML\ds\DsObject',
// 'PGPData' => '\SimpleSAML\XMLSecurity\XML\ds\PGPData',
'Reference' => '\SimpleSAML\XMLSecurity\XML\ds\Reference',
Expand Down
9 changes: 5 additions & 4 deletions src/XML/xenc/OriginatorKeyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType;
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
use SimpleSAML\XMLSecurity\XML\ds\KeyValue;
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;
use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod;
use SimpleSAML\XMLSecurity\XML\ds\X509Data;

Expand Down Expand Up @@ -52,17 +53,17 @@ public static function fromXML(DOMElement $xml): static
$x509Data = X509Data::getChildrenOfClass($xml);
//$pgpData = PGPData::getChildrenOfClass($xml);
//$spkiData = SPKIData::getChildrenOfClass($xml);
//$mgmtData = MgmtData::getChildrenOfClass($xml);
$mgmtData = MgmtData::getChildrenOfClass($xml);
$other = self::getChildElementsFromXML($xml);

$info = array_merge(
$keyName,
$keyValue,
$retrievalMethod,
$x509Data,
//$pgpdata,
//$spkidata,
//$mgmtdata,
//$pgpData,
//$spkiData,
$mgmtData,
$other,
);

Expand Down
9 changes: 5 additions & 4 deletions src/XML/xenc/RecipientKeyInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType;
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
use SimpleSAML\XMLSecurity\XML\ds\KeyValue;
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;
use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod;
use SimpleSAML\XMLSecurity\XML\ds\X509Data;

Expand Down Expand Up @@ -52,17 +53,17 @@ public static function fromXML(DOMElement $xml): static
$x509Data = X509Data::getChildrenOfClass($xml);
//$pgpData = PGPData::getChildrenOfClass($xml);
//$spkiData = SPKIData::getChildrenOfClass($xml);
//$mgmtData = MgmtData::getChildrenOfClass($xml);
$mgmtData = MgmtData::getChildrenOfClass($xml);
$other = self::getChildElementsFromXML($xml);

$info = array_merge(
$keyName,
$keyValue,
$retrievalMethod,
$x509Data,
//$pgpdata,
//$spkidata,
//$mgmtdata,
//$pgpData,
//$spkiData,
$mgmtData,
$other,
);

Expand Down
55 changes: 55 additions & 0 deletions tests/XML/ds/MgmtDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Test\XML\ds;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
use SimpleSAML\XMLSecurity\XML\ds\MgmtData;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\MgmtDataTest
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(AbstractDsElement::class)]
#[CoversClass(MgmtData::class)]
final class MgmtDataTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;

/**
*/
public static function setUpBeforeClass(): void
{
self::$testedClass = MgmtData::class;

self::$schemaFile = dirname(__FILE__, 4) . '/resources/schemas/xmldsig1-schema.xsd';

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


/**
*/
public function testMarshalling(): void
{
$mgmtData = new MgmtData('ManagementData');

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($mgmtData),
);
}
}
33 changes: 33 additions & 0 deletions tests/XML/ds/SignatureMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Utils\XPath;
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength;
use SimpleSAML\XMLSecurity\XML\ds\SignatureMethod;
Expand Down Expand Up @@ -61,4 +62,36 @@ public function testMarshalling(): void
strval($signatureMethod),
);
}


/**
*/
public function testMarshallingElementOrder(): void
{
$hmacOutputLength = new HMACOutputLength('1234');

$chunk = new Chunk(DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">Some</ssp:Chunk>',
)->documentElement);

$signatureMethod = new SignatureMethod(C::SIG_RSA_SHA256, $hmacOutputLength, [$chunk]);

$signatureMethodElement = $signatureMethod->toXML();

$xpCache = XPath::getXPath($signatureMethodElement);

$hmacOutputLength = XPath::xpQuery($signatureMethodElement, './ds:HMACOutputLength', $xpCache);
$this->assertCount(1, $hmacOutputLength);

/** @var \DOMElement[] $signatureMethodElements */
$signatureMethodElements = XPath::xpQuery(
$signatureMethodElement,
'./ds:HMACOutputLength/following-sibling::*',
$xpCache,
);

// Test ordering of SignatureMethod contents
$this->assertCount(1, $signatureMethodElements);
$this->assertEquals('ssp:Chunk', $signatureMethodElements[0]->tagName);
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/ds_MgmtData.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ds:MgmtData xmlns:ds="http://www.w3.org/2000/09/xmldsig#">ManagementData</ds:MgmtData>

0 comments on commit 889f012

Please sign in to comment.