Skip to content

Commit

Permalink
added test for UserService logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Lbagg1 committed Dec 19, 2023
1 parent 92a2b42 commit 9e00a9a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions service-api/app/src/App/src/Service/Log/Output/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function __construct(private string $email)

public function __toString(): string
{
$hash = hash('sha256', $this->email);
return sprintf($hash);
return hash('sha256', $this->email);
}
}
31 changes: 31 additions & 0 deletions service-api/app/test/AppTest/Service/User/UserServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Exception\GoneException;
use App\Exception\NotFoundException;
use App\Exception\UnauthorizedException;
use App\Service\Log\Output\Email;
use App\Service\User\UserService;
use DateTime;
use Exception;
Expand Down Expand Up @@ -189,6 +190,36 @@ public function cannot_add_existing_user_as_email_used_in_reset()
$us->add($userData);
}

/** @test */
public function logsNoticeWhenPasswordResetIsRequestedForNonExistentAccount(): void
{
$email = '[email protected]';
$hashed_email = hash('sha256', $email);

$repoProphecy = $this->prophesize(ActorUsersInterface::class);
$loggerProphecy = $this->prophesize(LoggerInterface::class);

$repoProphecy
->recordPasswordResetRequest(Argument::cetera())
->willThrow(Exception::class);

$loggerProphecy
->notice(
'Attempt made to reset password for non-existent account',
Argument::that(function ($arg) use ($hashed_email) {
return $arg['email'] instanceof Email && (string)($arg['email']) == $hashed_email;
})
)
->shouldBeCalled();

$userService = new UserService($repoProphecy->reveal(), $loggerProphecy->reveal());

try {
$userService->requestPasswordReset($email);
} catch (Exception) {
}
}

/** @test */
public function can_get_a_user_from_storage(): void
{
Expand Down

0 comments on commit 9e00a9a

Please sign in to comment.