Skip to content
Snippets Groups Projects
Unverified Commit 552f93f6 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #858 from mschwager/master

Fix #828, infinite loop in AttributeMap behavior
parents 31442318 fa4d12bb
No related branches found
No related tags found
No related merge requests found
...@@ -115,24 +115,28 @@ class sspmod_core_Auth_Process_AttributeMap extends SimpleSAML_Auth_ProcessingFi ...@@ -115,24 +115,28 @@ class sspmod_core_Auth_Process_AttributeMap extends SimpleSAML_Auth_ProcessingFi
assert(is_array($request)); assert(is_array($request));
assert(array_key_exists('Attributes', $request)); assert(array_key_exists('Attributes', $request));
$attributes =& $request['Attributes']; $mapped_attributes = array();
foreach ($attributes as $name => $values) { foreach ($request['Attributes'] as $name => $values) {
if (array_key_exists($name, $this->map)) { if (array_key_exists($name, $this->map)) {
if (!is_array($this->map[$name])) { if (!is_array($this->map[$name])) {
if (!$this->duplicate) { if ($this->duplicate) {
unset($attributes[$name]); $mapped_attributes[$name] = $values;
} }
$attributes[$this->map[$name]] = $values; $mapped_attributes[$this->map[$name]] = $values;
} else { } else {
foreach ($this->map[$name] as $to_map) { foreach ($this->map[$name] as $to_map) {
$attributes[$to_map] = $values; $mapped_attributes[$to_map] = $values;
} }
if (!$this->duplicate && !in_array($name, $this->map[$name], true)) { if ($this->duplicate && !in_array($name, $this->map[$name], true)) {
unset($attributes[$name]); $mapped_attributes[$name] = $values;
} }
} }
} else {
$mapped_attributes[$name] = $values;
} }
} }
$request['Attributes'] = $mapped_attributes;
} }
} }
...@@ -108,6 +108,51 @@ class Test_Core_Auth_Process_AttributeMap extends TestCase ...@@ -108,6 +108,51 @@ class Test_Core_Auth_Process_AttributeMap extends TestCase
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }
public function testCircular()
{
$config = [
'attribute1' => 'attribute1',
'attribute2' => 'attribute2',
];
$request = [
'Attributes' => [
'attribute1' => ['value'],
'attribute2' => ['value'],
],
];
$processed = self::processFilter($config, $request);
$result = $processed['Attributes'];
$expected = [
'attribute1' => ['value'],
'attribute2' => ['value'],
];
$this->assertEquals($expected, $result);
}
public function testMissingMap()
{
$config = [
'attribute1' => 'attribute3',
];
$request = [
'Attributes' => [
'attribute1' => ['value'],
'attribute2' => ['value'],
],
];
$processed = self::processFilter($config, $request);
$result = $processed['Attributes'];
$expected = [
'attribute2' => ['value'],
'attribute3' => ['value'],
];
$this->assertEquals($expected, $result);
}
public function testInvalidOriginalAttributeType() public function testInvalidOriginalAttributeType()
{ {
$config = [ $config = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment