Skip to content

Commit 5c34f92

Browse files
committed
Fix namespaced IncludeToken-attribute (both sp-versions and coverage)
1 parent e9db8a0 commit 5c34f92

23 files changed

Lines changed: 260 additions & 4 deletions

src/XML/sp_200507/Type/IncludeTokenValue.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,35 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\Type;
66

7+
use SimpleSAML\Assert\Assert;
78
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\AbstractSpElement;
89
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200507\IncludeToken;
910
use SimpleSAML\XML\Attribute as XMLAttribute;
10-
use SimpleSAML\XMLSchema\Type\AnyURIValue as BaseAnyURIValue;
11+
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13+
14+
use function array_column;
1115

1216
/**
1317
* @package simplesaml/xml-ws-security-policy
1418
*/
15-
class IncludeTokenValue extends BaseAnyURIValue
19+
class IncludeTokenValue extends AnyURIValue
1620
{
21+
/**
22+
* Validate the value.
23+
*
24+
* @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
25+
*/
26+
protected function validateValue(string $value): void
27+
{
28+
Assert::oneOf(
29+
$this->sanitizeValue($value),
30+
array_column(IncludeToken::cases(), 'value'),
31+
SchemaViolationException::class,
32+
);
33+
}
34+
35+
1736
/**
1837
* Convert this value to an attribute
1938
*

src/XML/sp_200702/AbstractIssuedTokenType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ abstract class AbstractIssuedTokenType extends AbstractSpElement
2525
{
2626
use ExtendableAttributesTrait;
2727
use ExtendableElementTrait;
28+
use IncludeTokenTypeTrait;
2829

2930

3031
/** The namespace-attribute for the xs:any element */
@@ -54,6 +55,7 @@ final public function __construct(
5455
array $elts = [],
5556
array $namespacedAttributes = [],
5657
) {
58+
$this->setIncludeToken($namespacedAttributes);
5759
$this->setElements($elts);
5860
$this->setAttributesNS($namespacedAttributes);
5961
}

src/XML/sp_200702/AbstractKeyValueTokenType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ abstract class AbstractKeyValueTokenType extends AbstractSpElement
2222
{
2323
use ExtendableAttributesTrait;
2424
use ExtendableElementTrait;
25+
use IncludeTokenTypeTrait;
2526

2627

2728
/** The namespace-attribute for the xs:any element */
@@ -41,6 +42,7 @@ final public function __construct(
4142
array $elts = [],
4243
array $namespacedAttributes = [],
4344
) {
45+
$this->setIncludeToken($namespacedAttributes);
4446
$this->setElements($elts);
4547
$this->setAttributesNS($namespacedAttributes);
4648
}

src/XML/sp_200702/AbstractSecureConversationTokenType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class AbstractSecureConversationTokenType extends AbstractSpElement
2323
{
2424
use ExtendableAttributesTrait;
2525
use ExtendableElementTrait;
26+
use IncludeTokenTypeTrait;
2627

2728

2829
/** The namespace-attribute for the xs:any element */
@@ -48,6 +49,7 @@ final public function __construct(
4849
array $elts = [],
4950
array $namespacedAttributes = [],
5051
) {
52+
$this->setIncludeToken($namespacedAttributes);
5153
$this->setElements($elts);
5254
$this->setAttributesNS($namespacedAttributes);
5355
}

src/XML/sp_200702/AbstractSpnegoContextTokenType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class AbstractSpnegoContextTokenType extends AbstractSpElement
2323
{
2424
use ExtendableAttributesTrait;
2525
use ExtendableElementTrait;
26+
use IncludeTokenTypeTrait;
2627

2728

2829
/** The namespace-attribute for the xs:any element */
@@ -48,6 +49,7 @@ final public function __construct(
4849
array $elts = [],
4950
array $namespacedAttributes = [],
5051
) {
52+
$this->setIncludeToken($namespacedAttributes);
5153
$this->setElements($elts);
5254
$this->setAttributesNS($namespacedAttributes);
5355
}

src/XML/sp_200702/AbstractTokenAssertionType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ abstract class AbstractTokenAssertionType extends AbstractSpElement
2222
{
2323
use ExtendableAttributesTrait;
2424
use ExtendableElementTrait;
25+
use IncludeTokenTypeTrait;
2526

2627

2728
/** The namespace-attribute for the xs:any element */
@@ -41,6 +42,7 @@ final public function __construct(
4142
array $elts = [],
4243
array $namespacedAttributes = [],
4344
) {
45+
$this->setIncludeToken($namespacedAttributes);
4446
$this->setElements($elts);
4547
$this->setAttributesNS($namespacedAttributes);
4648
}

src/XML/sp_200702/Type/IncludeTokenValue.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,33 @@
44

55
namespace SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\Type;
66

7+
use SimpleSAML\Assert\Assert;
78
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\AbstractSpElement;
89
use SimpleSAML\WebServices\SecurityPolicy\XML\sp_200702\IncludeToken;
910
use SimpleSAML\XML\Attribute as XMLAttribute;
10-
use SimpleSAML\XMLSchema\Type\AnyURIValue as BaseAnyURIValue;
11+
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
12+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
1113

1214
/**
1315
* @package simplesaml/xml-ws-security-policy
1416
*/
15-
class IncludeTokenValue extends BaseAnyURIValue
17+
class IncludeTokenValue extends AnyURIValue
1618
{
19+
/**
20+
* Validate the value.
21+
*
22+
* @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
23+
*/
24+
protected function validateValue(string $value): void
25+
{
26+
Assert::oneOf(
27+
$this->sanitizeValue($value),
28+
array_column(IncludeToken::cases(), 'value'),
29+
SchemaViolationException::class,
30+
);
31+
}
32+
33+
1734
/**
1835
* Convert this value to an attribute
1936
*

tests/SecurityPolicy/XML/sp_200507/IssuedTokenTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,8 @@ public function testMarshalling(): void
193193
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
194194
strval($issuedToken),
195195
);
196+
197+
$this->assertFalse($issuedToken->isEmptyElement());
198+
$this->assertEquals($issuedToken->getIncludeToken(), IncludeTokenValue::fromEnum(IncludeToken::Always));
196199
}
197200
}

tests/SecurityPolicy/XML/sp_200507/SecureConversationTokenTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,11 @@ public function testMarshalling(): void
181181
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
182182
strval($secureConversationToken),
183183
);
184+
185+
$this->assertFalse($secureConversationToken->isEmptyElement());
186+
$this->assertEquals(
187+
$secureConversationToken->getIncludeToken(),
188+
IncludeTokenValue::fromEnum(IncludeToken::Always),
189+
);
184190
}
185191
}

tests/SecurityPolicy/XML/sp_200507/SpnegoContextTokenTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,8 @@ public function testMarshalling(): void
181181
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
182182
strval($spnegoContextToken),
183183
);
184+
185+
$this->assertFalse($spnegoContextToken->isEmptyElement());
186+
$this->assertEquals($spnegoContextToken->getIncludeToken(), IncludeTokenValue::fromEnum(IncludeToken::Always));
184187
}
185188
}

0 commit comments

Comments
 (0)