Skip to content
Snippets Groups Projects
Unverified Commit de8c86c2 authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo Committed by GitHub
Browse files

Merge pull request #570 from moffe42/master

Sort attribute values for consent
parents a87a0ba4 c27b0cce
No related branches found
No related tags found
No related merge requests found
......@@ -375,6 +375,9 @@ class sspmod_consent_Auth_Process_Consent extends SimpleSAML_Auth_ProcessingFilt
public static function getAttributeHash($attributes, $includeValues = false)
{
if ($includeValues) {
foreach ($attributes as &$values) {
sort($values);
}
ksort($attributes);
$hashBase = serialize($attributes);
} else {
......
......@@ -120,4 +120,63 @@ class ConsentTest extends TestCase
// the state should NOT have changed because NO consent should be necessary (match)
$this->assertEquals($request, $result);
}
public function testAttributeHashIsConsistentWhenOrderOfValuesChange()
{
$attributes1 = array(
'attribute1' => array('val1', 'val2'),
'attribute2' => array('val1', 'val2')
);
$attributeHash1 = \sspmod_consent_Auth_Process_Consent::getAttributeHash($attributes1, true);
$attributes2 = array(
'attribute1' => array('val1', 'val2'),
'attribute2' => array('val2', 'val1')
);
$attributeHash2 = \sspmod_consent_Auth_Process_Consent::getAttributeHash($attributes2, true);
$this->assertEquals($attributeHash1, $attributeHash2, "Hash is not the same when the order of values changes");
}
public function testAttributeHashIsConsistentWhenOrderOfAttributesChange()
{
$attributes1 = array(
'attribute2' => array('val1', 'val2'),
'attribute1' => array('val1', 'val2')
);
$attributeHash1 = \sspmod_consent_Auth_Process_Consent::getAttributeHash($attributes1, true);
$attributes2 = array(
'attribute1' => array('val1', 'val2'),
'attribute2' => array('val1', 'val2')
);
$attributeHash2 = \sspmod_consent_Auth_Process_Consent::getAttributeHash($attributes2, true);
$this->assertEquals(
$attributeHash1,
$attributeHash2,
"Hash is not the same when the order of the attributs changes"
);
}
public function testAttributeHashIsConsistentWithoutValuesWhenOrderOfAttributesChange()
{
$attributes1 = array(
'attribute2' => array('val1', 'val2'),
'attribute1' => array('val1', 'val2')
);
$attributeHash1 = \sspmod_consent_Auth_Process_Consent::getAttributeHash($attributes1);
$attributes2 = array(
'attribute1' => array('val1', 'val2'),
'attribute2' => array('val1', 'val2')
);
$attributeHash2 = \sspmod_consent_Auth_Process_Consent::getAttributeHash($attributes2);
$this->assertEquals(
$attributeHash1,
$attributeHash2,
"Hash is not the same when the order of the attributs changes and the values are not included"
);
}
}
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