Completed
Push — master ( ecd5d7...f9662e )
by Julián
11:22
created

BasicAuthTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 47
rs 10
1
<?php
2
3
/*
4
 * janitor (http://juliangut.com/janitor).
5
 * Effortless maintenance management.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/janitor
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Janitor\Test\Excluder;
13
14
use Janitor\Excluder\BasicAuth;
15
use Zend\Diactoros\ServerRequestFactory;
16
17
/**
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
    }
66
}
67