-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathPasswordsTest.php
71 lines (55 loc) · 1.73 KB
/
PasswordsTest.php
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter Shield.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Tests\Unit;
use CodeIgniter\Shield\Authentication\Passwords;
use CodeIgniter\Shield\Config\Auth as AuthConfig;
use CodeIgniter\Shield\Entities\User;
use CodeIgniter\Test\CIUnitTestCase;
/**
* @internal
*/
final class PasswordsTest extends CIUnitTestCase
{
public function testEmptyPassword(): void
{
$passwords = new Passwords(new AuthConfig());
$result = $passwords->check('', new User());
$this->assertFalse($result->isOK());
$this->assertSame('A Password is required.', $result->reason());
}
public function testHash(): string
{
$config = new AuthConfig();
$passwords = new Passwords($config);
$plainPassword = 'passw0rd!';
$hashedPassword = $passwords->hash($plainPassword);
$user = new User([
'id' => 1,
'username' => 'John',
]);
$user->email = '[email protected]';
$user->password_hash = $hashedPassword;
$result = $passwords->check($plainPassword, $user);
$this->assertTrue($result->isOK());
return $hashedPassword;
}
/**
* @depends testHash
*/
public function testNeedsRehashTakesCareOptions(string $hashedPassword): void
{
$config = new AuthConfig();
$config->hashCost = 13;
$passwords = new Passwords($config);
$result = $passwords->needsRehash($hashedPassword);
$this->assertTrue($result);
}
}