Skip to content

Commit

Permalink
Add element fed:PseudonymServiceEndpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Sep 15, 2024
1 parent db3aa10 commit 54bedcd
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/XML/fed/PseudonymServiceEndpoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\fed;

/**
* Class defining the PseudonymServiceEndpointz element
*
* @package simplesamlphp/ws-security
*/
final class PseudonymServiceEndpoints extends AbstractEndpointType
{
}
118 changes: 118 additions & 0 deletions tests/WSSecurity/XML/fed/PseudonymServiceEndpointsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\fed;

use DOMElement;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use SimpleSAML\WSSecurity\XML\fed\AbstractEndpointType;
use SimpleSAML\WSSecurity\XML\fed\AbstractFedElement;
use SimpleSAML\WSSecurity\XML\fed\PseudonymServiceEndpoints;
use SimpleSAML\WSSecurity\XML\wsa_200508\Address;
use SimpleSAML\WSSecurity\XML\wsa_200508\EndpointReference;
use SimpleSAML\WSSecurity\XML\wsa_200508\Metadata;
use SimpleSAML\WSSecurity\XML\wsa_200508\ReferenceParameters;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;
use function strval;

/**
* Tests for fed:PseudonymServiceEndpoints.
*
* @package simplesamlphp/ws-security
*/
#[Group('fed')]
#[CoversClass(PseudonymServiceEndpoints::class)]
#[CoversClass(AbstractEndpointType::class)]
#[CoversClass(AbstractFedElement::class)]
final class PseudonymServiceEndpointsTest extends TestCase
{
use SchemaValidationTestTrait;
use SerializableElementTestTrait;

/** @var \DOMElement $endpointReference */
protected static DOMElement $endpointReference;

/** @var \DOMElement $referenceParameters */
protected static DOMElement $referenceParameters;

/** @var \DOMElement $metadataContent */
protected static DOMElement $metadataContent;

/** @var \DOMElement $customContent */
protected static DOMElement $customContent;


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

self::$schemaFile = dirname(__FILE__, 5) . '/resources/schemas/ws-federation.xsd';

self::$xmlRepresentation = DOMDocumentFactory::FromFile(
dirname(__FILE__, 4) . '/resources/xml/fed_PseudonymServiceEndpoints.xml',
);

self::$referenceParameters = DOMDocumentFactory::fromString(
'<m:GetPrice xmlns:m="https://www.w3schools.com/prices"><m:Item>Pears</m:Item></m:GetPrice>',
)->documentElement;

self::$metadataContent = DOMDocumentFactory::fromString(
'<m:GetPrice xmlns:m="https://www.w3schools.com/prices"><m:Item>Apples</m:Item></m:GetPrice>',
)->documentElement;

self::$customContent = DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>',
)->documentElement;

self::$endpointReference = DOMDocumentFactory::fromFile(
dirname(__FILE__, 4) . '/resources/xml/wsa/200508/EndpointReference.xml',
)->documentElement;
}


// test marshalling


/**
* Test creating an PseudonymServiceEndpoints object from scratch.
*/
public function testMarshalling(): void
{
$doc = DOMDocumentFactory::fromString('<root/>');

$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'test1', 'value1');
$attr2 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'test2', 'value2');
$attr3 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'test3', 'value3');
$attr4 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'test4', 'value4');

$referenceParameters = new ReferenceParameters([new Chunk(self::$referenceParameters)], [$attr4]);
$metadata = new Metadata([new Chunk(self::$metadataContent)], [$attr3]);
$chunk = new Chunk(self::$customContent);

$endpointReference = new EndpointReference(
new Address('https://login.microsoftonline.com/login.srf', [$attr2]),
$referenceParameters,
$metadata,
[$chunk],
[$attr1],
);

$PseudonymServiceEndpoints = new PseudonymServiceEndpoints([$endpointReference]);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($PseudonymServiceEndpoints),
);
}
}
16 changes: 16 additions & 0 deletions tests/resources/xml/fed_PseudonymServiceEndpoints.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<fed:PseudonymServiceEndpoints xmlns:fed="http://docs.oasis-open.org/wsfed/federation/200706">
<wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:test1="value1">
<wsa:Address ssp:test2="value2">https://login.microsoftonline.com/login.srf</wsa:Address>
<wsa:ReferenceParameters xmlns:wsa="http://www.w3.org/2005/08/addressing" ssp:test4="value4">
<m:GetPrice xmlns:m="https://www.w3schools.com/prices">
<m:Item>Pears</m:Item>
</m:GetPrice>
</wsa:ReferenceParameters>
<wsa:Metadata ssp:test3="value3">
<m:GetPrice xmlns:m="https://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</wsa:Metadata>
<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>
</wsa:EndpointReference>
</fed:PseudonymServiceEndpoints>

0 comments on commit 54bedcd

Please sign in to comment.