Skip to content

Commit 59575a0

Browse files
committed
Assert that all attribute values have the same type
1 parent adabfe4 commit 59575a0

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/XML/saml/Attribute.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
1919
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
2020

21+
use function array_unique;
22+
use function count;
2123
use function strval;
2224

2325
/**
@@ -65,7 +67,7 @@ public function __construct(
6567
array $namespacedAttribute = [],
6668
) {
6769
Assert::maxCount($attributeValue, C::UNBOUNDED_LIMIT);
68-
Assert::allIsInstanceOf($attributeValue, AttributeValue::class, 'Invalid AttributeValue.');
70+
Assert::allIsInstanceOf($attributeValue, AttributeValue::class, InvalidDOMElementException::class);
6971

7072
switch (strval($nameFormat)) {
7173
case C::NAMEFORMAT_URI:
@@ -82,6 +84,22 @@ public function __construct(
8284
break;
8385
}
8486

87+
$types = array_map(
88+
function(AttributeValue $av) {
89+
return $av->getXsiType();
90+
},
91+
$attributeValue,
92+
);
93+
94+
if ($types !== []) {
95+
Assert::same(
96+
count(array_unique($types)),
97+
1,
98+
"All of the <AttributeValue> elements must have the identical datatype assigned.",
99+
ProtocolViolationException::class,
100+
);
101+
}
102+
85103
$this->setAttributesNS($namespacedAttribute);
86104
}
87105

tests/SAML2/XML/saml/AttributeTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ public function testMarshalling(): void
9393
[
9494
new AttributeValue(StringValue::fromString('FirstValue')),
9595
new AttributeValue(StringValue::fromString('SecondValue')),
96-
new AttributeValue(IntegerValue::fromInteger(3)),
97-
new AttributeValue(DateTimeValue::fromString('2024-04-04T04:44:44Z')),
98-
new AttributeValue(null),
9996
],
10097
[$attr1, $attr2],
10198
);
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
<saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:test="urn:test:something" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" Name="TheName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" FriendlyName="TheFriendlyName" test:attr1="testval1" test:attr2="testval2">
1+
<saml:Attribute xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:test="urn:test:something" Name="TheName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" FriendlyName="TheFriendlyName" test:attr1="testval1" test:attr2="testval2">
22
<saml:AttributeValue>FirstValue</saml:AttributeValue>
33
<saml:AttributeValue>SecondValue</saml:AttributeValue>
4-
<saml:AttributeValue xsi:type="xs:integer">3</saml:AttributeValue>
5-
<saml:AttributeValue xsi:type="xs:dateTime">2024-04-04T04:44:44Z</saml:AttributeValue>
6-
<saml:AttributeValue xsi:nil="1"/>
74
</saml:Attribute>

0 commit comments

Comments
 (0)