🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 13:39
This commit is contained in:
30
tests/Unit/TotpServiceTest.php
Normal file
30
tests/Unit/TotpServiceTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Services\TotpService;
|
||||
|
||||
final class TotpServiceTest extends TestCase
|
||||
{
|
||||
public function test_it_generates_valid_secret(): void
|
||||
{
|
||||
$service = new TotpService();
|
||||
$secret = $service->generateSecret();
|
||||
|
||||
$this->assertEquals(16, strlen($secret));
|
||||
$this->assertMatchesRegularExpression('/^[A-Z2-7]+$/', $secret);
|
||||
}
|
||||
|
||||
public function test_it_verifies_correct_code(): void
|
||||
{
|
||||
$service = new TotpService();
|
||||
$secret = 'JBSWY3DPEHPK3PXP'; // Known secret
|
||||
|
||||
// We can't easily test the code without a time mocker or calculation
|
||||
// but we can check if it fails with an obviously wrong code
|
||||
$this->assertFalse($service->verify($secret, '000000'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user