Skip to content
Snippets Groups Projects
Unverified Commit 38141030 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Merge pull request #1423 from simplesamlphp/undocumented-feature-tags

Remove undocumented feature of Extension with 'tags' attribute
parents 67ca9cc5 28390bb5
Branches
Tags
No related merge requests found
......@@ -168,15 +168,6 @@ class SAMLBuilder
*/
private function addExtensions(Configuration $metadata, RoleDescriptor $e): void
{
if ($metadata->hasValue('tags')) {
$a = new Attribute();
$a->setName('tags');
foreach ($metadata->getArray('tags') as $tag) {
$a->addAttributeValue(new AttributeValue($tag));
}
$e->setExtensions(array_merge($e->getExtensions(), [$a]));
}
if ($metadata->hasValue('hint.cidr')) {
$a = new Attribute();
$a->setName('hint.cidr');
......
......@@ -147,11 +147,6 @@ class SAMLParser
*/
private array $registrationInfo;
/**
* @var array
*/
private array $tags;
/**
* This is an array of elements that may be used to validate this element.
*
......@@ -198,7 +193,6 @@ class SAMLParser
// process Extensions element, if it exists
$ext = self::processExtensions($entityElement, $parentExtensions);
$this->scopes = $ext['scope'];
$this->tags = $ext['tags'];
$this->entityAttributes = $ext['EntityAttributes'];
$this->registrationInfo = $ext['RegistrationInfo'];
......@@ -494,19 +488,12 @@ class SAMLParser
private function addExtensions(array &$metadata, array $roleDescriptor): void
{
Assert::keyExists($roleDescriptor, 'scope');
Assert::keyExists($roleDescriptor, 'tags');
$scopes = array_merge($this->scopes, array_diff($roleDescriptor['scope'], $this->scopes));
if (!empty($scopes)) {
$metadata['scope'] = $scopes;
}
$tags = array_merge($this->tags, array_diff($roleDescriptor['tags'], $this->tags));
if (!empty($tags)) {
$metadata['tags'] = $tags;
}
if (!empty($this->registrationInfo)) {
$metadata['RegistrationInfo'] = $this->registrationInfo;
}
......@@ -749,7 +736,6 @@ class SAMLParser
$ext = self::processExtensions($element);
$ret['scope'] = $ext['scope'];
$ret['tags'] = $ext['tags'];
$ret['EntityAttributes'] = $ext['EntityAttributes'];
$ret['UIInfo'] = $ext['UIInfo'];
$ret['DiscoHints'] = $ext['DiscoHints'];
......@@ -888,7 +874,6 @@ class SAMLParser
{
$ret = [
'scope' => [],
'tags' => [],
'EntityAttributes' => [],
'RegistrationInfo' => [],
'UIInfo' => [],
......@@ -1003,29 +988,6 @@ class SAMLParser
$ret['DiscoHints']['GeolocationHint'] = $e->getGeolocationHint();
}
}
if (!($e instanceof Chunk)) {
continue;
}
if ($e->getLocalName() === 'Attribute' && $e->getNamespaceURI() === Constants::NS_SAML) {
$attribute = $e->getXML();
$name = $attribute->getAttribute('Name');
$xmlUtils = new Utils\XML();
$values = array_map(
[$xmlUtils, 'getDOMText'],
$xmlUtils->getDOMChildren($attribute, 'AttributeValue', '@saml2')
);
if ($name === 'tags') {
foreach ($values as $tagname) {
if (!empty($tagname)) {
$ret['tags'][] = $tagname;
}
}
}
}
}
return $ret;
}
......
......@@ -258,71 +258,6 @@ class XML
}
/**
* This function finds direct descendants of a DOM element with the specified
* localName and namespace. They are returned in an array.
*
* This function accepts the same shortcuts for namespaces as the isDOMNodeOfType function.
*
* @param \DOMNode $element The element we should look in.
* @param string $localName The name the element should have.
* @param string $namespaceURI The namespace the element should have.
*
* @return array Array with the matching elements in the order they are found. An empty array is
* returned if no elements match.
* @throws \InvalidArgumentException If $element is not an instance of DOMElement, $localName is not a string or
* $namespaceURI is not a string.
*/
public function getDOMChildren(DOMNode $element, string $localName, string $namespaceURI): array
{
$ret = [];
for ($i = 0; $i < $element->childNodes->length; $i++) {
/** @var \DOMNode $child */
$child = $element->childNodes->item($i);
// skip text nodes and comment elements
if ($child instanceof DOMText || $child instanceof DOMComment) {
continue;
}
if ($this->isDOMNodeOfType($child, $localName, $namespaceURI) === true) {
$ret[] = $child;
}
}
return $ret;
}
/**
* This function extracts the text from DOMElements which should contain only text content.
*
* @param \DOMElement $element The element we should extract text from.
*
* @return string The text content of the element.
* @throws \SimpleSAML\Error\Exception If the element contains a non-text child node.
*
*/
public function getDOMText(DOMElement $element): string
{
$txt = '';
for ($i = 0; $i < $element->childNodes->length; $i++) {
/** @var \DOMElement $child */
$child = $element->childNodes->item($i);
if (!($child instanceof DOMText)) {
throw new Error\Exception($element->localName . ' contained a non-text child node.');
}
$txt .= $child->wholeText;
}
$txt = trim($txt);
return $txt;
}
/**
* This function checks if the DOMElement has the correct localName and namespaceURI.
*
......
......@@ -128,121 +128,6 @@ class XMLTest extends TestCase
}
/**
* @test
*/
public function testGetDomTextBasic(): void
{
$xmlUtils = new Utils\XML();
$data = 'root value';
$dom = new DOMDocument();
$element = $dom->appendChild(new \DOMElement('root'));
$element->appendChild(new DOMText($data));
$res = $xmlUtils->getDOMText($element);
$expected = $data;
$this->assertEquals($expected, $res);
}
/**
* @test
*/
public function testGetDomTextMulti(): void
{
$xmlUtils = new Utils\XML();
$data1 = 'root value 1';
$data2 = 'root value 2';
$dom = new DOMDocument();
$element = $dom->appendChild(new DOMElement('root'));
$element->appendChild(new DOMText($data1));
$element->appendChild(new DOMText($data2));
$res = $xmlUtils->getDOMText($element);
$expected = $data1 . $data2 . $data1 . $data2;
$this->assertEquals($expected, $res);
}
/**
* @test
*/
public function testGetDomTextIncorrectType(): void
{
$xmlUtils = new Utils\XML();
$this->expectException(Error\Exception::class);
$dom = new DOMDocument();
$element = $dom->appendChild(new DOMElement('root'));
$element->appendChild(new DOMComment(''));
$xmlUtils->getDOMText($element);
}
/**
* @test
*/
public function testGetDomChildrenBasic(): void
{
$xmlUtils = new Utils\XML();
$name = 'name';
$namespace_uri = 'ns';
$dom = new DOMDocument();
$element = new DOMElement($name, 'value', $namespace_uri);
$dom->appendChild($element);
$res = $xmlUtils->getDOMChildren($dom, $name, $namespace_uri);
$expected = [$element];
$this->assertEquals($expected, $res);
}
/**
* @test
*/
public function testGetDomChildrenIncorrectType(): void
{
$xmlUtils = new Utils\XML();
$dom = new DOMDocument();
$text = new DOMText('text');
$comment = new DOMComment('comment');
$dom->appendChild($text);
$dom->appendChild($comment);
$res = $xmlUtils->getDOMChildren($dom, 'name', 'ns');
$this->assertEmpty($res);
}
/**
* @test
*/
public function testGetDomChildrenIncorrectName(): void
{
$xmlUtils = new Utils\XML();
$name = 'name';
$bad_name = 'bad name';
$namespace_uri = 'ns';
$dom = new DOMDocument();
$element = new DOMElement($name, 'value', $namespace_uri);
$dom->appendChild($element);
$res = $xmlUtils->getDOMChildren($dom, $bad_name, $namespace_uri);
$this->assertEmpty($res);
}
/**
* @test
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment