-
-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathPasswordHasherTest.php
More file actions
51 lines (40 loc) · 1.69 KB
/
Copy pathPasswordHasherTest.php
File metadata and controls
51 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Tests\Tempest\Integration\Cryptography;
use Tempest\Cryptography\Password\BcryptConfig;
use Tempest\Cryptography\Password\HashingAlgorithm;
use Tempest\Cryptography\Password\PasswordHasher;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
final class PasswordHasherTest extends FrameworkIntegrationTestCase
{
public function test_default_algorithm(): void
{
$hasher = $this->container->get(PasswordHasher::class);
$expected = in_array(HashingAlgorithm::ARGON2ID->value, password_algos(), true)
? HashingAlgorithm::ARGON2ID
: HashingAlgorithm::BCRYPT;
$this->assertSame($expected, $hasher->algorithm);
}
public function test_hash_verify(): void
{
$hasher = $this->container->get(PasswordHasher::class);
$password = 'my_secure_password'; // @mago-expect lint:no-literal-password
$hash = $hasher->hash($password);
$this->assertTrue($hasher->verify($password, $hash));
}
public function test_update_config(): void
{
$this->container->config(new BcryptConfig());
$hasher = $this->container->get(PasswordHasher::class);
$this->assertSame(HashingAlgorithm::BCRYPT, $hasher->algorithm);
}
public function needs_rehash(): void
{
$this->container->config(new BcryptConfig(cost: 2));
$hasher1 = $this->container->get(PasswordHasher::class);
$hash = $hasher1->hash('my_secure_password');
$this->container->config(new BcryptConfig(cost: 3));
$hasher2 = $this->container->get(PasswordHasher::class);
$this->assertFalse($hasher1->needsRehash($hash));
$this->assertTrue($hasher2->needsRehash($hash));
}
}