Skip to content

Commit 3abdc69

Browse files
committed
Add test to verify the old hashing method stays consistent
1 parent 8302df2 commit 3abdc69

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/unit/OpenConext/EngineBlock/Service/Consent/ConsentHashServiceTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,31 @@ public function test_unstable_attribute_hash_key_order_normalized_in_names_only_
8282
$this->chs->getUnstableAttributesHash($reversed, false)
8383
);
8484
}
85+
86+
/**
87+
* Ensure the 'old' consent hash produces a manually verified hash
88+
* (if the old hash algorithm is accidentally changed, this test fails)
89+
*/
90+
public function test_unstable_hash_golden_values_must_never_change(): void
91+
{
92+
$attributes = [
93+
'urn:mace:dir:attribute-def:uid' => ['joe-f12'],
94+
'urn:mace:dir:attribute-def:displayName' => ['John Doe'],
95+
'urn:mace:dir:attribute-def:mail' => ['joe@example.org'],
96+
];
97+
98+
// Algorithm: sort(array_keys($attributes)), sha1(implode('|', ...))
99+
$this->assertSame(
100+
'65d6f8f1f7064a70921882e3840e807e1d14e535',
101+
$this->chs->getUnstableAttributesHash($attributes, false),
102+
'Unstable names-only hash must never change — existing DB rows depend on it'
103+
);
104+
105+
// Algorithm: ksort($attributes), sha1(serialize(...))
106+
$this->assertSame(
107+
'c4861f8908bd9311ea8e11df579a8ecb14c7ac66',
108+
$this->chs->getUnstableAttributesHash($attributes, true),
109+
'Unstable with-values hash must never change — existing DB rows depend on it'
110+
);
111+
}
85112
}

0 commit comments

Comments
 (0)