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