Skip to content

Commit

Permalink
Add auth:ValueOneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jul 18, 2023
1 parent d0d3dcf commit efbe300
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/XML/auth/AbstractConstrainedManyValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public static function fromXML(DOMElement $xml): static
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);

$structuredValue = StructuredValue::getChildrenOfClass($xml);
Assert::maxCount($structuredValue, 1, TooManyElementsException::class);

$value = Value::getChildrenOfClass($xml);
Assert::maxCount($value, 1, TooManyElementsException::class);

return new static(
$value,
Expand Down
14 changes: 14 additions & 0 deletions src/XML/auth/ValueInRangen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\auth;

/**
* Class representing WS-authorization ValueInRangen.
*
* @package tvdijen/ws-security
*/
final class ValueInRangen extends AbstractValueInRangeType
{
}
14 changes: 14 additions & 0 deletions src/XML/auth/ValueOneOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\WSSecurity\XML\auth;

/**
* Class representing WS-authorization ValueOneOf.
*
* @package tvdijen/ws-security
*/
final class ValueOneOf extends AbstractConstrainedManyValueType
{
}
74 changes: 74 additions & 0 deletions tests/WSSecurity/XML/auth/ConstrainedManyValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\auth;

use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\XML\auth\StructuredValue;
use SimpleSAML\WSSecurity\XML\auth\Value;
use SimpleSAML\WSSecurity\XML\auth\ValueOneOf;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;

/**
* Tests for auth:ConstrainedManyValueType.
*
* @covers \SimpleSAML\WSSecurity\XML\auth\AbstractConstrainedManyValueType
* @covers \SimpleSAML\WSSecurity\XML\auth\AbstractAuthElement
* @package tvdijen/ws-security
*/
final class ConstrainedManyValueTest extends TestCase
{
/**
* Test creating an object from scratch.
*
* @param class-string $class
*
* @dataProvider classProvider
*/
public function testMarshallingEmpty(string $class): void
{
$x = new $class([], []);
$this->assertTrue($x->isEmptyElement());
}


/**
* Test creating an object from scratch with both Value and StructuredValue.
*
* @param class-string $class
*
* @dataProvider classProvider
*/
public function testMarshallingIllegalCombination(string $class): void
{
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1');
$child = DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>',
);

$structuredValue = new StructuredValue(
[new Chunk($child->documentElement)],
[$attr1],
);

$value = new Value('MyValue');

$this->expectException(AssertionFailedException::class);
new $class([$value], [$structuredValue]);
}


/**
*/
public static function classProvider(): array
{
return [
'auth:ValueOneOf' => [ValueOneOf::class],
];
}
}
92 changes: 92 additions & 0 deletions tests/WSSecurity/XML/auth/ValueInRangenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\auth;

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\WSSecurity\Constants as C;
use SimpleSAML\WSSecurity\XML\auth\StructuredValue;
use SimpleSAML\WSSecurity\XML\auth\Value;
use SimpleSAML\WSSecurity\XML\auth\ValueInRangen;
use SimpleSAML\WSSecurity\XML\auth\ValueLowerBound;
use SimpleSAML\WSSecurity\XML\auth\ValueUpperBound;
use SimpleSAML\XML\Attribute as XMLAttribute;
use SimpleSAML\XML\Chunk;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;
use function strval;

/**
* Tests for auth:ValueInRangen.
*
* @covers \SimpleSAML\WSSecurity\XML\auth\ValueInRangen
* @covers \SimpleSAML\WSSecurity\XML\auth\AbstractValueInRangeType
* @covers \SimpleSAML\WSSecurity\XML\auth\AbstractAuthElement
* @package tvdijen/ws-security
*/
final class ValueInRangenTest extends TestCase
{
use SerializableElementTestTrait;


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

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


// test marshalling


/**
* Test creating a ValueInRangen object from scratch.
*/
public function testMarshalling(): void
{
$attr1 = new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1');
$child = DOMDocumentFactory::fromString(
'<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">SomeChunk</ssp:Chunk>',
);

$structuredValue = new StructuredValue(
[new Chunk($child->documentElement)],
[$attr1],
);

$valueUpperBound = new ValueUpperBound(null, $structuredValue);
$valueLowerBound = new ValueLowerBound(new Value('MyValue'), null);
$valueInRangen = new ValueInRangen($valueUpperBound, $valueLowerBound);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($valueInRangen),
);
}


// test unmarshalling


/**
* Test creating a ValueInRangen from XML.
*/
public function testUnmarshalling(): void
{
$valueInRangen = ValueInRangen::fromXML(self::$xmlRepresentation->documentElement);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($valueInRangen),
);
}
}
77 changes: 77 additions & 0 deletions tests/WSSecurity/XML/auth/ValueOneOfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\WSSecurity\XML\auth;

use DOMDocument;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\WSSecurity\Constants;
use SimpleSAML\WSSecurity\XML\auth\Value;
use SimpleSAML\WSSecurity\XML\auth\ValueOneOf;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;

use function dirname;
use function strval;

/**
* Tests for auth:Value.
*
* @covers \SimpleSAML\WSSecurity\XML\auth\ValueOneOf
* @covers \SimpleSAML\WSSecurity\XML\auth\AbstractConstrainedManyValueType
* @covers \SimpleSAML\WSSecurity\XML\auth\AbstractAuthElement
* @package tvdijen/ws-security
*/
final class ValueOneOfTest extends TestCase
{
use SerializableElementTestTrait;


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

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


// test marshalling


/**
* Test creating a ValueOneOf object from scratch.
*/
public function testMarshalling(): void
{
$value1 = new Value('MyValue');
$value2 = new Value('MyOtherValue');
$valueOneOf = new ValueOneOf([$value1, $value2]);

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($valueOneOf),
);
}


// test unmarshalling


/**
* Test creating a ValueOneOf from XML.
*/
public function testUnmarshalling(): void
{
$valueOneOf = ValueOneOf::fromXML(self::$xmlRepresentation->documentElement);
$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($valueOneOf),
);
}
}
10 changes: 10 additions & 0 deletions tests/resources/xml/auth_ValueInRangen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<auth:ValueInRangen xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706">
<auth:ValueUpperBound>
<auth:StructuredValue xmlns:ssp="urn:x-simplesamlphp:namespace" ssp:attr1="testval1">
<ssp:Chunk>SomeChunk</ssp:Chunk>
</auth:StructuredValue>
</auth:ValueUpperBound>
<auth:ValueLowerBound>
<auth:Value>MyValue</auth:Value>
</auth:ValueLowerBound>
</auth:ValueInRangen>
4 changes: 4 additions & 0 deletions tests/resources/xml/auth_ValueOneOf.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<auth:ValueOneOf xmlns:auth="http://docs.oasis-open.org/wsfed/authorization/200706">
<auth:Value>MyValue</auth:Value>
<auth:Value>MyOtherValue</auth:Value>
</auth:ValueOneOf>

0 comments on commit efbe300

Please sign in to comment.