Passed
Push — master ( b28c40...f61e74 )
by Petr
08:06
created

UserTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 2
1
<?php
2
3
namespace MethodsTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_address_handler\Sources;
8
use kalanis\kw_auth\AuthException;
9
use kalanis\kw_auth\Data\FileUser;
10
use kalanis\kw_auth\Interfaces\IUser;
11
use kalanis\kw_auth\Methods;
12
use kalanis\kw_locks\LockException;
13
14
15
class UserTest extends CommonTestClass
16
{
17
    /**
18
     * @param string $address
19
     * @param bool $isAuth
20
     * @param IUser|null $expectedUser
21
     * @param string $expectedPass
22
     * @param array $incomingCredentials
23
     * @throws AuthException
24
     * @throws LockException
25
     * @dataProvider httpUserProvider
26
     */
27
    public function testHttpUser(string $address, bool $isAuth, ?IUser $expectedUser, string $expectedPass, array $incomingCredentials): void
28
    {
29
        $urlSource = new Sources\Sources();
30
        $urlSource->setAddress($address);
31
        $method = new Methods\HttpUser(new \MockAuth($expectedUser, $expectedPass), null, new \MockCredentials($incomingCredentials));
32
        $method->process(new \MockCredentials());
33
        $this->assertEquals($isAuth, $method->isAuthorized());
34
    }
35
36
    public function httpUserProvider(): array
37
    {
38
        $mockUser = new FileUser();
39
        $mockUser->setData(123, 'testing', 456, 789, 453, 'Testing', '/dunno/');
40
        return [
41
            [
42
                '//dummy/u:whoami/?pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
43
                false,
44
                null,
45
                '',
46
                [],
47
            ],
48
            [
49
                '//dummy/?user=whoami&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
50
                false,
51
                $mockUser,
52
                '',
53
                [],
54
            ],
55
            [
56
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
57
                true,
58
                $mockUser,
59
                'asdfghjkl',
60
                [Methods\HttpUser::INPUT_NAME => 'testing', Methods\HttpUser::INPUT_PASS => 'asdfghjkl', ],
61
            ],
62
        ];
63
    }
64
}
65