feat: local password hashes
This commit is contained in:
1 parent
08f6633507
commit
fe562e5e73
15 files changed
+541
-253
No files matched your search
@@ -12,7 +12,6 @@ use App\BusProNet\Model\PersonalData;
|
||||
use App\Entity\User;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Security\Crypt;
|
||||
use App\Service\ParticipantDataPrefiller;
|
||||
use Carbon\CarbonImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -21,19 +20,16 @@ use Psr\Log\LoggerInterface;
|
||||
class ParticipantDataPrefillerTest extends TestCase
|
||||
{
|
||||
private ApiClient $apiClient;
|
||||
private Crypt $crypt;
|
||||
private LoggerInterface $logger;
|
||||
private ParticipantDataPrefiller $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->apiClient = $this->createMock(ApiClient::class);
|
||||
$this->crypt = $this->createMock(Crypt::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->service = new ParticipantDataPrefiller(
|
||||
$this->apiClient,
|
||||
$this->crypt,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
@@ -46,14 +42,9 @@ class ParticipantDataPrefillerTest extends TestCase
|
||||
|
||||
$personalData = $this->createCompletePersonalData();
|
||||
|
||||
$this->crypt->expects($this->once())
|
||||
->method('decrypt')
|
||||
->with('encrypted_password')
|
||||
->willReturn('decrypted_password');
|
||||
|
||||
$this->apiClient->expects($this->once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', 'decrypted_password')
|
||||
->with('[email protected]', null, null)
|
||||
->willReturn($personalData);
|
||||
|
||||
$result = $this->service->prefillApplicantFromUser($user, $applicant);
|
||||
@@ -94,12 +85,9 @@ class ParticipantDataPrefillerTest extends TestCase
|
||||
|
||||
$personalData = $this->createPartialPersonalData();
|
||||
|
||||
$this->crypt->expects($this->once())
|
||||
->method('decrypt')
|
||||
->willReturn('decrypted_password');
|
||||
|
||||
$this->apiClient->expects($this->once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', null, null)
|
||||
->willReturn($personalData);
|
||||
|
||||
$result = $this->service->prefillApplicantFromUser($user, $applicant);
|
||||
@@ -129,12 +117,9 @@ class ParticipantDataPrefillerTest extends TestCase
|
||||
|
||||
$notification = new Notification(401, 'Authentication failed');
|
||||
|
||||
$this->crypt->expects($this->once())
|
||||
->method('decrypt')
|
||||
->willReturn('decrypted_password');
|
||||
|
||||
$this->apiClient->expects($this->once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', null, null)
|
||||
->willReturn($notification);
|
||||
|
||||
$this->logger->expects($this->once())
|
||||
@@ -156,46 +141,15 @@ class ParticipantDataPrefillerTest extends TestCase
|
||||
$this->assertNull($result->email);
|
||||
}
|
||||
|
||||
public function testPrepopulateApplicantWithDecryptionException(): void
|
||||
{
|
||||
$user = $this->createUser('[email protected]', 'encrypted_password');
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
|
||||
$this->crypt->expects($this->once())
|
||||
->method('decrypt')
|
||||
->willThrowException(new \RuntimeException('Decryption failed'));
|
||||
|
||||
$this->apiClient->expects($this->never())
|
||||
->method('getPersonalData');
|
||||
|
||||
$this->logger->expects($this->once())
|
||||
->method('error')
|
||||
->with('Exception during applicant prepopulation', [
|
||||
'error' => 'Decryption failed',
|
||||
'email' => '[email protected]',
|
||||
]);
|
||||
|
||||
$result = $this->service->prefillApplicantFromUser($user, $applicant);
|
||||
|
||||
// Should return unchanged applicant
|
||||
$this->assertNull($result->firstName);
|
||||
$this->assertNull($result->lastName);
|
||||
$this->assertNull($result->email);
|
||||
}
|
||||
|
||||
public function testPrepopulateApplicantWithApiException(): void
|
||||
{
|
||||
$user = $this->createUser('[email protected]', 'encrypted_password');
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
|
||||
$this->crypt->expects($this->once())
|
||||
->method('decrypt')
|
||||
->willReturn('decrypted_password');
|
||||
|
||||
$this->apiClient->expects($this->once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', null, null)
|
||||
->willThrowException(new \RuntimeException('API connection failed'));
|
||||
|
||||
$this->logger->expects($this->once())
|
||||
@@ -223,12 +177,9 @@ class ParticipantDataPrefillerTest extends TestCase
|
||||
|
||||
$personalData = $this->createCompletePersonalData();
|
||||
|
||||
$this->crypt->expects($this->once())
|
||||
->method('decrypt')
|
||||
->willReturn('decrypted_password');
|
||||
|
||||
$this->apiClient->expects($this->once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', null, null)
|
||||
->willReturn($personalData);
|
||||
|
||||
$result = $this->service->prefillApplicantFromUser($user, $applicant);
|
||||
|
||||
Reference in new issue
Block a user