Skip to content

Commit e2d8eff

Browse files
committed
Add element xenc:Public
1 parent 2f17b7f commit e2d8eff

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

src/XML/xenc/XencPublic.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\xenc;
6+
7+
use SimpleSAML\XML\Base64ElementTrait;
8+
9+
/**
10+
* Class representing a xenc:Public element.
11+
*
12+
* @package simplesaml/xml-security
13+
*/
14+
final class XencPublic extends AbstractXencElement
15+
{
16+
use Base64ElementTrait;
17+
18+
/** @var string */
19+
public const LOCALNAME = 'Public';
20+
21+
22+
/**
23+
* @param string $content
24+
*/
25+
public function __construct(string $content)
26+
{
27+
$this->setContent($content);
28+
}
29+
}

tests/XML/xenc/PublicTest.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML\xenc;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\Assert\AssertionFailedException;
10+
use SimpleSAML\XML\DOMDocumentFactory;
11+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
12+
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
13+
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement;
14+
use SimpleSAML\XMLSecurity\XML\xenc\XencPublic;
15+
16+
use function dirname;
17+
use function strval;
18+
19+
/**
20+
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\PublicTest
21+
*
22+
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
23+
* @covers \SimpleSAML\XMLSecurity\XML\xenc\XencPublic
24+
*
25+
* @package simplesamlphp/xml-security
26+
*/
27+
#[CoversClass(AbstractXencElement::class)]
28+
#[CoversClass(XencPublic::class)]
29+
final class PublicTest extends TestCase
30+
{
31+
use SerializableElementTestTrait;
32+
33+
/**
34+
*/
35+
public static function setUpBeforeClass(): void
36+
{
37+
self::$testedClass = XencPublic::class;
38+
39+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
40+
dirname(__FILE__, 3) . '/resources/xml/xenc_Public.xml',
41+
);
42+
}
43+
44+
45+
/**
46+
*/
47+
public function testMarshalling(): void
48+
{
49+
$public = new XencPublic('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
50+
51+
$this->assertEquals(
52+
XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
53+
strval($public),
54+
);
55+
}
56+
57+
58+
/**
59+
*/
60+
public function testMarshallingNotBase64(): void
61+
{
62+
$this->expectException(AssertionFailedException::class);
63+
new XencPublic('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
64+
}
65+
}

tests/resources/xml/xenc_Public.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<xenc:Public xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</xenc:Public>

0 commit comments

Comments
 (0)