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

HashTest::urlHashProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 27
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 40
rs 9.488
1
<?php
2
3
namespace MethodsTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_address_handler\Handler;
8
use kalanis\kw_address_handler\Sources;
9
use kalanis\kw_auth\AuthException;
10
use kalanis\kw_auth\Data\FileCertUser;
11
use kalanis\kw_auth\Interfaces\IUserCert;
12
use kalanis\kw_auth\Methods;
13
use kalanis\kw_locks\LockException;
14
15
16
class HashTest extends CommonTestClass
17
{
18
    /**
19
     * @param string $address
20
     * @param bool $isAuth
21
     * @param IUserCert|null $expectedUser
22
     * @param string $expectedPass
23
     * @param array $incomingCredentials
24
     * @throws AuthException
25
     * @throws LockException
26
     * @dataProvider urlHashProvider
27
     */
28
    public function testUrlHash(string $address, bool $isAuth, ?IUserCert $expectedUser, string $expectedPass, array $incomingCredentials): void
29
    {
30
        $urlSource = new Sources\Sources();
31
        $urlSource->setAddress($address);
32
        $method = new Methods\UrlHash(new \MockAuthCert($expectedUser, $expectedPass), null, new Handler($urlSource), 'md5');
33
        $method->process(new \MockCredentials($incomingCredentials));
34
        $this->assertEquals($isAuth, $method->isAuthorized());
35
        $method->remove();
36
    }
37
38
    public function urlHashProvider(): array
39
    {
40
        $mockUser = new FileCertUser();
41
        $mockUser->setData(123, 'testing', 456, 789, 452, 'Testing', '/dunno/');
42
        $mockUser->addCertInfo('qwertziop', 'qwertziop');
43
        return [
44
            [
45
                '//dummy/u:whoami/?pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
46
                false,
47
                null,
48
                '',
49
                [],
50
            ],
51
            [
52
                '//dummy/?user=whoami&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
53
                false,
54
                $mockUser,
55
                '',
56
                [],
57
            ],
58
            [
59
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
60
                false,
61
                $mockUser,
62
                'asdfghjkl',
63
                [Methods\UrlHash::INPUT_STAMP => time(), ],
64
            ],
65
            [
66
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
67
                false,
68
                $mockUser,
69
                'asdfghjkl',
70
                ['pass'=> 'lkjhgfdsa', ],
71
            ],
72
            [
73
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=3d43f5b47be2258468c862fce574dfe0',
74
                true,
75
                $mockUser,
76
                'lkjhgfdsa',
77
                ['pass' => 'lkjhgfdsa', Methods\UrlHash::INPUT_NAME => 'someone', Methods\UrlHash::INPUT_STAMP => time(), ],
78
            ],
79
        ];
80
    }
81
}
82