Passed
Push — master ( 413d70...a8c502 )
by Gaetano
10:32
created

HTTPTest::testHttpsProxyCurl()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 35
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 21
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 35
rs 8.9617
1
<?php
2
3
include_once __DIR__ . '/08ServerTest.php';
4
5
/**
6
 * Tests which stress http features of the library.
7
 * Each of these tests iterates over (almost) all the 'Server' tests
8
 */
9
class HTTPTest extends ServerTest
10
{
11
    protected $expectHttp2 = false;
12
13
    protected $unsafeMethods = array(
14
        'testCatchExceptions', 'testCatchErrors', 'testUtf8Method', 'testServerComments',
15
        'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
16
        'testWrapInexistentUrl', 'testNegativeDebug', 'testTimeout'
17
    );
18
19
    /**
20
     * Returns all test methods from the base class, except the ones which failed already and the ones which make no sense
21
     * to run with different HTTP options.
22
     *
23
     * @todo (re)introduce skipping of tests which failed when executed individually even if test runs happen as separate processes
24
     * @todo reintroduce skipping of tests within the loop
25
     * @todo testTimeout is actually good to be tested with proxies etc - but it slows down the testsuite a lot!
26
     */
27
    public function getSingleHttpTestMethods()
28
    {
29
        $methods = array();
30
        // as long as we are descendants, get_class_methods will list private/protected methods
31
        foreach(get_class_methods('ServerTest') as $method)
32
        {
33
            if (strpos($method, 'test') === 0 && !in_array($method, $this->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');
0 ignored issues
show
Bug Best Practice introduced by
The property $accepted_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
57
        $this->client->request_compression = 'deflate';
0 ignored issues
show
Bug Best Practice introduced by
The property $request_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
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');
0 ignored issues
show
Bug Best Practice introduced by
The property $accepted_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
75
        $this->client->request_compression = 'gzip';
0 ignored issues
show
Bug Best Practice introduced by
The property $request_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The property $keepalive is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
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 testRedirects($method)
104
    {
105
        if (!function_exists('curl_init'))
106
        {
107
            $this->markTestSkipped('CURL missing: cannot test redirects');
108
            return;
109
        }
110
111
        /// @todo replace with setOption when dropping the BC layer
112
        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setUseCurl() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

112
        /** @scrutinizer ignore-deprecated */ $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
113
        $this->client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3));
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setCurlOptions() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

113
        /** @scrutinizer ignore-deprecated */ $this->client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
114
115
        $this->$method();
116
    }
117
118
    public function testAcceptCharset()
119
    {
120
        if (version_compare(PHP_VERSION, '5.6.0', '<'))
121
        {
122
            $this->markTestSkipped('Cannot test accept-charset on php < 5.6');
123
            return;
124
        }
125
        if (!function_exists('mb_list_encodings'))
126
        {
127
            $this->markTestSkipped('mbstring missing: cannot test accept-charset');
128
            return;
129
        }
130
131
        $r = new \PhpXmlRpc\Request('examples.stringecho', array(new \PhpXmlRpc\Value('€')));
132
        //chr(164)
133
134
        \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
135
136
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'auto'));
137
        $this->client->accepted_charset_encodings = array(
0 ignored issues
show
Bug Best Practice introduced by
The property $accepted_charset_encodings is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
138
            'utf-1234;q=0.1',
139
            'windows-1252;q=0.8'
140
        );
141
        $v = $this->send($r, 0, true);
142
        $h = $v->httpResponse();
143
        $this->assertEquals('text/xml; charset=Windows-1252', $h['headers']['content-type']);
144
        if ($v) {
145
            $this->assertEquals('€', $v->value()->scalarval());
146
        }
147
    }
148
149
    /**
150
     * @dataProvider getSingleHttpTestMethods
151
     * @param string $method
152
     */
153
    public function testProxy($method)
154
    {
155
        if ($this->args['PROXYSERVER'] == '')
156
        {
157
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy');
158
            return;
159
        }
160
161
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
162
163
        $this->$method();
164
    }
165
166
    /**
167
     * @dataProvider getSingleHttpTestMethods
168
     * @param string $method
169
     */
170
    public function testHttp11($method)
171
    {
172
        if (!function_exists('curl_init'))
173
        {
174
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
175
            return;
176
        }
177
178
        $this->method = 'http11'; // not an error the double assignment!
179
        $this->client->method = 'http11';
180
        $this->client->keepalive = false;
0 ignored issues
show
Bug Best Practice introduced by
The property $keepalive is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
181
182
        $this->$method();
183
    }
184
185
    /**
186
     * @dataProvider getSingleHttpTestMethods
187
     * @param string $method
188
     */
189
    public function testHttp10Curl($method)
190
    {
191
        if (!function_exists('curl_init'))
192
        {
193
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
194
            return;
195
        }
196
197
        $this->method = 'http10'; // not an error the double assignment!
198
        $this->client->method = 'http10';
199
        /// @todo replace with setOption when dropping the BC layer
200
        $this->client->keepalive = false;
0 ignored issues
show
Bug Best Practice introduced by
The property $keepalive is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
201
        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setUseCurl() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

201
        /** @scrutinizer ignore-deprecated */ $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
202
203
        $this->$method();
204
    }
205
206
    /**
207
     * @dataProvider getSingleHttpTestMethods
208
     * @param string $method
209
     */
210
    public function testHttp11Gzip($method)
211
    {
212
        if (!function_exists('curl_init'))
213
        {
214
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
215
            return;
216
        }
217
        $this->method = 'http11'; // not an error the double assignment!
218
        $this->client->method = 'http11';
219
        $this->client->keepalive = false;
0 ignored issues
show
Bug Best Practice introduced by
The property $keepalive is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
220
        $this->client->accepted_compression = array('gzip');
0 ignored issues
show
Bug Best Practice introduced by
The property $accepted_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
221
        $this->client->request_compression = 'gzip';
0 ignored issues
show
Bug Best Practice introduced by
The property $request_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
222
223
        $this->$method();
224
    }
225
226
    /**
227
     * @dataProvider getSingleHttpTestMethods
228
     * @param string $method
229
     */
230
    public function testHttp11Deflate($method)
231
    {
232
        if (!function_exists('curl_init'))
233
        {
234
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
235
            return;
236
        }
237
        $this->method = 'http11'; // not an error the double assignment!
238
        $this->client->method = 'http11';
239
        $this->client->keepalive = false;
0 ignored issues
show
Bug Best Practice introduced by
The property $keepalive is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
240
        $this->client->accepted_compression = array('deflate');
0 ignored issues
show
Bug Best Practice introduced by
The property $accepted_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
241
        $this->client->request_compression = 'deflate';
0 ignored issues
show
Bug Best Practice introduced by
The property $request_compression is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
242
243
        $this->$method();
244
    }
245
246
    /**
247
     * @dataProvider getSingleHttpTestMethods
248
     * @param string $method
249
     */
250
    public function testHttp11Proxy($method)
251
    {
252
        if (!function_exists('curl_init'))
253
        {
254
            $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
255
            return;
256
        }
257
        else if ($this->args['PROXYSERVER'] == '')
258
        {
259
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. http 1.1');
260
            return;
261
        }
262
263
        $this->method = 'http11'; // not an error the double assignment!
264
        $this->client->method = 'http11';
265
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
266
        $this->client->keepalive = false;
0 ignored issues
show
Bug Best Practice introduced by
The property $keepalive is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
267
268
        $this->$method();
269
    }
270
271
    /**
272
     * @dataProvider getSingleHttpTestMethods
273
     * @param string $method
274
     */
275
    public function testHttpsCurl($method)
276
    {
277
        if (!function_exists('curl_init'))
278
        {
279
            $this->markTestSkipped('CURL missing: cannot test https functionality');
280
            return;
281
        }
282
        else if ($this->args['HTTPSSERVER'] == '')
283
        {
284
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https');
285
            return;
286
        }
287
288
        $this->client->server = $this->args['HTTPSSERVER'];
289
        $this->method = 'https';
290
        $this->client->method = 'https';
291
        $this->client->path = $this->args['HTTPSURI'];
292
        /// @todo replace with setOptions when dropping the BC layer
293
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyPeer() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

293
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
294
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyHost() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

294
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
295
        $this->client->setSSLVersion($this->args['SSLVERSION']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

295
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion($this->args['SSLVERSION']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
296
        /// @todo push this IF to the test matrix config?
297
        if (version_compare(PHP_VERSION, '8.0', '>=') && $this->args['SSLVERSION'] == 0)
298
        {
299
            $version = explode('.', PHP_VERSION);
300
            $this->client->setSSLVersion(min(4 + $version[1], 7));
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

300
            /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion(min(4 + $version[1], 7));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
301
        }
302
303
        $this->$method();
304
    }
305
306
    /**
307
     * @dataProvider getSingleHttpTestMethods
308
     * @param string $method
309
     */
310
    public function testHttpsSocket($method)
311
    {
312
        if ($this->args['HTTPSSERVER'] == '')
313
        {
314
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https');
315
            return;
316
        }
317
318
        /// @todo investigate: can we make this work?
319
        ///       See changes in STREAM_CRYPTO_METHOD_TLS constants in 7.2 at https://wiki.php.net/rfc/improved-tls-constants
320
        ///       and in 5.6 at https://www.php.net/manual/en/migration56.openssl.php#migration56.openssl.crypto-method
321
        ///       Take into account also that the issue might in fact relate to the server-side (Apache) ssl config
322
        if (version_compare(PHP_VERSION, '7.2', '<'))
323
        {
324
            if (is_readable('/etc/os-release')) {
325
                $output = file_get_contents('/etc/os-release');
326
                preg_match('/VERSION="?([0-9]+)/', $output, $matches);
327
                $ubuntuVersion = @$matches[1];
328
            } else {
329
                exec('uname -a', $output, $retval);
330
                preg_match('/ubunutu([0-9]+)/', $output[0], $matches);
331
                $ubuntuVersion = @$matches[1];
332
            }
333
            if ($ubuntuVersion >= 20 && $this->args['SSLVERSION'] != 6) {
334
                $this->markTestSkipped('HTTPS via Socket known to fail on php less than 7.2 on Ubuntu 20 and higher');
335
                return;
336
            }
337
        }
338
339
        $this->client->server = $this->args['HTTPSSERVER'];
340
        $this->method = 'https';
341
        $this->client->method = 'https';
342
        $this->client->path = $this->args['HTTPSURI'];
343
        /// @todo replace with setOptions when dropping the BC layer
344
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyPeer() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

344
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
345
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyHost() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

345
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
346
        $this->client->setSSLVersion($this->args['SSLVERSION']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

346
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion($this->args['SSLVERSION']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
347
        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setUseCurl() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

347
        /** @scrutinizer ignore-deprecated */ $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
348
349
        if (version_compare(PHP_VERSION, '8.1', '>='))
350
        {
351
            $version = explode('.', PHP_VERSION);
352
            /// @see https://docs.openssl.org/1.1.1/man3/SSL_CTX_set_security_level/#default-callback-behaviour for levels
353
            $this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_SOCKET_OPTS,
354
                array('ssl' => array(
355
                    // security level is available as of php 7.2.0 + openssl 1.1.0 according to the docs
356
                    'security_level' => min(2 + $version[1], 5),
357
                    'capture_session_meta' => true,
358
                ))
359
            );
360
            /// @todo we should probably look deeper into the Apache config / ssl version in use to find out why this
361
            ///       does not work well with TLS < 1.2.
362
            /// @todo push this IF to the test matrix config, leave here only the setting of security_level?
363
            if ($this->args['SSLVERSION'] == 0) {
364
                $this->client->setSSLVersion(min(5 + $version[1], 7));
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

364
                /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion(min(5 + $version[1], 7));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
365
            }
366
        }
367
        $this->$method();
368
    }
369
370
    /**
371
     * @dataProvider getSingleHttpTestMethods
372
     * @param string $method
373
     */
374
    public function testHttpsProxyCurl($method)
375
    {
376
        if (!function_exists('curl_init'))
377
        {
378
            $this->markTestSkipped('CURL missing: cannot test https w. proxy');
379
            return;
380
        }
381
        else if ($this->args['PROXYSERVER'] == '')
382
        {
383
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https');
384
            return;
385
        }
386
        else if ($this->args['HTTPSSERVER'] == '')
387
        {
388
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy');
389
            return;
390
        }
391
392
        $this->method = 'https';
393
        $this->client->method = 'https';
394
        $this->client->server = $this->args['HTTPSSERVER'];
395
        $this->client->path = $this->args['HTTPSURI'];
396
        /// @todo replace with setOptions when dropping the BC layer
397
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
398
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyPeer() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

398
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
399
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyHost() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

399
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
400
        $this->client->setSSLVersion($this->args['SSLVERSION']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

400
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion($this->args['SSLVERSION']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
401
        /// @todo push this override to the test matrix config?
402
        if (version_compare(PHP_VERSION, '8.0', '>=') && $this->args['SSLVERSION'] == 0)
403
        {
404
            $version = explode('.', PHP_VERSION);
405
            $this->client->setSSLVersion(min(4 + $version[1], 7));
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

405
            /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion(min(4 + $version[1], 7));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
406
        }
407
408
        $this->$method();
409
    }
410
411
/*  NB: this is not yet supported by the Client class
412
    /**
413
     * @dataProvider getSingleHttpTestMethods
414
     * @param string $method
415
     * /
416
    public function testHttpsProxySocket($method)
417
    {
418
        if ($this->args['PROXYSERVER'] == '')
419
        {
420
            $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https');
421
            return;
422
        }
423
        else if ($this->args['HTTPSSERVER'] == '')
424
        {
425
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy');
426
            return;
427
        }
428
429
        if (version_compare(PHP_VERSION, '7.2', '<'))
430
        {
431
            if (is_readable('/etc/os-release')) {
432
                $output = file_get_contents('/etc/os-release');
433
                preg_match('/VERSION="?([0-9]+)/', $output, $matches);
434
                $ubuntuVersion = @$matches[1];
435
            } else {
436
                exec('uname -a', $output, $retval);
437
                preg_match('/ubunutu([0-9]+)/', $output[0], $matches);
438
                $ubuntuVersion = @$matches[1];
439
            }
440
            if ($ubuntuVersion >= 20 && $this->args['SSLVERSION'] != 6) {
441
                $this->markTestSkipped('HTTPS via Socket known to fail on php less than 7.2 on Ubuntu 20 and higher');
442
                return;
443
            }
444
        }
445
446
        $this->method = 'https';
447
        $this->client->method = 'https';
448
        $this->client->server = $this->args['HTTPSSERVER'];
449
        $this->client->path = $this->args['HTTPSURI'];
450
        /// @todo replace with setOptions when dropping the BC layer
451
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
452
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
453
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
454
        $this->client->setSSLVersion($this->args['SSLVERSION']);
455
        $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER);
456
        /// @todo push this override to the test matrix config?
457
        if (version_compare(PHP_VERSION, '8.1', '>=') && $this->args['SSLVERSION'] == 0)
458
        {
459
            $version = explode('.', PHP_VERSION);
460
            $this->client->setSSLVersion(min(5 + $version[1], 7));
461
        }
462
463
        $this->$method();
464
    }
465
*/
466
467
    /**
468
     * @dataProvider getSingleHttpTestMethods
469
     * @param string $method
470
     */
471
    public function testHttp2NoTls($method)
472
    {
473
        if (!function_exists('curl_init'))
474
        {
475
            $this->markTestSkipped('CURL missing: cannot test http/2');
476
            return;
477
        } else if (!defined('CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE'))
478
        {
479
            $this->markTestSkipped('CURL http/2 support missing: cannot test http/2');
480
            return;
481
        }
482
483
        $this->method = 'h2c'; // not an error the double assignment!
484
        $this->client->method = 'h2c';
485
        //$this->client->keepalive = false; // q: is this a good idea?
486
487
        $this->expectHttp2 = true;
488
        $this->$method();
489
        $this->expectHttp2 = false;
490
    }
491
492
    /**
493
     * @dataProvider getSingleHttpTestMethods
494
     * @param string $method
495
     */
496
    public function testHttp2tls($method)
497
    {
498
        if (!function_exists('curl_init'))
499
        {
500
            $this->markTestSkipped('CURL missing: cannot test http/2 tls');
501
            return;
502
        } else if ($this->args['HTTPSSERVER'] == '')
503
        {
504
            $this->markTestSkipped('HTTPS SERVER definition missing: cannot test http/2 tls');
505
            return;
506
        } else if (!defined('CURL_HTTP_VERSION_2_0'))
507
        {
508
            $this->markTestSkipped('CURL http/2 support missing: cannot test http/2 tls');
509
            return;
510
        }
511
512
        $this->method = 'h2';
513
        $this->client->method = 'h2';
514
        $this->client->server = $this->args['HTTPSSERVER'];
515
        $this->client->path = $this->args['HTTPSURI'];
516
        /// @todo replace with setOptions when dropping the BC layer
517
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyPeer() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

517
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
518
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVerifyHost() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

518
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
519
        $this->client->setSSLVersion($this->args['SSLVERSION']);
0 ignored issues
show
Deprecated Code introduced by
The function PhpXmlRpc\Client::setSSLVersion() has been deprecated: use setOption ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

519
        /** @scrutinizer ignore-deprecated */ $this->client->setSSLVersion($this->args['SSLVERSION']);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
520
521
        $this->expectHttp2 = true;
522
        $this->$method();
523
        $this->expectHttp2 = false;
524
    }
525
526
    /// @todo a better organization of tests could be to move the 4 tests below and all charset-related tests from
527
    ///       class ServerTest to a dedicated class - and make sure we iterate over each of those with different
528
    ///       proxy/auth/compression/etc... settings
529
530
    /**
531
     * @dataProvider getSingleHttpTestMethods
532
     * @param string $method
533
     */
534
    public function testUTF8Responses($method)
535
    {
536
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8'));
537
538
        $this->$method();
539
    }
540
541
    /**
542
     * @dataProvider getSingleHttpTestMethods
543
     * @param string $method
544
     */
545
    public function testUTF8Requests($method)
546
    {
547
        $this->client->request_charset_encoding = 'UTF-8';
0 ignored issues
show
Bug Best Practice introduced by
The property $request_charset_encoding is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
548
549
        $this->$method();
550
    }
551
552
    /**
553
     * @dataProvider getSingleHttpTestMethods
554
     * @param string $method
555
     */
556
    public function testISOResponses($method)
557
    {
558
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1'));
559
560
        $this->$method();
561
    }
562
563
    /**
564
     * @dataProvider getSingleHttpTestMethods
565
     * @param string $method
566
     */
567
    public function testISORequests($method)
568
    {
569
        $this->client->request_charset_encoding = 'ISO-8859-1';
0 ignored issues
show
Bug Best Practice introduced by
The property $request_charset_encoding is declared protected in PhpXmlRpc\Client. Since you implement __set, consider adding a @property or @property-write.
Loading history...
570
571
        $this->$method();
572
    }
573
574
    /**
575
     * @dataProvider getSingleHttpTestMethods
576
     * @param string $method
577
     */
578
    public function testBasicAuth($method)
579
    {
580
        $this->client->setCredentials('test', 'test');
581
        $this->addQueryParams(array('FORCE_AUTH' => 'Basic'));
582
583
        $this->$method();
584
    }
585
586
    /**
587
     * @dataProvider getSingleHttpTestMethods
588
     * @param string $method
589
     */
590
    public function testDigestAuth($method)
591
    {
592
        if (!function_exists('curl_init'))
593
        {
594
            $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
595
            return;
596
        }
597
598
        $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
599
        $this->addQueryParams(array('FORCE_AUTH' => 'Digest'));
600
        $this->method = 'http11';
601
        $this->client->method = 'http11';
602
603
        $this->$method();
604
    }
605
606
    /**
607
     * @dataProvider getAvailableUseCurlOptions
608
     */
609
    public function testTimeout($curlOpt)
610
    {
611
        $this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $curlOpt);
612
613
        // decrease the timeout to avoid slowing down the testsuite too much
614
        $this->timeout = 3;
615
616
        // the server will wait for 1 second before sending back the response - should pass
617
        $m = new xmlrpcmsg('tests.sleep', array(new xmlrpcval(1, 'int')));
618
        // this checks for a non-failed call
619
        $time = microtime(true);
620
        $this->send($m);
621
        $time = microtime(true) - $time;
622
        $this->assertGreaterThan(1.0, $time);
623
        $this->assertLessThan(2.0, $time);
624
625
        // the server will wait for 5 seconds before sending back the response - fail
626
        $m = new xmlrpcmsg('tests.sleep', array(new xmlrpcval(5, 'int')));
627
        $time = microtime(true);
628
        $r = $this->send($m, array(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['http_error'], PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['curl_fail']));
0 ignored issues
show
Unused Code introduced by
The assignment to $r is dead and can be removed.
Loading history...
629
        $time = microtime(true) - $time;
630
        $this->assertGreaterThan(2.0, $time);
631
        $this->assertLessThan(4.0, $time);
632
633
        /*
634
        // the server will send back the response one chunk per second, waiting 5 seconds in between chunks
635
        $m = new xmlrpcmsg('examples.addtwo', array(new xmlrpcval(1, 'int'), new xmlrpcval(2, 'int')));
636
        $this->addQueryParams(array('SLOW_LORIS' => 5));
637
        $time = microtime(true);
638
        $this->send($m, array(PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['http_error'], PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['curl_fail']));
639
        $time = microtime(true) - $time;
640
        $this->assertGreaterThan(2.0, $time);
641
        $this->assertLessThan(4.0, $time);
642
        */
643
644
        // pesky case: the server will send back the response one chunk per second, taking 10 seconds in total
645
        $m = new xmlrpcmsg('examples.addtwo', array(new xmlrpcval(1, 'int'), new xmlrpcval(2, 'int')));
646
        $this->addQueryParams(array('SLOW_LORIS' => 1));
647
        $time = microtime(true);
648
        $this->send($m, array(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['http_error'], PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['curl_fail']));
649
        $time = microtime(true) - $time;
650
        $this->assertGreaterThan(2.0, $time);
651
        $this->assertLessThan(4.0, $time);
652
    }
653
654
    /**
655
     * @param \PhpXmlRpc\Response $r
656
     * @return void
657
     */
658
    protected function validateResponse($r)
659
    {
660
        if ($this->expectHttp2) {
661
            $hr = $r->httpResponse();
662
            $this->assertEquals("2", @$hr['protocol_version'], 'Server response not using http version 2');
663
        }
664
    }
665
}
666