Subversion Repositories php-qbpwcf

Rev

Rev 3 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace Ratchet\RFC6455\Test\Unit\Handshake;
4
 
5
use Ratchet\RFC6455\Handshake\RequestVerifier;
6
use PHPUnit\Framework\TestCase;
7
 
8
/**
9
 * @covers Ratchet\RFC6455\Handshake\RequestVerifier
10
 */
11
class RequestVerifierTest extends TestCase {
12
    /**
13
     * @var RequestVerifier
14
     */
15
    protected $_v;
16
 
17
    public function setUp() {
18
        $this->_v = new RequestVerifier();
19
    }
20
 
21
    public static function methodProvider() {
22
        return array(
23
            array(true,  'GET'),
24
            array(true,  'get'),
25
            array(true,  'Get'),
26
            array(false, 'POST'),
27
            array(false, 'DELETE'),
28
            array(false, 'PUT'),
29
            array(false, 'PATCH')
30
        );
31
    }
32
    /**
33
     * @dataProvider methodProvider
34
     */
35
    public function testMethodMustBeGet($result, $in) {
36
        $this->assertEquals($result, $this->_v->verifyMethod($in));
37
    }
38
 
39
    public static function httpVersionProvider() {
40
        return array(
41
            array(true,  1.1),
42
            array(true,  '1.1'),
43
            array(true,  1.2),
44
            array(true,  '1.2'),
45
            array(true,  2),
46
            array(true,  '2'),
47
            array(true,  '2.0'),
48
            array(false, '1.0'),
49
            array(false, 1),
50
            array(false, '0.9'),
51
            array(false, ''),
52
            array(false, 'hello')
53
        );
54
    }
55
 
56
    /**
57
     * @dataProvider httpVersionProvider
58
     */
59
    public function testHttpVersionIsAtLeast1Point1($expected, $in) {
60
        $this->assertEquals($expected, $this->_v->verifyHTTPVersion($in));
61
    }
62
 
63
    public static function uRIProvider() {
64
        return array(
65
            array(true, '/chat'),
66
            array(true, '/hello/world?key=val'),
67
            array(false, '/chat#bad'),
68
            array(false, 'nope'),
69
            array(false, '/ ಠ_ಠ '),
70
            array(false, '/✖')
71
        );
72
    }
73
 
74
    /**
75
     * @dataProvider URIProvider
76
     */
77
    public function testRequestUri($expected, $in) {
78
        $this->assertEquals($expected, $this->_v->verifyRequestURI($in));
79
    }
80
 
81
    public static function hostProvider() {
82
        return array(
83
            array(true, ['server.example.com']),
84
            array(false, [])
85
        );
86
    }
87
 
88
    /**
89
     * @dataProvider HostProvider
90
     */
91
    public function testVerifyHostIsSet($expected, $in) {
92
        $this->assertEquals($expected, $this->_v->verifyHost($in));
93
    }
94
 
95
    public static function upgradeProvider() {
96
        return array(
97
            array(true,  ['websocket']),
98
            array(true,  ['Websocket']),
99
            array(true,  ['webSocket']),
100
            array(false, []),
101
            array(false, [''])
102
        );
103
    }
104
 
105
    /**
106
     * @dataProvider upgradeProvider
107
     */
108
    public function testVerifyUpgradeIsWebSocket($expected, $val) {
109
        $this->assertEquals($expected, $this->_v->verifyUpgradeRequest($val));
110
    }
111
 
112
    public static function connectionProvider() {
113
        return array(
114
            array(true,  ['Upgrade']),
115
            array(true,  ['upgrade']),
116
            array(true,  ['keep-alive', 'Upgrade']),
117
            array(true,  ['Upgrade', 'keep-alive']),
118
            array(true,  ['keep-alive', 'Upgrade', 'something']),
119
            // as seen in Firefox 47.0.1 - see https://github.com/ratchetphp/RFC6455/issues/14
120
            array(true,  ['keep-alive, Upgrade']),
121
            array(true,  ['Upgrade, keep-alive']),
122
            array(true,  ['keep-alive, Upgrade, something']),
123
            array(true,  ['keep-alive, Upgrade', 'something']),
124
            array(false, ['']),
125
            array(false, [])
126
        );
127
    }
128
 
129
    /**
130
     * @dataProvider connectionProvider
131
     */
132
    public function testConnectionHeaderVerification($expected, $val) {
133
        $this->assertEquals($expected, $this->_v->verifyConnection($val));
134
    }
135
 
136
    public static function keyProvider() {
137
        return array(
138
            array(true,  ['hkfa1L7uwN6DCo4IS3iWAw==']),
139
            array(true,  ['765vVoQpKSGJwPzJIMM2GA==']),
140
            array(true,  ['AQIDBAUGBwgJCgsMDQ4PEC==']),
141
            array(true,  ['axa2B/Yz2CdpfQAY2Q5P7w==']),
142
            array(false, [0]),
143
            array(false, ['Hello World']),
144
            array(false, ['1234567890123456']),
145
            array(false, ['123456789012345678901234']),
146
            array(true,  [base64_encode('UTF8allthngs+✓')]),
147
            array(true,  ['dGhlIHNhbXBsZSBub25jZQ==']),
148
            array(false, []),
149
            array(false, ['dGhlIHNhbXBsZSBub25jZQ==', 'Some other value']),
150
            array(false, ['Some other value', 'dGhlIHNhbXBsZSBub25jZQ=='])
151
        );
152
    }
153
 
154
    /**
155
     * @dataProvider keyProvider
156
     */
157
    public function testKeyIsBase64Encoded16BitNonce($expected, $val) {
158
        $this->assertEquals($expected, $this->_v->verifyKey($val));
159
    }
160
 
161
    public static function versionProvider() {
162
        return array(
163
            array(true,  [13]),
164
            array(true,  ['13']),
165
            array(false, [12]),
166
            array(false, [14]),
167
            array(false, ['14']),
168
            array(false, ['hi']),
169
            array(false, ['']),
170
            array(false, [])
171
        );
172
    }
173
 
174
    /**
175
     * @dataProvider versionProvider
176
     */
177
    public function testVersionEquals13($expected, $in) {
178
        $this->assertEquals($expected, $this->_v->verifyVersion($in));
179
    }
180
}