Passed
Push — master ( c58543...7e23e7 )
by Gaetano
13:15
created

HTTPTest::testHttp2()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
include_once __DIR__ . '/../lib/xmlrpc.inc';
4
include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
5
6
include_once __DIR__ . '/parse_args.php';
7
8
include_once __DIR__ . '/5ServerTest.php';
9
10
/**
11
 * Tests which stress http features of the library.
12
 * Each of these tests iterates over (almost) all the 'localhost' tests
13
 */
14
class HTTPTest extends ServerTest
15
{
16
    /**
17
     * Returns all test methods from the base class, except the ones which failed already
18
     *
19
     * @todo (re)introduce skipping of tests which failed when executed individually even if test runs happen as separate processes
20
     * @todo reintroduce skipping of tests within the loop
21
     */
22
    public function getSingleHttpTestMethods()
23
    {
24
        $unsafeMethods = array(
25
            'testCatchExceptions', 'testUtf8Method', 'testServerComments',
26
            'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
27
            'testWrapInexistentUrl',
28
        );
29
30
        $methods = array();
31
        foreach(get_class_methods('ServerTest') as $method)
32
        {
33
            if (strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
34
            {
35
                if (!isset(self::$failed_tests[$method])) {
36
                    $methods[$method] = array($method);
37
                }
38
            }
39
        }
40
41
        return $methods;
42
    }
43
44
    /**
45
     * @dataProvider getSingleHttpTestMethods
46
     * @param string $method
47
     */
48
    public function testDeflate($method)
49
    {
50
        if (!function_exists('gzdeflate'))
51
        {
52
            $this->markTestSkipped('Zlib missing: cannot test deflate functionality');
53
            return;
54
        }
55
56
        $this->client->accepted_compression = array('deflate');
57
        $this->client->request_compression = 'deflate';
58
59
        $this->$method();
60
    }
61
62
    /**
63
     * @dataProvider getSingleHttpTestMethods
64
     * @param string $method
65
     */
66
    public function testGzip($method)
67
    {
68
        if (!function_exists('gzdeflate'))
69
        {
70
            $this->markTestSkipped('Zlib missing: cannot test gzip functionality');
71
            return;
72
        }
73
74
        $this->client->accepted_compression = array('gzip');
75
        $this->client->request_compression = 'gzip';
76
77
        $this->$method();
78
    }
79
80
    public function testKeepAlives()
81
    {
82
        if (!function_exists('curl_init'))
83
        {
84
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
85
            return;
86
        }
87
88
        $this->method = 'http11';
89
        $this->client->method = 'http11';
90
        $this->client->keepalive = true;
91
92
        // to successfully test keepalive, we have to reuse the same client for all tests, we can not recreate one on setup/teardown...
93
        foreach ($this->getSingleHttpTestMethods() as $methods) {
94
            $method = $methods[0];
95
            $this->$method();
96
        }
97
    }
98
99
    /**
100
     * @dataProvider getSingleHttpTestMethods
101
     * @param string $method
102
     */
103
    public function testProxy($method)
104
    {
105
        if ($this->args['PROXYSERVER'] == '')
106
        {
107
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy');
108
            return;
109
        }
110
111
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
112
113
        $this->$method();
114
    }
115
116
    /**
117
     * @dataProvider getSingleHttpTestMethods
118
     * @param string $method
119
     */
120
    public function testHttp11($method)
121
    {
122
        if (!function_exists('curl_init'))
123
        {
124
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
125
            return;
126
        }
127
128
        $this->method = 'http11'; // not an error the double assignment!
129
        $this->client->method = 'http11';
130
        $this->client->keepalive = false;
131
132
        $this->$method();
133
    }
134
135
    /**
136
     * @dataProvider getSingleHttpTestMethods
137
     * @param string $method
138
     */
139
    public function testHttp10Curl($method)
140
    {
141
        if (!function_exists('curl_init'))
142
        {
143
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
144
            return;
145
        }
146
147
        $this->method = 'http10'; // not an error the double assignment!
148
        $this->client->method = 'http10';
149
        $this->client->keepalive = false;
150
        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);
151
152
        $this->$method();
153
    }
154
155
    /**
156
     * @dataProvider getSingleHttpTestMethods
157
     * @param string $method
158
     */
159
    public function testHttp11Gzip($method)
160
    {
161
        if (!function_exists('curl_init'))
162
        {
163
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
164
            return;
165
        }
166
        $this->method = 'http11'; // not an error the double assignment!
167
        $this->client->method = 'http11';
168
        $this->client->keepalive = false;
169
        $this->client->accepted_compression = array('gzip');
170
        $this->client->request_compression = 'gzip';
171
172
        $this->$method();
173
    }
174
175
    /**
176
     * @dataProvider getSingleHttpTestMethods
177
     * @param string $method
178
     */
179
    public function testHttp11Deflate($method)
180
    {
181
        if (!function_exists('curl_init'))
182
        {
183
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
184
            return;
185
        }
186
        $this->method = 'http11'; // not an error the double assignment!
187
        $this->client->method = 'http11';
188
        $this->client->keepalive = false;
189
        $this->client->accepted_compression = array('deflate');
190
        $this->client->request_compression = 'deflate';
191
192
        $this->$method();
193
    }
194
195
    /**
196
     * @dataProvider getSingleHttpTestMethods
197
     * @param string $method
198
     */
199
    public function testHttp11Proxy($method)
200
    {
201
        if (!function_exists('curl_init'))
202
        {
203
            $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
204
            return;
205
        }
206
        else if ($this->args['PROXYSERVER'] == '')
207
        {
208
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. http 1.1');
209
            return;
210
        }
211
212
        $this->method = 'http11'; // not an error the double assignment!
213
        $this->client->method = 'http11';
214
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
215
        $this->client->keepalive = false;
216
217
        $this->$method();
218
    }
219
220
    /**
221
     * @dataProvider getSingleHttpTestMethods
222
     * @param string $method
223
     */
224
    public function testHttps($method)
225
    {
226
        if (!function_exists('curl_init'))
227
        {
228
            $this->markTestSkipped('CURL missing: cannot test https functionality');
229
            return;
230
        }
231
        else if ($this->args['HTTPSSERVER'] == '')
232
        {
233
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https');
234
            return;
235
        }
236
237
        $this->client->server = $this->args['HTTPSSERVER'];
238
        $this->method = 'https';
239
        $this->client->method = 'https';
240
        $this->client->path = $this->args['HTTPSURI'];
241
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
242
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
243
        $this->client->setSSLVersion($this->args['SSLVERSION']);
244
245
        $this->$method();
246
    }
247
248
    /**
249
     * @dataProvider getSingleHttpTestMethods
250
     * @param string $method
251
     */
252
    public function testHttpsSocket($method)
253
    {
254
        if ($this->args['HTTPSSERVER'] == '')
255
        {
256
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https');
257
            return;
258
        }
259
260
        $this->client->server = $this->args['HTTPSSERVER'];
261
        $this->method = 'https';
262
        $this->client->method = 'https';
263
        $this->client->path = $this->args['HTTPSURI'];
264
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
265
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
266
        $this->client->setSSLVersion($this->args['SSLVERSION']);
267
        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER);
268
269
        $this->$method();
270
    }
