| 1 | <?php |
||
| 18 | * Class BasicAuthTest. |
||
| 19 | */ |
||
| 20 | class BasicAuthTest extends \PHPUnit_Framework_TestCase |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | protected $excludedUsers = [ |
||
| 26 | 'root' => 'secret', |
||
| 27 | 'guest' => null, |
||
| 28 | ]; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @dataProvider usersProvider |
||
| 32 | */ |
||
| 33 | public function testIsExcluded($username, $password) |
||
| 34 | { |
||
| 35 | $authString = $username . ($password === null ? '' : ':' . $password); |
||
| 36 | |||
| 37 | $request = ServerRequestFactory::fromGlobals(); |
||
| 38 | $request = $request->withHeader('Authorization', 'Basic ' . base64_encode($authString)); |
||
| 39 | |||
| 40 | $excluder = new BasicAuth; |
||
| 41 | $excluder->addUser($username, $password); |
||
| 42 | |||
| 43 | self::assertTrue($excluder->isExcluded($request)); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Users provider. |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | public function usersProvider() |
||
| 52 | { |
||
| 53 | return [ |
||
| 54 | ['root', 'secret'], |
||
| 55 | ['guest', null], |
||
| 56 | ]; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function testIsNotExcluded() |
||
| 60 | { |
||
| 61 | $request = ServerRequestFactory::fromGlobals(); |
||
| 62 | $excluder = new BasicAuth(['root' => 'secret']); |
||
| 63 | |||
| 64 | self::assertFalse($excluder->isExcluded($request)); |
||
| 65 | } |
||
| 67 |