Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement missing xenc elements #57

Merged
merged 12 commits into from
Nov 28, 2024
Prev Previous commit
Next Next commit
Add element xenc:pgenGenerator
  • Loading branch information
tvdijen committed Nov 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit ff5cbf0fa2dc4a922bd589121b0d7a5889013708
29 changes: 29 additions & 0 deletions src/XML/xenc/PgenCounter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\XML\xenc;

use SimpleSAML\XML\Base64ElementTrait;

/**
* Class representing a xenc:pgenCounter element.
*
* @package simplesaml/xml-security
*/
final class PgenCounter extends AbstractXencElement
{
use Base64ElementTrait;

/** @var string */
public const LOCALNAME = 'pgenCounter';


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
65 changes: 65 additions & 0 deletions tests/XML/xenc/PgenCounterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Test\XML\xenc;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement;
use SimpleSAML\XMLSecurity\XML\xenc\PgenCounter;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\PgenCounterTest
*
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
* @covers \SimpleSAML\XMLSecurity\XML\xenc\PgenCounter
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(AbstractXencElement::class)]
#[CoversClass(PgenCounter::class)]
final class PgenCounterTest extends TestCase
{
use SerializableElementTestTrait;

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

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


/**
*/
public function testMarshalling(): void
{
$pgenCounter = new PgenCounter('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');

$this->assertEquals(
XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
strval($pgenCounter),
);
}


/**
*/
public function testMarshallingNotBase64(): void
{
$this->expectException(AssertionFailedException::class);
new PgenCounter('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/xenc_pgenCounter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<xenc:pgenCounter xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</xenc:pgenCounter>