2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
2014-09-08 19:45:46 +00:00
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
/**
|
2019-05-13 10:38:00 +00:00
|
|
|
* @covers Http
|
2014-09-08 19:45:46 +00:00
|
|
|
* @group Http
|
2018-03-20 16:14:34 +00:00
|
|
|
* @group small
|
2010-12-14 16:26:35 +00:00
|
|
|
*/
|
2010-12-28 18:17:16 +00:00
|
|
|
class HttpTest extends MediaWikiTestCase {
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2011-03-05 16:15:39 +00:00
|
|
|
/**
|
|
|
|
|
* Test Http::isValidURI()
|
2017-02-20 23:45:58 +00:00
|
|
|
* T29854 : Http::isValidURI is too lax
|
2011-09-08 14:04:36 +00:00
|
|
|
* @dataProvider provideURI
|
2013-10-21 21:09:13 +00:00
|
|
|
* @covers Http::isValidURI
|
2011-09-08 14:04:36 +00:00
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
public function testIsValidUri( $expect, $URI, $message = '' ) {
|
2011-03-05 16:15:39 +00:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$expect,
|
2013-01-28 10:27:15 +00:00
|
|
|
(bool)Http::isValidURI( $URI ),
|
2011-03-05 16:15:39 +00:00
|
|
|
$message
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-25 15:10:19 +00:00
|
|
|
/**
|
|
|
|
|
* @covers Http::getProxy
|
|
|
|
|
*/
|
|
|
|
|
public function testGetProxy() {
|
2019-04-15 13:23:02 +00:00
|
|
|
$this->hideDeprecated( 'Http::getProxy' );
|
|
|
|
|
|
2017-03-29 00:21:15 +00:00
|
|
|
$this->setMwGlobals( 'wgHTTPProxy', false );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'',
|
|
|
|
|
Http::getProxy(),
|
|
|
|
|
'default setting'
|
|
|
|
|
);
|
|
|
|
|
|
2016-03-25 15:10:19 +00:00
|
|
|
$this->setMwGlobals( 'wgHTTPProxy', 'proxy.domain.tld' );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'proxy.domain.tld',
|
|
|
|
|
Http::getProxy()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-05 16:15:39 +00:00
|
|
|
/**
|
|
|
|
|
* Feeds URI to test a long regular expression in Http::isValidURI
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provideURI() {
|
2011-03-05 16:15:39 +00:00
|
|
|
/** Format: 'boolean expectation', 'URI to test', 'Optional message' */
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[ false, '¿non sens before!! http://a', 'Allow anything before URI' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
2011-06-21 21:38:29 +00:00
|
|
|
# (http|https) - only two schemes allowed
|
2016-02-17 09:09:32 +00:00
|
|
|
[ true, 'http://www.example.org/' ],
|
|
|
|
|
[ true, 'https://www.example.org/' ],
|
|
|
|
|
[ true, 'http://www.example.org', 'URI without directory' ],
|
|
|
|
|
[ true, 'http://a', 'Short name' ],
|
|
|
|
|
[ true, 'http://étoile', 'Allow UTF-8 in hostname' ], # 'étoile' is french for 'star'
|
|
|
|
|
[ false, '\\host\directory', 'CIFS share' ],
|
|
|
|
|
[ false, 'gopher://host/dir', 'Reject gopher scheme' ],
|
|
|
|
|
[ false, 'telnet://host', 'Reject telnet scheme' ],
|
2011-10-26 04:15:09 +00:00
|
|
|
|
2011-03-05 16:15:39 +00:00
|
|
|
# :\/\/ - double slashes
|
2016-02-17 09:09:32 +00:00
|
|
|
[ false, 'http//example.org', 'Reject missing colon in protocol' ],
|
|
|
|
|
[ false, 'http:/example.org', 'Reject missing slash in protocol' ],
|
|
|
|
|
[ false, 'http:example.org', 'Must have two slashes' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
# Following fail since hostname can be made of anything
|
2016-02-17 09:09:32 +00:00
|
|
|
[ false, 'http:///example.org', 'Must have exactly two slashes, not three' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
|
|
|
|
# (\w+:{0,1}\w*@)? - optional user:pass
|
2016-02-17 09:09:32 +00:00
|
|
|
[ true, 'http://user@host', 'Username provided' ],
|
|
|
|
|
[ true, 'http://user:@host', 'Username provided, no password' ],
|
|
|
|
|
[ true, 'http://user:pass@host', 'Username and password provided' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
|
|
|
|
# (\S+) - host part is made of anything not whitespaces
|
2014-09-08 19:45:46 +00:00
|
|
|
// commented these out in order to remove @group Broken
|
|
|
|
|
// @todo are these valid tests? if so, fix Http::isValidURI so it can handle them
|
2016-07-10 15:23:29 +00:00
|
|
|
// [ false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ],
|
|
|
|
|
// [ false, 'http://exam:ple.org/', 'hostname can not use colons!' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
|
|
|
|
# (:[0-9]+)? - port number
|
2016-02-17 09:09:32 +00:00
|
|
|
[ true, 'http://example.org:80/' ],
|
|
|
|
|
[ true, 'https://example.org:80/' ],
|
|
|
|
|
[ true, 'http://example.org:443/' ],
|
|
|
|
|
[ true, 'https://example.org:443/' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
|
|
|
|
# Part after the hostname is / or / with something else
|
2016-02-17 09:09:32 +00:00
|
|
|
[ true, 'http://example/#' ],
|
|
|
|
|
[ true, 'http://example/!' ],
|
|
|
|
|
[ true, 'http://example/:' ],
|
|
|
|
|
[ true, 'http://example/.' ],
|
|
|
|
|
[ true, 'http://example/?' ],
|
|
|
|
|
[ true, 'http://example/+' ],
|
|
|
|
|
[ true, 'http://example/=' ],
|
|
|
|
|
[ true, 'http://example/&' ],
|
|
|
|
|
[ true, 'http://example/%' ],
|
|
|
|
|
[ true, 'http://example/@' ],
|
|
|
|
|
[ true, 'http://example/-' ],
|
|
|
|
|
[ true, 'http://example//' ],
|
|
|
|
|
[ true, 'http://example/&' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
|
|
|
|
# Fragment
|
2016-02-17 09:09:32 +00:00
|
|
|
[ true, 'http://exam#ple.org', ], # This one is valid, really!
|
|
|
|
|
[ true, 'http://example.org:80#anchor' ],
|
|
|
|
|
[ true, 'http://example.org/?id#anchor' ],
|
|
|
|
|
[ true, 'http://example.org/?#anchor' ],
|
2011-03-05 16:15:39 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
[ false, 'http://a ¿non !!sens after', 'Allow anything after URI' ],
|
|
|
|
|
];
|
2011-03-05 16:15:39 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|