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

DigestTest::httpDigestProvider()   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\Sources;
8
use kalanis\kw_auth\AuthException;
9
use kalanis\kw_auth\Data\FileCertUser;
10
use kalanis\kw_auth\Interfaces\IUserCert;
11
use kalanis\kw_auth\Methods;
12
use kalanis\kw_locks\LockException;
13
14
15
class DigestTest extends CommonTestClass
16
{
17
    protected $realm1 = 'KWCMS_Http_Digest';
18
    protected $realm2 = '[email protected]';
19
20
    /**
21
     * @param string $address
22
     * @param bool $isAuth
23
     * @param IUserCert|null $expectedUser    chce cert data, kde je pub key a v nem sdileny klic
24
     * @param string $expectedPass
25
     * @param array $incomingCredentials    vlastne _SERVER, kam se nacpou data z klienta, ktera se pak rozdeluji a kontroluji
26
     * @throws AuthException
27
     * @throws LockException
28
     * @dataProvider httpDigestProvider
29
     */
30
    public function testHttpDigest(string $address, bool $isAuth, ?IUserCert $expectedUser, string $expectedPass, array $incomingCredentials): void
31
    {
32
        $urlSource = new Sources\Sources();
33
        $urlSource->setAddress($address);
34
        $method = new Methods\HttpDigest(new \MockAuthCert($expectedUser, $expectedPass), null, new \MockCredentials($incomingCredentials));
35
        $method->process(new \MockCredentials());
36
        $this->assertEquals($isAuth, $method->isAuthorized());
37
    }
38
39
    public function httpDigestProvider(): array
40
    {
41
        $mockUser = new FileCertUser();
42
        $mockUser->setData(123, 'testing', 456, 789, 452, 'Testing', '/dunno/');
43
        $mockUser->addCertInfo('qwertziop', 'qwertziop');
44
        return [
45
            [
46
                '//dummy/u:whoami/?pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
47
                false,
48
                null,
49
                '',
50
                [],
51
            ],
52
            [
53
                '//dummy/?user=whoami&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
54
                false,
55
                $mockUser,
56
                '',
57
                [],
58
            ],
59
            [
60
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
61
                true,
62
                $mockUser,
63
                'asdfghjkl',
64
                [Methods\HttpDigest::INPUT_METHOD => 'GET', Methods\HttpDigest::INPUT_DIGEST => 'username="Mufasa", realm="[email protected]", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dir/index.html", qop="auth", nc="00000001", cnonce="0a4f113b", response="9a4310460ec85329b0263d1f3e6a61af", opaque="5ccc069c403ebaf9f0171e9517f40e41"', ],
65
            ],
66
            [
67
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
68
                false,
69
                $mockUser,
70
                'asdfghjkl',
71
                [Methods\HttpDigest::INPUT_METHOD => 'GET', Methods\HttpDigest::INPUT_DIGEST => 'username="", realm="", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dummy/", qop="auth", nc="00000002", cnonce="0b83e197", response="397e0e824048a9d9aab4792df4083ed6", opaque="5ccc069c403ebaf9f0171e9517f40e41"', ],
72
            ],
73
            [
74
                '//dummy/?user=testing&pass=asdf123ghjk456&timestamp=123456&digest=poiuztrewq',
75
                true,
76
                $mockUser,
77
                'asdfghjkl',
78
                [Methods\HttpDigest::INPUT_METHOD => 'GET', Methods\HttpDigest::INPUT_DIGEST => 'username="Tester", realm="KWCMS_Http_Digest", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", uri="/dummy/", qop="auth", nc="00000002", cnonce="0b83e197", response="397e0e824048a9d9aab4792df4083ed6", opaque="5ccc069c403ebaf9f0171e9517f40e41"', ],
79
            ],
80
        ];
81
    }
82
}
83