Skip to content

Commit

Permalink
Add mex classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jan 28, 2024
1 parent b3c94bf commit ce91037
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class Constants extends \SimpleSAML\SAML2\Constants
*/
public const NS_SEC_UTIL = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';

/**
* The namespace for the Metadata Exchange protocol.
*/
public const NS_MEX = 'http://schemas.xmlsoap.org/ws/2004/09/mex';

/**
* The schema-defined wsa fault codes
*/
Expand Down
22 changes: 22 additions & 0 deletions src/XML/mex/AbstractMexElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\mex;

use SimpleSAML\WSSecurity\Constants as C;
use SimpleSAML\XML\AbstractElement;

/**
* Abstract class to be implemented by all the classes in this namespace
*
* @package tvdijen/ws-security
*/
abstract class AbstractMexElement extends AbstractElement
{
/** @var string */
public const NS = C::NS_MEX;

/** @var string */
public const NS_PREFIX = 'mex';
}
26 changes: 26 additions & 0 deletions src/XML/mex/Dialect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\mex;

use SimpleSAML\XML\URIElementTrait;

/**
* An Dialect element
*
* @package tvdijen/ws-security
*/
final class Dialect extends AbstractMexElement
{
use URIElementTrait;


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

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\mex;

use SimpleSAML\XML\URIElementTrait;

/**
* An Identifier element
*
* @package tvdijen/ws-security
*/
final class Identifier extends AbstractMexElement
{
use URIElementTrait;


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

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\mex;

use SimpleSAML\XML\URIElementTrait;

/**
* An Location element
*
* @package tvdijen/ws-security
*/
final class Location extends AbstractMexElement
{
use URIElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
59 changes: 59 additions & 0 deletions tests/WSSecurity/XML/mex/DialectTest.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\mex;

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

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\mex\DialectTest
*
* @covers \SimpleSAML\WSSecurity\XML\mex\Dialect
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractMexElement
*
* @package tvdijen/ws-security
*/
final class DialectTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


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

self::$testedClass = Dialect::class;

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


// test marshalling


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

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($dialect),
);
}
}
59 changes: 59 additions & 0 deletions tests/WSSecurity/XML/mex/IdentifierTest.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\mex;

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

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\mex\IdentifierTest
*
* @covers \SimpleSAML\WSSecurity\XML\mex\Identifier
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractMexElement
*
* @package tvdijen/ws-security
*/
final class IdentifierTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


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

self::$testedClass = Identifier::class;

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


// test marshalling


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

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($identifier),
);
}
}
59 changes: 59 additions & 0 deletions tests/WSSecurity/XML/mex/LocationTest.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\mex;

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

use function dirname;

/**
* Class \SimpleSAML\WSSecurity\XML\mex\LocationTest
*
* @covers \SimpleSAML\WSSecurity\XML\mex\Location
* @covers \SimpleSAML\WSSecurity\XML\wst\AbstractMexElement
*
* @package tvdijen/ws-security
*/
final class LocationTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;


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

self::$testedClass = Location::class;

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


// test marshalling


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

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($location),
);
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/mex_Dialect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mex:Dialect xmlns:mex="http://schemas.xmlsoap.org/ws/2004/09/mex">urn:x-simplesamlphp:namespace</mex:Dialect>
1 change: 1 addition & 0 deletions tests/resources/xml/mex_Identifier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mex:Identifier xmlns:mex="http://schemas.xmlsoap.org/ws/2004/09/mex">urn:x-simplesamlphp:namespace</mex:Identifier>
1 change: 1 addition & 0 deletions tests/resources/xml/mex_Location.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mex:Location xmlns:mex="http://schemas.xmlsoap.org/ws/2004/09/mex">urn:x-simplesamlphp:namespace</mex:Location>

0 comments on commit ce91037

Please sign in to comment.