21 lines
662 B
PHP
21 lines
662 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Tests;
|
|
use App\Security\{Password, Csrf};
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class PasswordCsrfTest extends TestCase
|
|
{
|
|
public function testHashVerify(): void {
|
|
$h = Password::hash('s3cret!');
|
|
$this->assertNotSame('s3cret!', $h);
|
|
$this->assertTrue(Password::verify('s3cret!', $h));
|
|
$this->assertFalse(Password::verify('wrong', $h));
|
|
}
|
|
public function testCsrf(): void {
|
|
$t = Csrf::issue(fn() => 'abc123');
|
|
$this->assertSame('abc123', $t);
|
|
$this->assertTrue(Csrf::check($t, 'abc123'));
|
|
$this->assertFalse(Csrf::check($t, 'nope'));
|
|
}
|
|
}
|