|
7 | 7 | require_once __DIR__ . '/../../bootstrap.php'; |
8 | 8 |
|
9 | 9 | use Contributte\Security\Auth\StaticAuthenticator; |
| 10 | +use Contributte\Tester\Toolkit; |
10 | 11 | use Nette\Security\AuthenticationException; |
11 | 12 | use Nette\Security\IIdentity; |
12 | 13 | use Nette\Security\Passwords; |
13 | 14 | use Tester\Assert; |
14 | 15 |
|
15 | | -// Success - hashed password |
16 | | -test(function (): void { |
| 16 | +// Authenticate with hashed password |
| 17 | +Toolkit::test(function (): void { |
17 | 18 | $hash = (new Passwords(PASSWORD_BCRYPT))->hash('foobar'); |
18 | 19 | $auth = new StaticAuthenticator([ |
19 | 20 | |
20 | 21 | 'password' => $hash, |
21 | 22 | ], |
22 | | - ], (new Passwords(PASSWORD_BCRYPT))); |
| 23 | + ], new Passwords(PASSWORD_BCRYPT)); |
23 | 24 |
|
24 | 25 | Assert:: type(IIdentity::class, $auth-> authenticate( '[email protected]', 'foobar')); |
25 | 26 | }); |
26 | 27 |
|
27 | | -// Success - plain password |
28 | | -test(function (): void { |
| 28 | +// Authenticate with plain password (unsecured) |
| 29 | +Toolkit::test(function (): void { |
29 | 30 | $auth = new StaticAuthenticator([ |
30 | 31 | |
31 | 32 | 'password' => 'foobar', |
32 | 33 | 'unsecured' => true, |
33 | 34 | ], |
34 | | - ], (new Passwords(PASSWORD_BCRYPT))); |
| 35 | + ], new Passwords(PASSWORD_BCRYPT)); |
35 | 36 |
|
36 | 37 | Assert:: type(IIdentity::class, $auth-> authenticate( '[email protected]', 'foobar')); |
37 | 38 | }); |
38 | 39 |
|
39 | | -// User not found |
40 | | -test(function (): void { |
| 40 | +// Authenticate throws exception when user not found |
| 41 | +Toolkit::test(function (): void { |
41 | 42 | $hash = (new Passwords(PASSWORD_BCRYPT))->hash('foobar'); |
42 | 43 | $auth = new StaticAuthenticator([ |
43 | 44 | |
44 | 45 | 'password' => $hash, |
45 | 46 | ], |
46 | | - ], (new Passwords(PASSWORD_BCRYPT))); |
| 47 | + ], new Passwords(PASSWORD_BCRYPT)); |
47 | 48 |
|
48 | 49 | Assert::exception(function () use ($auth): void { |
49 | 50 | $auth->authenticate('foo', 'bar'); |
50 | 51 | }, AuthenticationException::class, 'User `foo` not found'); |
51 | 52 | }); |
52 | 53 |
|
53 | | -// Invalid password |
54 | | -test(function (): void { |
| 54 | +// Authenticate throws exception on invalid password |
| 55 | +Toolkit::test(function (): void { |
55 | 56 | $hash = (new Passwords(PASSWORD_BCRYPT))->hash('foobar'); |
56 | 57 | $auth = new StaticAuthenticator([ |
57 | 58 | |
58 | 59 | 'password' => $hash, |
59 | 60 | ], |
60 | | - ], (new Passwords(PASSWORD_BCRYPT))); |
| 61 | + ], new Passwords(PASSWORD_BCRYPT)); |
61 | 62 |
|
62 | 63 | Assert::exception(function () use ($auth): void { |
63 | 64 | $auth-> authenticate( '[email protected]', 'bar'); |
|
0 commit comments