Skip to content

Commit

Permalink
WIP: create fed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 6, 2024
1 parent 4ba3c7e commit 7a5f72f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/XML/fed/Realm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\fed;

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\StringElementTrait;

use function sprintf;

/**
* A Realm element
*
* @package tvdijen/ws-security
*/
final class Realm extends AbstractFedElement
{
use StringElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}


/**
* Validate the content of the element.
*
* @param string $content The value to go in the XML textContent
* @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure
* @return void
*/
protected function validateContent(string $content): void
{
Assert::validURI($content, SchemaViolationException::class);
}
}
3 changes: 2 additions & 1 deletion src/XML/sp/IssuerName.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SimpleSAML\WSSecurity\XML\sp;

use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\StringElementTrait;

/**
Expand Down Expand Up @@ -38,6 +39,6 @@ public function __construct(
*/
protected function validateContent(string $content): void
{
Assert::validURI($content);
Assert::validURI($content, SchemaViolationException::class);
}
}
59 changes: 59 additions & 0 deletions tests/WSSecurity/XML/fed/RealmTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\sp;

use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\XML\fed\Realm;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\fed\RealmTest
*
* @covers \SimpleSAML\WSSecurity\XML\fed\Realm
* @covers \SimpleSAML\WSSecurity\XML\fed\AbstractFedElement
*
* @package tvdijen/ws-security
*/
final class RealmTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


/**
*/
public static function setUpBeforeClass(): void
{
self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-federation.xsd';

self::$testedClass = Realm::class;

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


// test marshalling


/**
* Test creating a Realm object from scratch.
*/
public function testMarshalling(): void
{
$realm = new Realm(C::NAMESPACE);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($realm),
);
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/fed_Realm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<fed:Realm xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706">urn:x-simplesamlphp:namespace</fed:Realm>

0 comments on commit 7a5f72f

Please sign in to comment.