Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / tests / phpunit / includes / http / HttpTest.php
1 <?php
2
3 /**
4 * @covers Http
5 * @group Http
6 * @group small
7 */
8 class HttpTest extends MediaWikiTestCase {
9
10 /**
11 * Test Http::isValidURI()
12 * T29854 : Http::isValidURI is too lax
13 * @dataProvider provideURI
14 * @covers Http::isValidURI
15 */
16 public function testIsValidUri( $expect, $URI, $message = '' ) {
17 $this->assertEquals(
18 $expect,
19 (bool)Http::isValidURI( $URI ),
20 $message
21 );
22 }
23
24 /**
25 * @covers Http::getProxy
26 */
27 public function testGetProxy() {
28 $this->hideDeprecated( 'Http::getProxy' );
29
30 $this->setMwGlobals( 'wgHTTPProxy', false );
31 $this->assertEquals(
32 '',
33 Http::getProxy(),
34 'default setting'
35 );
36
37 $this->setMwGlobals( 'wgHTTPProxy', 'proxy.domain.tld' );
38 $this->assertEquals(
39 'proxy.domain.tld',
40 Http::getProxy()
41 );
42 }
43
44 /**
45 * Feeds URI to test a long regular expression in Http::isValidURI
46 */
47 public static function provideURI() {
48 /** Format: 'boolean expectation', 'URI to test', 'Optional message' */
49 return [
50 [ false, '¿non sens before!! http://a', 'Allow anything before URI' ],
51
52 # (http|https) - only two schemes allowed
53 [ true, 'http://www.example.org/' ],
54 [ true, 'https://www.example.org/' ],
55 [ true, 'http://www.example.org', 'URI without directory' ],
56 [ true, 'http://a', 'Short name' ],
57 [ true, 'http://étoile', 'Allow UTF-8 in hostname' ], # 'étoile' is french for 'star'
58 [ false, '\\host\directory', 'CIFS share' ],
59 [ false, 'gopher://host/dir', 'Reject gopher scheme' ],
60 [ false, 'telnet://host', 'Reject telnet scheme' ],
61
62 # :\/\/ - double slashes
63 [ false, 'http//example.org', 'Reject missing colon in protocol' ],
64 [ false, 'http:/example.org', 'Reject missing slash in protocol' ],
65 [ false, 'http:example.org', 'Must have two slashes' ],
66 # Following fail since hostname can be made of anything
67 [ false, 'http:///example.org', 'Must have exactly two slashes, not three' ],
68
69 # (\w+:{0,1}\w*@)? - optional user:pass
70 [ true, 'http://user@host', 'Username provided' ],
71 [ true, 'http://user:@host', 'Username provided, no password' ],
72 [ true, 'http://user:pass@host', 'Username and password provided' ],
73
74 # (\S+) - host part is made of anything not whitespaces
75 // commented these out in order to remove @group Broken
76 // @todo are these valid tests? if so, fix Http::isValidURI so it can handle them
77 // [ false, 'http://!"èèè¿¿¿~~\'', 'hostname is made of any non whitespace' ],
78 // [ false, 'http://exam:ple.org/', 'hostname can not use colons!' ],
79
80 # (:[0-9]+)? - port number
81 [ true, 'http://example.org:80/' ],
82 [ true, 'https://example.org:80/' ],
83 [ true, 'http://example.org:443/' ],
84 [ true, 'https://example.org:443/' ],
85
86 # Part after the hostname is / or / with something else
87 [ true, 'http://example/#' ],
88 [ true, 'http://example/!' ],
89 [ true, 'http://example/:' ],
90 [ true, 'http://example/.' ],
91 [ true, 'http://example/?' ],
92 [ true, 'http://example/+' ],
93 [ true, 'http://example/=' ],
94 [ true, 'http://example/&' ],
95 [ true, 'http://example/%' ],
96 [ true, 'http://example/@' ],
97 [ true, 'http://example/-' ],
98 [ true, 'http://example//' ],
99 [ true, 'http://example/&' ],
100
101 # Fragment
102 [ true, 'http://exam#ple.org', ], # This one is valid, really!
103 [ true, 'http://example.org:80#anchor' ],
104 [ true, 'http://example.org/?id#anchor' ],
105 [ true, 'http://example.org/?#anchor' ],
106
107 [ false, 'http://a ¿non !!sens after', 'Allow anything after URI' ],
108 ];
109 }
110
111 }