Completed
Pull Request — master (#18)
by Harry
03:48
created

SignatureTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 9
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 136
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A teatDown() 0 4 1
A testCalculateSignature() 0 4 1
A signatureTests() 0 21 1
A testGetUidSignature() 0 4 1
A getUidSignatures() 0 11 1
A testGetFriendUidSignature() 0 4 1
A getFriendUidSignatures() 0 23 1
A testCheckTimestamp() 0 8 1
1
<?php
2
/**
3
 * This file is part of graze/gigya-client
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/gigya-client/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/gigya-client
12
 */
13
14
namespace Graze\Gigya\Test\Unit\Validation;
15
16
use Graze\Gigya\Test\TestCase;
17
use Graze\Gigya\Validation\Signature;
18
19
class SignatureTest extends TestCase
20
{
21
    const UID        = 'g8f7d6gd7s6t23t4gekfs';
22
    const FRIEND_UID = '890fd7tg97d08sbg';
23
    const SECRET     = '8j9h0g-opko;dk]=id0f[sjo';
24
25
    /**
26
     * @var Signature
27
     */
28
    private $validator;
29
30
    public function setUp()
31
    {
32
        $this->validator = new Signature();
33
    }
34
35
    public function teatDown()
36
    {
37
        $this->validator = null;
38
    }
39
40
    /**
41
     * @dataProvider signatureTests
42
     *
43
     * @param string $base
44
     * @param string $secret
45
     * @param string $expected
46
     */
47
    public function testCalculateSignature($base, $secret, $expected)
48
    {
49
        static::assertEquals($expected, $this->validator->calculateSignature($base, $secret));
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    public function signatureTests()
56
    {
57
        return [
58
            ['3242342342_fbdjsfdksbfs', 'hdsvddhlrhtbs[]34o543]', 'PqX1gioG5KKWu2V+nz9d1rKe6rU='],
59
            [
60
                '67686768_fdhfgsvk',
61
                'dsbfjsdkdsaivfdsk',
62
                '/MPK8HnKtMB1n2oxWYTiWdU0S5k=',
63
            ],
64
            [
65
                '129048972362_dhskgafgslad',
66
                '3e54ght879r8ei0[w-4t5',
67
                'QFkNQ6JVk8QuDLjFbm3QtE39lkw=',
68
            ],
69
            [
70
                'k43je5hgy78efu9w0i-oip4h5u',
71
                '=-`z0icd9ufohgutreb4kj342lnejpfud0',
72
                '03NWb/fPekvUmXUlmGVPyPRSDpo=',
73
            ],
74
        ];
75
    }
76
77
    /**
78
     * @dataProvider getUidSignatures
79
     *
80
     * @param string $uid
81
     * @param int    $time
82
     * @param string $secret
83
     * @param string $expected
84
     */
85
    public function testGetUidSignature($uid, $time, $secret, $expected)
86
    {
87
        static::assertEquals($expected, $this->validator->getUidSignature($uid, $time, $secret));
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getUidSignatures()
94
    {
95
        return [
96
            ['908dsf7g68d9', 23456754, 'jkl234h53k2', 'AzKUa+6a2+27Oqxu0nDksvDdjLI='],
97
            ['0-9vbn8m7gfd0ru', 46578543, 'mkl34n5jb4356', 'zGAMM6XlTamV4QH+g3C/RgptX+0='],
98
            ['nk34bjh5kl432njbh', 3456789, 'kln45j654l3kn5jb', 'y8fo2ebrzyuN/kbX0wbPul8VwI8='],
99
            ['b45432lkn4jb', 9876543, 'b4645kl35jb', 'VP93O4U8MeTCH5sJntEBVBRG/F0='],
100
            ['3m4lkn5jb645l43;2k', 345678232, '890fd7g69f0sfd7', 'sVrznUKLsDOJ1Z3Df4qNhClWZ8Q='],
101
            ['809dierpwojl4k23mr', 76823433, 'v65jbk4renlfioupb8', 'hqT0Y7rFL1khRLfwVDFk64vf28M='],
102
        ];
103
    }
104
105
    /**
106
     * @dataProvider getFriendUidSignatures
107
     *
108
     * @param string $uid
109
     * @param string $friendUid
110
     * @param int    $time
111
     * @param string $secret
112
     * @param string $expected
113
     */
114
    public function testGetFriendUidSignature($uid, $friendUid, $time, $secret, $expected)
115
    {
116
        static::assertEquals($expected, $this->validator->getFriendUidSignature($uid, $friendUid, $time, $secret));
117
    }
118
119
    /**
120
     * @return array
121
     */
122
    public function getFriendUidSignatures()
123
    {
124
        return [
125
            ['908dsf7g68d9', '7fcghjv5et4iogu9fp8', 23456754, 'jkl234h53k2', 'tq+VN8H/ygYJbSF+91Mak8XUjGY='],
126
            ['0-9vbn8m7gfd0ru', 'b5jkw4repshdf89vuilbt453w', 46578543, 'mkl34n5jb4356', 'g+oeLL0iZYC4C7tb34qdov5Puec='],
127
            [
128
                'nk34bjh5kl432njbh',
129
                '849357yturiehjwldaksfnbv',
130
                3456789,
131
                'kln45j654l3kn5jb',
132
                't4b9ggtficcKyL4YbHpdHEZbdrw=',
133
            ],
134
            ['b45432lkn4jb', 'v5hjbkl34;ejapwfu8d9gyo7', 9876543, 'b4645kl35jb', 'WKiloNBnOvazdwary9EQdlAKovs='],
135
            ['3m4lkn5jb645l43;2k', 'b5yelrtgiufdbtker', 345678232, '890fd7g69f0sfd7', 'UnuJroSwujupzqwhaCQYItNQ0C4='],
136
            [
137
                '809dierpwojl4k23mr',
138
                '03-49ut8iryughdfkjsladm',
139
                76823433,
140
                'v65jbk4renlfioupb8',
141
                'dkcOPZlo35IE0IMkYtXmeaqF58g=',
142
            ],
143
        ];
144
    }
145
146
    public function testCheckTimestamp()
147
    {
148
        static::assertTrue($this->validator->checkTimestamp(time()));
149
        static::assertTrue($this->validator->checkTimestamp(time() + 180));
150
        static::assertTrue($this->validator->checkTimestamp(time() - 180));
151
        static::assertFalse($this->validator->checkTimestamp(time() + 181));
152
        static::assertFalse($this->validator->checkTimestamp(time() - 181));
153
    }
154
}
155