2727use OpenConext \EngineBlock \Metadata \Entity \ServiceProvider ;
2828use OpenConext \EngineBlock \Service \Consent \ConsentHashService ;
2929use OpenConext \EngineBlockBundle \Authentication \Repository \DbalConsentRepository ;
30- use OpenConext \EngineBlockBundle \Configuration \FeatureConfiguration ;
3130use PHPUnit \Framework \Attributes \DataProvider ;
3231use PHPUnit \Framework \TestCase ;
3332
@@ -58,19 +57,7 @@ public function setup(): void
5857 $ this ->response = Mockery::mock (EngineBlock_Saml2_ResponseAnnotationDecorator::class);
5958 $ this ->consentRepository = Mockery::mock (ConsentRepository::class);
6059
61- $ this ->buildConsentAndService (migrationEnabled: true );
62- }
63-
64- /**
65- * Rebuilds $this->consentService and $this->consent with the given toggle state.
66- * Call this in tests that need a specific toggle setting different from setUp's default.
67- */
68- private function buildConsentAndService (bool $ migrationEnabled ): void
69- {
70- $ featureConfig = new FeatureConfiguration ([
71- 'eb.stable_consent_hash_migration ' => $ migrationEnabled ,
72- ]);
73- $ this ->consentService = new ConsentHashService ($ this ->consentRepository , $ featureConfig );
60+ $ this ->consentService = new ConsentHashService ($ this ->consentRepository );
7461 $ this ->consent = new EngineBlock_Corto_Model_Consent (
7562 true ,
7663 $ this ->response ,
@@ -164,49 +151,13 @@ public function test_stable_consent_given($consentType)
164151 }
165152
166153 /**
167- * Toggle ON (migration enabled): new consent stores only the stable hash.
168- * The legacy attribute column must be left NULL so fully-migrated deployments
169- * don't accumulate unnecessary data in the old column .
154+ * New consent always stores both the stable and legacy hashes so that old
155+ * instances can still find the consent record during a rolling deploy, and
156+ * so the legacy column is never wiped prematurely .
170157 */
171158 #[DataProvider('consentTypeProvider ' )]
172- public function test_give_consent_toggle_on_stores_only_stable_hash ($ consentType )
159+ public function test_give_consent_stores_both_hashes ($ consentType )
173160 {
174- // setUp already builds with migrationEnabled=true
175- $ serviceProvider = new ServiceProvider ("service-provider-entity-id " );
176- $ this ->response ->shouldReceive ('getNameIdValue ' )
177- ->once ()
178- ->andReturn ('collab:person:id:org-a:joe-a ' );
179- $ this ->consentRepository
180- ->shouldReceive ('storeConsentHash ' )
181- ->once ()
182- ->with (new ConsentStoreParameters (
183- hashedUserId: '0e54805079c56c2b1c1197a760af86ac337b7bac ' ,
184- serviceId: 'service-provider-entity-id ' ,
185- attributeStableHash: '8739602554c7f3241958e3cc9b57fdecb474d508 ' ,
186- consentType: $ consentType ->value ,
187- attributeHash: null ,
188- ))
189- ->andReturn (true );
190-
191- switch ($ consentType ) {
192- case ConsentType::Explicit:
193- $ this ->assertTrue ($ this ->consent ->giveExplicitConsentFor ($ serviceProvider ));
194- break ;
195- case ConsentType::Implicit:
196- $ this ->assertTrue ($ this ->consent ->giveImplicitConsentFor ($ serviceProvider ));
197- break ;
198- }
199- }
200-
201- /**
202- * Toggle OFF (migration disabled): new consent stores BOTH hashes so that
203- * old EB instances (still reading only the `attribute` column) can still
204- * find the consent record during a rolling deploy.
205- */
206- #[DataProvider('consentTypeProvider ' )]
207- public function test_give_consent_toggle_off_stores_both_hashes ($ consentType )
208- {
209- $ this ->buildConsentAndService (migrationEnabled: false );
210161 $ serviceProvider = new ServiceProvider ("service-provider-entity-id " );
211162 $ this ->response ->shouldReceive ('getNameIdValue ' )
212163 ->once ()
@@ -234,41 +185,12 @@ public function test_give_consent_toggle_off_stores_both_hashes($consentType)
234185 }
235186
236187 /**
237- * Toggle OFF (migration disabled): upgrading an old unstable consent leaves
238- * the legacy `attribute` column intact so old instances keep working.
239- */
240- #[DataProvider('consentTypeProvider ' )]
241- public function test_upgrade_toggle_off_preserves_legacy_hash ($ consentType )
242- {
243- $ this ->buildConsentAndService (migrationEnabled: false );
244- $ serviceProvider = new ServiceProvider ("service-provider-entity-id " );
245- $ this ->response ->shouldReceive ('getNameIdValue ' )
246- ->once ()
247- ->andReturn ('collab:person:id:org-a:joe-a ' );
248- $ this ->consentRepository
249- ->shouldReceive ('updateConsentHash ' )
250- ->once ()
251- ->with (new ConsentUpdateParameters (
252- attributeStableHash: '8739602554c7f3241958e3cc9b57fdecb474d508 ' ,
253- attributeHash: '8739602554c7f3241958e3cc9b57fdecb474d508 ' ,
254- hashedUserId: '0e54805079c56c2b1c1197a760af86ac337b7bac ' ,
255- serviceId: 'service-provider-entity-id ' ,
256- consentType: $ consentType ->value ,
257- clearLegacyHash: false ,
258- ))
259- ->andReturn (true );
260-
261- $ this ->assertNull ($ this ->consent ->upgradeAttributeHashFor ($ serviceProvider , $ consentType , ConsentVersion::Unstable));
262- }
263-
264- /**
265- * Toggle ON (migration enabled): upgrading an old unstable consent nulls the
266- * legacy `attribute` column so the old column is cleaned up over time.
188+ * Upgrading an unstable consent always preserves the legacy `attribute` column
189+ * so that old instances keep working during a rolling deploy.
267190 */
268191 #[DataProvider('consentTypeProvider ' )]
269- public function test_upgrade_toggle_on_clears_legacy_hash ($ consentType )
192+ public function test_upgrade_preserves_legacy_hash ($ consentType )
270193 {
271- // setUp already builds with migrationEnabled=true
272194 $ serviceProvider = new ServiceProvider ("service-provider-entity-id " );
273195 $ this ->response ->shouldReceive ('getNameIdValue ' )
274196 ->once ()
@@ -282,7 +204,6 @@ public function test_upgrade_toggle_on_clears_legacy_hash($consentType)
282204 hashedUserId: '0e54805079c56c2b1c1197a760af86ac337b7bac ' ,
283205 serviceId: 'service-provider-entity-id ' ,
284206 consentType: $ consentType ->value ,
285- clearLegacyHash: true ,
286207 ))
287208 ->andReturn (true );
288209
0 commit comments