2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* @group Broken
|
|
|
|
|
*/
|
2010-12-28 18:17:16 +00:00
|
|
|
class HttpTest extends MediaWikiTestCase {
|
2011-06-01 22:13:47 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider cookieDomains
|
|
|
|
|
*/
|
2011-09-08 14:04:36 +00:00
|
|
|
function testValidateCookieDomain( $expected, $domain, $origin = null ) {
|
2011-06-01 22:13:47 +00:00
|
|
|
if ( $origin ) {
|
|
|
|
|
$ok = Cookie::validateCookieDomain( $domain, $origin );
|
|
|
|
|
$msg = "$domain against origin $origin";
|
|
|
|
|
} else {
|
|
|
|
|
$ok = Cookie::validateCookieDomain( $domain );
|
|
|
|
|
$msg = "$domain";
|
|
|
|
|
}
|
|
|
|
|
$this->assertEquals( $expected, $ok, $msg );
|
|
|
|
|
}
|
2011-09-08 14:04:36 +00:00
|
|
|
|
2011-06-01 22:13:47 +00:00
|
|
|
function cookieDomains() {
|
|
|
|
|
return array(
|
2011-06-01 22:27:24 +00:00
|
|
|
array( false, "org"),
|
|
|
|
|
array( false, ".org"),
|
|
|
|
|
array( true, "wikipedia.org"),
|
|
|
|
|
array( true, ".wikipedia.org"),
|
2011-06-01 22:13:47 +00:00
|
|
|
array( false, "co.uk" ),
|
|
|
|
|
array( false, ".co.uk" ),
|
|
|
|
|
array( false, "gov.uk" ),
|
|
|
|
|
array( false, ".gov.uk" ),
|
|
|
|
|
array( true, "supermarket.uk" ),
|
|
|
|
|
array( false, "uk" ),
|
|
|
|
|
array( false, ".uk" ),
|
|
|
|
|
array( false, "127.0.0." ),
|
|
|
|
|
array( false, "127." ),
|
|
|
|
|
array( false, "127.0.0.1." ),
|
|
|
|
|
array( true, "127.0.0.1" ),
|
|
|
|
|
array( false, "333.0.0.1" ),
|
|
|
|
|
array( true, "example.com" ),
|
|
|
|
|
array( false, "example.com." ),
|
|
|
|
|
array( true, ".example.com" ),
|
|
|
|
|
|
|
|
|
|
array( true, ".example.com", "www.example.com" ),
|
|
|
|
|
array( false, "example.com", "www.example.com" ),
|
|
|
|
|
array( true, "127.0.0.1", "127.0.0.1" ),
|
|
|
|
|
array( false, "127.0.0.1", "localhost" ),
|
|
|
|
|
);
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-05 16:15:39 +00:00
|
|
|
/**
|
|
|
|
|
* Test Http::isValidURI()
|
2011-10-26 04:15:09 +00:00
|
|
|
* @bug 27854 : Http::isValidURI is too lax
|
2011-09-08 14:04:36 +00:00
|
|
|
* @dataProvider provideURI
|
|
|
|
|
*/
|
2011-03-05 16:15:39 +00:00
|
|
|
function testIsValidUri( $expect, $URI, $message = '' ) {
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expect,
|
|
|
|
|
(bool) Http::isValidURI( $URI ),
|
|
|
|
|
$message
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Feeds URI to test a long regular expression in Http::isValidURI
|
|
|
|
|
*/
|
|
|
|
|
function provideURI() {
|
|
|
|
|
/** Format: 'boolean expectation', 'URI to test', 'Optional message' */
|
|
|
|
|
return array(
|
|
|
|
|
array( false, '¿non sens before!! http://a', 'Allow anything before URI' ),
|
|
|
|
|
|
2011-06-21 21:38:29 +00:00
|
|
|
# (http|https) - only two schemes allowed
|
2011-03-05 16:15:39 +00:00
|
|
|
array( true, 'http://www.example.org/' ),
|
|
|
|
|
array( true, 'https://www.example.org/' ),
|
|
|
|
|
array( true, 'http://www.example.org', 'URI without directory' ),
|
|
|
|
|
array( true, 'http://a', 'Short name' ),
|
|
|
|
|
array( true, 'http://étoile', 'Allow UTF-8 in hostname' ), # 'étoile' is french for 'star'
|
|
|
|
|
array( false, '\\host\directory', 'CIFS share' ),
|
|
|
|
|
array( false, 'gopher://host/dir', 'Reject gopher scheme' ),
|
|
|
|
|
array( false, 'telnet://host', 'Reject telnet scheme' ),
|
2011-10-26 04:15:09 +00:00
|
|
|
|
2011-03-05 16:15:39 +00:00
|
|
|
# :\/\/ - double slashes
|
2011-03-08 07:27:18 +00:00
|
|
|
array( false, 'http//example.org', 'Reject missing colon in protocol' ),
|
2011-03-05 16:15:39 +00:00
|
|
|
array( false, 'http:/example.org', 'Reject missing slash in protocol' ),
|
|
|
|
|
array( false, 'http:example.org', 'Must have two slashes' ),
|
|
|
|
|
# Following fail since hostname can be made of anything
|
|
|
|
|
array( false, 'http:///example.org', 'Must have exactly two slashes, not three' ),
|
|
|
|
|
|
|
|
|
|
# (\w+:{0,1}\w*@)? - optional user:pass
|
|
|
|
|
array( true, 'http://user@host', 'Username provided' ),
|
|
|
|
|
array( true, 'http://user:@host', 'Username provided, no password' ),
|
|
|
|
|
array( true, 'http://user:pass@host', 'Username and password provided' ),
|
|
|
|
|
|
|
|
|
|
# (\S+) - host part is made of anything not whitespaces
|
|
|
|
|
array( false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ),
|
2011-03-08 07:27:18 +00:00
|
|
|
array( false, 'http://exam:ple.org/', 'hostname can not use colons!' ),
|
2011-03-05 16:15:39 +00:00
|
|
|
|
|
|
|
|
# (:[0-9]+)? - port number
|
|
|
|
|
array( true, 'http://example.org:80/' ),
|
|
|
|
|
array( true, 'https://example.org:80/' ),
|
|
|
|
|
array( true, 'http://example.org:443/' ),
|
|
|
|
|
array( true, 'https://example.org:443/' ),
|
|
|
|
|
|
|
|
|
|
# Part after the hostname is / or / with something else
|
|
|
|
|
array( true, 'http://example/#' ),
|
|
|
|
|
array( true, 'http://example/!' ),
|
|
|
|
|
array( true, 'http://example/:' ),
|
|
|
|
|
array( true, 'http://example/.' ),
|
|
|
|
|
array( true, 'http://example/?' ),
|
|
|
|
|
array( true, 'http://example/+' ),
|
|
|
|
|
array( true, 'http://example/=' ),
|
|
|
|
|
array( true, 'http://example/&' ),
|
|
|
|
|
array( true, 'http://example/%' ),
|
|
|
|
|
array( true, 'http://example/@' ),
|
|
|
|
|
array( true, 'http://example/-' ),
|
|
|
|
|
array( true, 'http://example//' ),
|
|
|
|
|
array( true, 'http://example/&' ),
|
|
|
|
|
|
|
|
|
|
# Fragment
|
|
|
|
|
array( true, 'http://exam#ple.org', ), # This one is valid, really!
|
|
|
|
|
array( true, 'http://example.org:80#anchor' ),
|
|
|
|
|
array( true, 'http://example.org/?id#anchor' ),
|
|
|
|
|
array( true, 'http://example.org/?#anchor' ),
|
|
|
|
|
|
|
|
|
|
array( false, 'http://a ¿non !!sens after', 'Allow anything after URI' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|