Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uml 1533 hashing logged email #2460

Merged
merged 13 commits into from
Dec 19, 2023
8 changes: 8 additions & 0 deletions service-api/.idea/.gitignore
Lbagg1 marked this conversation as resolved.
Show resolved Hide resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions service-api/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions service-api/.idea/service-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions service-api/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions service-api/app/src/App/src/Service/Log/Output/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Service\Log\Output;

use function hash;

class Email
{
public function __construct(private string $email)
{
}

public function __toString(): string
{
$hash = hash('sha256', $this->email);
return sprintf($hash);
}
}
2 changes: 1 addition & 1 deletion service-api/app/src/App/src/Service/User/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
} catch (Exception $e) {
$this->logger->notice(
'Attempt made to reset password for non-existent account',
['email' => $email]
['email' => new Email($email)]

Check warning on line 193 in service-api/app/src/App/src/Service/User/UserService.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/User/UserService.php#L193

Added line #L193 was not covered by tests
Lbagg1 marked this conversation as resolved.
Show resolved Hide resolved
);

throw $e;
Expand Down
19 changes: 19 additions & 0 deletions service-api/app/test/AppTest/Service/Log/Output/EmailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace AppTest\Service\Log\Output;

use App\Service\Log\Output\Email;
use PHPUnit\Framework\TestCase;

class EmailTest extends TestCase
{
/** @test */
public function it_hides_a_string()
{
$email = new Email('[email protected]');
$this->assertMatchesRegularExpression('/.*/', (string)$email);
$this->assertStringNotContainsString('[email protected]', (string)$email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function authenticate(string $credential, ?string $password = null): ?Use
'Authentication failed for {email} with code {code}',
[
'code' => $e->getCode(),
'email' => $credential,
'email' =>new Email($credential),
]
);
if ($e->getCode() === StatusCodeInterface::STATUS_UNAUTHORIZED) {
Expand Down
Loading