271
272
    /**
273
     * @dataProvider getSingleHttpTestMethods
274
     * @param string $method
275
     */
276
    public function testHttpsProxy($method)
277
    {
278
        if (!function_exists('curl_init'))
279
        {
280
            $this->markTestSkipped('CURL missing: cannot test https w. proxy');
281
            return;
282
        }
283
        else if ($this->args['PROXYSERVER'] == '')
284
        {
285
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https');
286
            return;
287
        }
288
        else if ($this->args['HTTPSSERVER'] == '')
289
        {
290
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy');
291
            return;
292
        }
293
294
        $this->client->server = $this->args['HTTPSSERVER'];
295
        $this->method = 'https';
296
        $this->client->method = 'https';
297
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
298
        $this->client->path = $this->args['HTTPSURI'];
299
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
300
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
301
        $this->client->setSSLVersion($this->args['SSLVERSION']);
302
303
        $this->$method();
304
    }
305
306
    /**
307
     * @dataProvider getSingleHttpTestMethods
308
     * @param string $method
309
     */
310
    public function testHttp2($method)
311
    {
312
        if (!function_exists('curl_init'))
313
        {
314
            $this->markTestSkipped('CURL missing: cannot test http/2');
315
            return;
316
        }
317
318
        $this->method = 'http2'; // not an error the double assignment!
319
        $this->client->method = 'http2';
320
        //$this->client->keepalive = false; // q: is this a good idea?
321
        $this->$method();
322
    }
323
324
    /**
325
     * @dataProvider getSingleHttpTestMethods
326
     * @param string $method
327
     */
328
    public function testHttp2tls($method)
329
    {
330
        if (!function_exists('curl_init'))
331
        {
332
            $this->markTestSkipped('CURL missing: cannot test http/2 tls');
333
            return;
334
        } else if ($this->args['HTTPSSERVER'] == '')
335
        {
336
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test http/2 tls');
337
            return;
338
        }
339
340
        $this->client->server = $this->args['HTTPSSERVER'];
341
        $this->method = 'http2tls';
342
        $this->client->method = 'http2tls';
343
        $this->client->path = $this->args['HTTPSURI'];
344
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
345
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
346
        $this->client->setSSLVersion($this->args['SSLVERSION']);
347
348
        $this->$method();
349
    }
350
351
    /**
352
     * @dataProvider getSingleHttpTestMethods
353
     * @param string $method
354
     */
355
    public function testUTF8Responses($method)
356
    {
357
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8'));
358
359
        $this->$method();
360
    }
361
362
    /**
363
     * @dataProvider getSingleHttpTestMethods
364
     * @param string $method
365
     */
366
    public function testUTF8Requests($method)
367
    {
368
        $this->client->request_charset_encoding = 'UTF-8';
369
370
        $this->$method();
371
    }
372
373
    /**
374
     * @dataProvider getSingleHttpTestMethods
375
     * @param string $method
376
     */
377
    public function testISOResponses($method)
378
    {
379
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1'));
380
381
        $this->$method();
382
    }
383
384
    /**
385
     * @dataProvider getSingleHttpTestMethods
386
     * @param string $method
387
     */
388
    public function testISORequests($method)
389
    {
390
        $this->client->request_charset_encoding = 'ISO-8859-1';
391
392
        $this->$method();
393
    }
394
395
    /**
396
     * @dataProvider getSingleHttpTestMethods
397
     * @param string $method
398
     */
399
    public function testBasicAuth($method)
400
    {
401
        $this->client->setCredentials('test', 'test');
402
        $this->addQueryParams(array('FORCE_AUTH' => 'Basic'));
403
404
        $this->$method();
405
    }
406
407
    /**
408
     * @dataProvider getSingleHttpTestMethods
409
     * @param string $method
410
     */
411
    public function testDigestAuth($method)
412
    {
413
        if (!function_exists('curl_init'))
414
        {
415
            $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
416
            return;
417
        }
418
419
        $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
420
        $this->addQueryParams(array('FORCE_AUTH' => 'Digest'));
421
        $this->method = 'http11';
422
        $this->client->method = 'http11';
423
424
        $this->$method();
425
    }
426
}
427