Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / HttpTest.php
blobea4b6462e05b04157c09fdf23a79ba3932d74003
1 <?php
3 /**
4 * @group Http
5 */
6 class HttpTest extends MediaWikiTestCase {
7 /**
8 * @dataProvider cookieDomains
9 * @covers Cookie::validateCookieDomain
11 public function testValidateCookieDomain( $expected, $domain, $origin = null ) {
12 if ( $origin ) {
13 $ok = Cookie::validateCookieDomain( $domain, $origin );
14 $msg = "$domain against origin $origin";
15 } else {
16 $ok = Cookie::validateCookieDomain( $domain );
17 $msg = "$domain";
19 $this->assertEquals( $expected, $ok, $msg );
22 public static function cookieDomains() {
23 return array(
24 array( false, "org" ),
25 array( false, ".org" ),
26 array( true, "wikipedia.org" ),
27 array( true, ".wikipedia.org" ),
28 array( false, "co.uk" ),
29 array( false, ".co.uk" ),
30 array( false, "gov.uk" ),
31 array( false, ".gov.uk" ),
32 array( true, "supermarket.uk" ),
33 array( false, "uk" ),
34 array( false, ".uk" ),
35 array( false, "127.0.0." ),
36 array( false, "127." ),
37 array( false, "127.0.0.1." ),
38 array( true, "127.0.0.1" ),
39 array( false, "333.0.0.1" ),
40 array( true, "example.com" ),
41 array( false, "example.com." ),
42 array( true, ".example.com" ),
44 array( true, ".example.com", "www.example.com" ),
45 array( false, "example.com", "www.example.com" ),
46 array( true, "127.0.0.1", "127.0.0.1" ),
47 array( false, "127.0.0.1", "localhost" ),
51 /**
52 * Test Http::isValidURI()
53 * @bug 27854 : Http::isValidURI is too lax
54 * @dataProvider provideURI
55 * @covers Http::isValidURI
57 public function testIsValidUri( $expect, $URI, $message = '' ) {
58 $this->assertEquals(
59 $expect,
60 (bool)Http::isValidURI( $URI ),
61 $message
65 /**
66 * Feeds URI to test a long regular expression in Http::isValidURI
68 public static function provideURI() {
69 /** Format: 'boolean expectation', 'URI to test', 'Optional message' */
70 return array(
71 array( false, '¿non sens before!! http://a', 'Allow anything before URI' ),
73 # (http|https) - only two schemes allowed
74 array( true, 'http://www.example.org/' ),
75 array( true, 'https://www.example.org/' ),
76 array( true, 'http://www.example.org', 'URI without directory' ),
77 array( true, 'http://a', 'Short name' ),
78 array( true, 'http://étoile', 'Allow UTF-8 in hostname' ), # 'étoile' is french for 'star'
79 array( false, '\\host\directory', 'CIFS share' ),
80 array( false, 'gopher://host/dir', 'Reject gopher scheme' ),
81 array( false, 'telnet://host', 'Reject telnet scheme' ),
83 # :\/\/ - double slashes
84 array( false, 'http//example.org', 'Reject missing colon in protocol' ),
85 array( false, 'http:/example.org', 'Reject missing slash in protocol' ),
86 array( false, 'http:example.org', 'Must have two slashes' ),
87 # Following fail since hostname can be made of anything
88 array( false, 'http:///example.org', 'Must have exactly two slashes, not three' ),
90 # (\w+:{0,1}\w*@)? - optional user:pass
91 array( true, 'http://user@host', 'Username provided' ),
92 array( true, 'http://user:@host', 'Username provided, no password' ),
93 array( true, 'http://user:pass@host', 'Username and password provided' ),
95 # (\S+) - host part is made of anything not whitespaces
96 // commented these out in order to remove @group Broken
97 // @todo are these valid tests? if so, fix Http::isValidURI so it can handle them
98 // array( false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ),
99 // array( false, 'http://exam:ple.org/', 'hostname can not use colons!' ),
101 # (:[0-9]+)? - port number
102 array( true, 'http://example.org:80/' ),
103 array( true, 'https://example.org:80/' ),
104 array( true, 'http://example.org:443/' ),
105 array( true, 'https://example.org:443/' ),
107 # Part after the hostname is / or / with something else
108 array( true, 'http://example/#' ),
109 array( true, 'http://example/!' ),
110 array( true, 'http://example/:' ),
111 array( true, 'http://example/.' ),
112 array( true, 'http://example/?' ),
113 array( true, 'http://example/+' ),
114 array( true, 'http://example/=' ),
115 array( true, 'http://example/&' ),
116 array( true, 'http://example/%' ),
117 array( true, 'http://example/@' ),
118 array( true, 'http://example/-' ),
119 array( true, 'http://example//' ),
120 array( true, 'http://example/&' ),
122 # Fragment
123 array( true, 'http://exam#ple.org', ), # This one is valid, really!
124 array( true, 'http://example.org:80#anchor' ),
125 array( true, 'http://example.org/?id#anchor' ),
126 array( true, 'http://example.org/?#anchor' ),
128 array( false, 'http://a ¿non !!sens after', 'Allow anything after URI' ),
133 * Warning:
135 * These tests are for code that makes use of an artifact of how CURL
136 * handles header reporting on redirect pages, and will need to be
137 * rewritten when bug 29232 is taken care of (high-level handling of
138 * HTTP redirects).
140 public function testRelativeRedirections() {
141 $h = MWHttpRequestTester::factory( 'http://oldsite/file.ext', array(), __METHOD__ );
143 # Forge a Location header
144 $h->setRespHeaders( 'location', array(
145 'http://newsite/file.ext',
146 '/newfile.ext',
149 # Verify we correctly fix the Location
150 $this->assertEquals(
151 'http://newsite/newfile.ext',
152 $h->getFinalUrl(),
153 "Relative file path Location: interpreted as full URL"
156 $h->setRespHeaders( 'location', array(
157 'https://oldsite/file.ext'
160 $this->assertEquals(
161 'https://oldsite/file.ext',
162 $h->getFinalUrl(),
163 "Location to the HTTPS version of the site"
166 $h->setRespHeaders( 'location', array(
167 '/anotherfile.ext',
168 'http://anotherfile/hoster.ext',
169 'https://anotherfile/hoster.ext'
172 $this->assertEquals(
173 'https://anotherfile/hoster.ext',
174 $h->getFinalUrl( "Relative file path Location: should keep the latest host and scheme!" )
179 * Constant values are from PHP 5.3.28 using cURL 7.24.0
180 * @see http://php.net/manual/en/curl.constants.php
182 * All constant values are present so that developers don’t need to remember
183 * to add them if added at a later date. The commented out constants were
184 * not found anywhere in the MediaWiki core code.
186 * Commented out constants that were not available in:
187 * HipHop VM 3.3.0 (rel)
188 * Compiler: heads/master-0-g08810d920dfff59e0774cf2d651f92f13a637175
189 * Repo schema: 3214fc2c684a4520485f715ee45f33f2182324b1
190 * Extension API: 20140829
192 * Commented out constants that were removed in PHP 5.6.0
194 * @covers CurlHttpRequest::execute
196 public function provideCurlConstants() {
197 return array(
198 array( 'CURLAUTH_ANY' ),
199 array( 'CURLAUTH_ANYSAFE' ),
200 array( 'CURLAUTH_BASIC' ),
201 array( 'CURLAUTH_DIGEST' ),
202 array( 'CURLAUTH_GSSNEGOTIATE' ),
203 array( 'CURLAUTH_NTLM' ),
204 // array( 'CURLCLOSEPOLICY_CALLBACK' ), // removed in PHP 5.6.0
205 // array( 'CURLCLOSEPOLICY_LEAST_RECENTLY_USED' ), // removed in PHP 5.6.0
206 // array( 'CURLCLOSEPOLICY_LEAST_TRAFFIC' ), // removed in PHP 5.6.0
207 // array( 'CURLCLOSEPOLICY_OLDEST' ), // removed in PHP 5.6.0
208 // array( 'CURLCLOSEPOLICY_SLOWEST' ), // removed in PHP 5.6.0
209 array( 'CURLE_ABORTED_BY_CALLBACK' ),
210 array( 'CURLE_BAD_CALLING_ORDER' ),
211 array( 'CURLE_BAD_CONTENT_ENCODING' ),
212 array( 'CURLE_BAD_FUNCTION_ARGUMENT' ),
213 array( 'CURLE_BAD_PASSWORD_ENTERED' ),
214 array( 'CURLE_COULDNT_CONNECT' ),
215 array( 'CURLE_COULDNT_RESOLVE_HOST' ),
216 array( 'CURLE_COULDNT_RESOLVE_PROXY' ),
217 array( 'CURLE_FAILED_INIT' ),
218 array( 'CURLE_FILESIZE_EXCEEDED' ),
219 array( 'CURLE_FILE_COULDNT_READ_FILE' ),
220 array( 'CURLE_FTP_ACCESS_DENIED' ),
221 array( 'CURLE_FTP_BAD_DOWNLOAD_RESUME' ),
222 array( 'CURLE_FTP_CANT_GET_HOST' ),
223 array( 'CURLE_FTP_CANT_RECONNECT' ),
224 array( 'CURLE_FTP_COULDNT_GET_SIZE' ),
225 array( 'CURLE_FTP_COULDNT_RETR_FILE' ),
226 array( 'CURLE_FTP_COULDNT_SET_ASCII' ),
227 array( 'CURLE_FTP_COULDNT_SET_BINARY' ),
228 array( 'CURLE_FTP_COULDNT_STOR_FILE' ),
229 array( 'CURLE_FTP_COULDNT_USE_REST' ),
230 array( 'CURLE_FTP_PORT_FAILED' ),
231 array( 'CURLE_FTP_QUOTE_ERROR' ),
232 array( 'CURLE_FTP_SSL_FAILED' ),
233 array( 'CURLE_FTP_USER_PASSWORD_INCORRECT' ),
234 array( 'CURLE_FTP_WEIRD_227_FORMAT' ),
235 array( 'CURLE_FTP_WEIRD_PASS_REPLY' ),
236 array( 'CURLE_FTP_WEIRD_PASV_REPLY' ),
237 array( 'CURLE_FTP_WEIRD_SERVER_REPLY' ),
238 array( 'CURLE_FTP_WEIRD_USER_REPLY' ),
239 array( 'CURLE_FTP_WRITE_ERROR' ),
240 array( 'CURLE_FUNCTION_NOT_FOUND' ),
241 array( 'CURLE_GOT_NOTHING' ),
242 array( 'CURLE_HTTP_NOT_FOUND' ),
243 array( 'CURLE_HTTP_PORT_FAILED' ),
244 array( 'CURLE_HTTP_POST_ERROR' ),
245 array( 'CURLE_HTTP_RANGE_ERROR' ),
246 array( 'CURLE_LDAP_CANNOT_BIND' ),
247 array( 'CURLE_LDAP_INVALID_URL' ),
248 array( 'CURLE_LDAP_SEARCH_FAILED' ),
249 array( 'CURLE_LIBRARY_NOT_FOUND' ),
250 array( 'CURLE_MALFORMAT_USER' ),
251 array( 'CURLE_OBSOLETE' ),
252 array( 'CURLE_OK' ),
253 array( 'CURLE_OPERATION_TIMEOUTED' ),
254 array( 'CURLE_OUT_OF_MEMORY' ),
255 array( 'CURLE_PARTIAL_FILE' ),
256 array( 'CURLE_READ_ERROR' ),
257 array( 'CURLE_RECV_ERROR' ),
258 array( 'CURLE_SEND_ERROR' ),
259 array( 'CURLE_SHARE_IN_USE' ),
260 // array( 'CURLE_SSH' ), // not present in HHVM 3.3.0-dev
261 array( 'CURLE_SSL_CACERT' ),
262 array( 'CURLE_SSL_CERTPROBLEM' ),
263 array( 'CURLE_SSL_CIPHER' ),
264 array( 'CURLE_SSL_CONNECT_ERROR' ),
265 array( 'CURLE_SSL_ENGINE_NOTFOUND' ),
266 array( 'CURLE_SSL_ENGINE_SETFAILED' ),
267 array( 'CURLE_SSL_PEER_CERTIFICATE' ),
268 array( 'CURLE_TELNET_OPTION_SYNTAX' ),
269 array( 'CURLE_TOO_MANY_REDIRECTS' ),
270 array( 'CURLE_UNKNOWN_TELNET_OPTION' ),
271 array( 'CURLE_UNSUPPORTED_PROTOCOL' ),
272 array( 'CURLE_URL_MALFORMAT' ),
273 array( 'CURLE_URL_MALFORMAT_USER' ),
274 array( 'CURLE_WRITE_ERROR' ),
275 array( 'CURLFTPAUTH_DEFAULT' ),
276 array( 'CURLFTPAUTH_SSL' ),
277 array( 'CURLFTPAUTH_TLS' ),
278 // array( 'CURLFTPMETHOD_MULTICWD' ), // not present in HHVM 3.3.0-dev
279 // array( 'CURLFTPMETHOD_NOCWD' ), // not present in HHVM 3.3.0-dev
280 // array( 'CURLFTPMETHOD_SINGLECWD' ), // not present in HHVM 3.3.0-dev
281 array( 'CURLFTPSSL_ALL' ),
282 array( 'CURLFTPSSL_CONTROL' ),
283 array( 'CURLFTPSSL_NONE' ),
284 array( 'CURLFTPSSL_TRY' ),
285 // array( 'CURLINFO_CERTINFO' ), // not present in HHVM 3.3.0-dev
286 array( 'CURLINFO_CONNECT_TIME' ),
287 array( 'CURLINFO_CONTENT_LENGTH_DOWNLOAD' ),
288 array( 'CURLINFO_CONTENT_LENGTH_UPLOAD' ),
289 array( 'CURLINFO_CONTENT_TYPE' ),
290 array( 'CURLINFO_EFFECTIVE_URL' ),
291 array( 'CURLINFO_FILETIME' ),
292 array( 'CURLINFO_HEADER_OUT' ),
293 array( 'CURLINFO_HEADER_SIZE' ),
294 array( 'CURLINFO_HTTP_CODE' ),
295 array( 'CURLINFO_NAMELOOKUP_TIME' ),
296 array( 'CURLINFO_PRETRANSFER_TIME' ),
297 array( 'CURLINFO_PRIVATE' ),
298 array( 'CURLINFO_REDIRECT_COUNT' ),
299 array( 'CURLINFO_REDIRECT_TIME' ),
300 // array( 'CURLINFO_REDIRECT_URL' ), // not present in HHVM 3.3.0-dev
301 array( 'CURLINFO_REQUEST_SIZE' ),
302 array( 'CURLINFO_SIZE_DOWNLOAD' ),
303 array( 'CURLINFO_SIZE_UPLOAD' ),
304 array( 'CURLINFO_SPEED_DOWNLOAD' ),
305 array( 'CURLINFO_SPEED_UPLOAD' ),
306 array( 'CURLINFO_SSL_VERIFYRESULT' ),
307 array( 'CURLINFO_STARTTRANSFER_TIME' ),
308 array( 'CURLINFO_TOTAL_TIME' ),
309 array( 'CURLMSG_DONE' ),
310 array( 'CURLM_BAD_EASY_HANDLE' ),
311 array( 'CURLM_BAD_HANDLE' ),
312 array( 'CURLM_CALL_MULTI_PERFORM' ),
313 array( 'CURLM_INTERNAL_ERROR' ),
314 array( 'CURLM_OK' ),
315 array( 'CURLM_OUT_OF_MEMORY' ),
316 array( 'CURLOPT_AUTOREFERER' ),
317 array( 'CURLOPT_BINARYTRANSFER' ),
318 array( 'CURLOPT_BUFFERSIZE' ),
319 array( 'CURLOPT_CAINFO' ),
320 array( 'CURLOPT_CAPATH' ),
321 // array( 'CURLOPT_CERTINFO' ), // not present in HHVM 3.3.0-dev
322 // array( 'CURLOPT_CLOSEPOLICY' ), // removed in PHP 5.6.0
323 array( 'CURLOPT_CONNECTTIMEOUT' ),
324 array( 'CURLOPT_CONNECTTIMEOUT_MS' ),
325 array( 'CURLOPT_COOKIE' ),
326 array( 'CURLOPT_COOKIEFILE' ),
327 array( 'CURLOPT_COOKIEJAR' ),
328 array( 'CURLOPT_COOKIESESSION' ),
329 array( 'CURLOPT_CRLF' ),
330 array( 'CURLOPT_CUSTOMREQUEST' ),
331 array( 'CURLOPT_DNS_CACHE_TIMEOUT' ),
332 array( 'CURLOPT_DNS_USE_GLOBAL_CACHE' ),
333 array( 'CURLOPT_EGDSOCKET' ),
334 array( 'CURLOPT_ENCODING' ),
335 array( 'CURLOPT_FAILONERROR' ),
336 array( 'CURLOPT_FILE' ),
337 array( 'CURLOPT_FILETIME' ),
338 array( 'CURLOPT_FOLLOWLOCATION' ),
339 array( 'CURLOPT_FORBID_REUSE' ),
340 array( 'CURLOPT_FRESH_CONNECT' ),
341 array( 'CURLOPT_FTPAPPEND' ),
342 array( 'CURLOPT_FTPLISTONLY' ),
343 array( 'CURLOPT_FTPPORT' ),
344 array( 'CURLOPT_FTPSSLAUTH' ),
345 array( 'CURLOPT_FTP_CREATE_MISSING_DIRS' ),
346 // array( 'CURLOPT_FTP_FILEMETHOD' ), // not present in HHVM 3.3.0-dev
347 // array( 'CURLOPT_FTP_SKIP_PASV_IP' ), // not present in HHVM 3.3.0-dev
348 array( 'CURLOPT_FTP_SSL' ),
349 array( 'CURLOPT_FTP_USE_EPRT' ),
350 array( 'CURLOPT_FTP_USE_EPSV' ),
351 array( 'CURLOPT_HEADER' ),
352 array( 'CURLOPT_HEADERFUNCTION' ),
353 array( 'CURLOPT_HTTP200ALIASES' ),
354 array( 'CURLOPT_HTTPAUTH' ),
355 array( 'CURLOPT_HTTPGET' ),
356 array( 'CURLOPT_HTTPHEADER' ),
357 array( 'CURLOPT_HTTPPROXYTUNNEL' ),
358 array( 'CURLOPT_HTTP_VERSION' ),
359 array( 'CURLOPT_INFILE' ),
360 array( 'CURLOPT_INFILESIZE' ),
361 array( 'CURLOPT_INTERFACE' ),
362 array( 'CURLOPT_IPRESOLVE' ),
363 // array( 'CURLOPT_KEYPASSWD' ), // not present in HHVM 3.3.0-dev
364 array( 'CURLOPT_KRB4LEVEL' ),
365 array( 'CURLOPT_LOW_SPEED_LIMIT' ),
366 array( 'CURLOPT_LOW_SPEED_TIME' ),
367 array( 'CURLOPT_MAXCONNECTS' ),
368 array( 'CURLOPT_MAXREDIRS' ),
369 // array( 'CURLOPT_MAX_RECV_SPEED_LARGE' ), // not present in HHVM 3.3.0-dev
370 // array( 'CURLOPT_MAX_SEND_SPEED_LARGE' ), // not present in HHVM 3.3.0-dev
371 array( 'CURLOPT_NETRC' ),
372 array( 'CURLOPT_NOBODY' ),
373 array( 'CURLOPT_NOPROGRESS' ),
374 array( 'CURLOPT_NOSIGNAL' ),
375 array( 'CURLOPT_PORT' ),
376 array( 'CURLOPT_POST' ),
377 array( 'CURLOPT_POSTFIELDS' ),
378 array( 'CURLOPT_POSTQUOTE' ),
379 array( 'CURLOPT_POSTREDIR' ),
380 array( 'CURLOPT_PRIVATE' ),
381 array( 'CURLOPT_PROGRESSFUNCTION' ),
382 // array( 'CURLOPT_PROTOCOLS' ), // not present in HHVM 3.3.0-dev
383 array( 'CURLOPT_PROXY' ),
384 array( 'CURLOPT_PROXYAUTH' ),
385 array( 'CURLOPT_PROXYPORT' ),
386 array( 'CURLOPT_PROXYTYPE' ),
387 array( 'CURLOPT_PROXYUSERPWD' ),
388 array( 'CURLOPT_PUT' ),
389 array( 'CURLOPT_QUOTE' ),
390 array( 'CURLOPT_RANDOM_FILE' ),
391 array( 'CURLOPT_RANGE' ),
392 array( 'CURLOPT_READDATA' ),
393 array( 'CURLOPT_READFUNCTION' ),
394 // array( 'CURLOPT_REDIR_PROTOCOLS' ), // not present in HHVM 3.3.0-dev
395 array( 'CURLOPT_REFERER' ),
396 array( 'CURLOPT_RESUME_FROM' ),
397 array( 'CURLOPT_RETURNTRANSFER' ),
398 // array( 'CURLOPT_SSH_AUTH_TYPES' ), // not present in HHVM 3.3.0-dev
399 // array( 'CURLOPT_SSH_HOST_PUBLIC_KEY_MD5' ), // not present in HHVM 3.3.0-dev
400 // array( 'CURLOPT_SSH_PRIVATE_KEYFILE' ), // not present in HHVM 3.3.0-dev
401 // array( 'CURLOPT_SSH_PUBLIC_KEYFILE' ), // not present in HHVM 3.3.0-dev
402 array( 'CURLOPT_SSLCERT' ),
403 array( 'CURLOPT_SSLCERTPASSWD' ),
404 array( 'CURLOPT_SSLCERTTYPE' ),
405 array( 'CURLOPT_SSLENGINE' ),
406 array( 'CURLOPT_SSLENGINE_DEFAULT' ),
407 array( 'CURLOPT_SSLKEY' ),
408 array( 'CURLOPT_SSLKEYPASSWD' ),
409 array( 'CURLOPT_SSLKEYTYPE' ),
410 array( 'CURLOPT_SSLVERSION' ),
411 array( 'CURLOPT_SSL_CIPHER_LIST' ),
412 array( 'CURLOPT_SSL_VERIFYHOST' ),
413 array( 'CURLOPT_SSL_VERIFYPEER' ),
414 array( 'CURLOPT_STDERR' ),
415 array( 'CURLOPT_TCP_NODELAY' ),
416 array( 'CURLOPT_TIMECONDITION' ),
417 array( 'CURLOPT_TIMEOUT' ),
418 array( 'CURLOPT_TIMEOUT_MS' ),
419 array( 'CURLOPT_TIMEVALUE' ),
420 array( 'CURLOPT_TRANSFERTEXT' ),
421 array( 'CURLOPT_UNRESTRICTED_AUTH' ),
422 array( 'CURLOPT_UPLOAD' ),
423 array( 'CURLOPT_URL' ),
424 array( 'CURLOPT_USERAGENT' ),
425 array( 'CURLOPT_USERPWD' ),
426 array( 'CURLOPT_VERBOSE' ),
427 array( 'CURLOPT_WRITEFUNCTION' ),
428 array( 'CURLOPT_WRITEHEADER' ),
429 // array( 'CURLPROTO_ALL' ), // not present in HHVM 3.3.0-dev
430 // array( 'CURLPROTO_DICT' ), // not present in HHVM 3.3.0-dev
431 // array( 'CURLPROTO_FILE' ), // not present in HHVM 3.3.0-dev
432 // array( 'CURLPROTO_FTP' ), // not present in HHVM 3.3.0-dev
433 // array( 'CURLPROTO_FTPS' ), // not present in HHVM 3.3.0-dev
434 // array( 'CURLPROTO_HTTP' ), // not present in HHVM 3.3.0-dev
435 // array( 'CURLPROTO_HTTPS' ), // not present in HHVM 3.3.0-dev
436 // array( 'CURLPROTO_LDAP' ), // not present in HHVM 3.3.0-dev
437 // array( 'CURLPROTO_LDAPS' ), // not present in HHVM 3.3.0-dev
438 // array( 'CURLPROTO_SCP' ), // not present in HHVM 3.3.0-dev
439 // array( 'CURLPROTO_SFTP' ), // not present in HHVM 3.3.0-dev
440 // array( 'CURLPROTO_TELNET' ), // not present in HHVM 3.3.0-dev
441 // array( 'CURLPROTO_TFTP' ), // not present in HHVM 3.3.0-dev
442 array( 'CURLPROXY_HTTP' ),
443 // array( 'CURLPROXY_SOCKS4' ), // not present in HHVM 3.3.0-dev
444 array( 'CURLPROXY_SOCKS5' ),
445 // array( 'CURLSSH_AUTH_DEFAULT' ), // not present in HHVM 3.3.0-dev
446 // array( 'CURLSSH_AUTH_HOST' ), // not present in HHVM 3.3.0-dev
447 // array( 'CURLSSH_AUTH_KEYBOARD' ), // not present in HHVM 3.3.0-dev
448 // array( 'CURLSSH_AUTH_NONE' ), // not present in HHVM 3.3.0-dev
449 // array( 'CURLSSH_AUTH_PASSWORD' ), // not present in HHVM 3.3.0-dev
450 // array( 'CURLSSH_AUTH_PUBLICKEY' ), // not present in HHVM 3.3.0-dev
451 array( 'CURLVERSION_NOW' ),
452 array( 'CURL_HTTP_VERSION_1_0' ),
453 array( 'CURL_HTTP_VERSION_1_1' ),
454 array( 'CURL_HTTP_VERSION_NONE' ),
455 array( 'CURL_IPRESOLVE_V4' ),
456 array( 'CURL_IPRESOLVE_V6' ),
457 array( 'CURL_IPRESOLVE_WHATEVER' ),
458 array( 'CURL_NETRC_IGNORED' ),
459 array( 'CURL_NETRC_OPTIONAL' ),
460 array( 'CURL_NETRC_REQUIRED' ),
461 array( 'CURL_TIMECOND_IFMODSINCE' ),
462 array( 'CURL_TIMECOND_IFUNMODSINCE' ),
463 array( 'CURL_TIMECOND_LASTMOD' ),
464 array( 'CURL_VERSION_IPV6' ),
465 array( 'CURL_VERSION_KERBEROS4' ),
466 array( 'CURL_VERSION_LIBZ' ),
467 array( 'CURL_VERSION_SSL' ),
472 * Added this test based on an issue experienced with HHVM 3.3.0-dev
473 * where it did not define a cURL constant.
475 * @bug 70570
476 * @dataProvider provideCurlConstants
478 public function testCurlConstants( $value ) {
479 $this->assertTrue( defined( $value ), $value . ' not defined' );
484 * Class to let us overwrite MWHttpRequest respHeaders variable
486 class MWHttpRequestTester extends MWHttpRequest {
487 // function derived from the MWHttpRequest factory function but
488 // returns appropriate tester class here
489 public static function factory( $url, $options = null, $caller = __METHOD__ ) {
490 if ( !Http::$httpEngine ) {
491 Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
492 } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
493 throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' .
494 'Http::$httpEngine is set to "curl"' );
497 switch ( Http::$httpEngine ) {
498 case 'curl':
499 return new CurlHttpRequestTester( $url, $options, $caller );
500 case 'php':
501 if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
502 throw new MWException( __METHOD__ .
503 ': allow_url_fopen needs to be enabled for pure PHP HTTP requests to work. '
504 . 'If possible, curl should be used instead. See http://php.net/curl.' );
507 return new PhpHttpRequestTester( $url, $options, $caller );
508 default:
513 class CurlHttpRequestTester extends CurlHttpRequest {
514 function setRespHeaders( $name, $value ) {
515 $this->respHeaders[$name] = $value;
519 class PhpHttpRequestTester extends PhpHttpRequest {
520 function setRespHeaders( $name, $value ) {
521 $this->respHeaders[$name] = $value;