From c9a1f109567865735d84e5b977d44745ff5477e4 Mon Sep 17 00:00:00 2001 From: Bas Date: Thu, 16 Jan 2025 14:55:40 +0100 Subject: [PATCH] Make forget command idempotent --- src/Surfnet/Stepup/Identity/Identity.php | 2 -- .../RightToBeForgottenCommandHandlerTest.php | 15 ++++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Surfnet/Stepup/Identity/Identity.php b/src/Surfnet/Stepup/Identity/Identity.php index f84a0baed..4a16fb80c 100644 --- a/src/Surfnet/Stepup/Identity/Identity.php +++ b/src/Surfnet/Stepup/Identity/Identity.php @@ -1003,8 +1003,6 @@ public function expressPreferredLocale(Locale $preferredLocale): void public function forget(): void { - $this->assertNotForgotten(); - if ($this->registrationAuthorities->count() !== 0) { throw new DomainException('Cannot forget an identity that is currently accredited as an RA(A)'); } diff --git a/src/Surfnet/StepupMiddleware/CommandHandlingBundle/Tests/Identity/CommandHandler/RightToBeForgottenCommandHandlerTest.php b/src/Surfnet/StepupMiddleware/CommandHandlingBundle/Tests/Identity/CommandHandler/RightToBeForgottenCommandHandlerTest.php index 039117b0e..fef449cc0 100644 --- a/src/Surfnet/StepupMiddleware/CommandHandlingBundle/Tests/Identity/CommandHandler/RightToBeForgottenCommandHandlerTest.php +++ b/src/Surfnet/StepupMiddleware/CommandHandlingBundle/Tests/Identity/CommandHandler/RightToBeForgottenCommandHandlerTest.php @@ -160,11 +160,8 @@ public function an_identity_can_be_forgotten(): void * @group command-handler * @group sensitive-data */ - public function an_identity_may_not_be_forgotten_twice(): void + public function an_identity_may_be_forgotten_twice(): void { - $this->expectExceptionMessage("Operation on this Identity is not allowed: it has been forgotten"); - $this->expectException(DomainException::class); - $identityId = new IdentityId('A'); $institution = new Institution('Helsingin Yliopisto'); $nameId = new NameId('urn:eeva-kuopio'); @@ -178,6 +175,11 @@ public function an_identity_may_not_be_forgotten_twice(): void ->with(new IsEqual($nameId), new IsEqual($institution)) ->andReturn($this->createIdentity($identityId->getIdentityId())); + $this->sensitiveDataService + ->shouldReceive('forgetSensitiveData') + ->once() + ->with(new IsEqual($identityId)); + $this->sraaRepository->shouldReceive('contains')->once()->with(new IsEqual($nameId))->andReturn(false); $command = new ForgetIdentityCommand(); @@ -207,7 +209,10 @@ public function an_identity_may_not_be_forgotten_twice(): void ), new IdentityForgottenEvent($identityId, $institution), ]) - ->when($command); + ->when($command) + ->then([ + new IdentityForgottenEvent($identityId, $institution), + ]); } /**