forked from nette/security
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleAuthenticator.phpt
More file actions
35 lines (24 loc) · 984 Bytes
/
Copy pathSimpleAuthenticator.phpt
File metadata and controls
35 lines (24 loc) · 984 Bytes
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
<?php
/**
* Test: Nette\Security\SimpleAuthenticator
*/
use Nette\Security\SimpleAuthenticator;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$users = [
'john' => 'password123!',
'admin' => 'admin',
];
$authenticator = new SimpleAuthenticator($users);
$identity = $authenticator->authenticate(['john', 'password123!']);
Assert::type(Nette\Security\IIdentity::class, $identity);
Assert::equal('john', $identity->getId());
$identity = $authenticator->authenticate(['admin', 'admin']);
Assert::type(Nette\Security\IIdentity::class, $identity);
Assert::equal('admin', $identity->getId());
Assert::exception(function () use ($authenticator) {
$authenticator->authenticate(['admin', 'wrong password']);
}, Nette\Security\AuthenticationException::class, 'Invalid password.');
Assert::exception(function () use ($authenticator) {
$authenticator->authenticate(['nobody', 'password']);
}, Nette\Security\AuthenticationException::class, "User 'nobody' not found.");