Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / libs / IPSetTest.php
blob5bbacef42dade16fba081f9ee09417ba25f5fd26
1 <?php
3 /**
4 * @group IPSet
5 */
6 class IPSetTest extends PHPUnit_Framework_TestCase {
7 /**
8 * Provides test cases for IPSetTest::testIPSet
10 * Returns an array of test cases. Each case is an array of (description,
11 * config, tests). Description is just text output for failure messages,
12 * config is an array constructor argument for IPSet, and the tests are
13 * an array of IP => expected (boolean) result against the config dataset.
15 public static function provideIPSets() {
16 return array(
17 array(
18 'old_list_subset',
19 array(
20 '208.80.152.162',
21 '10.64.0.123',
22 '10.64.0.124',
23 '10.64.0.125',
24 '10.64.0.126',
25 '10.64.0.127',
26 '10.64.0.128',
27 '10.64.0.129',
28 '10.64.32.104',
29 '10.64.32.105',
30 '10.64.32.106',
31 '10.64.32.107',
32 '91.198.174.45',
33 '91.198.174.46',
34 '91.198.174.47',
35 '91.198.174.57',
36 '2620:0:862:1:A6BA:DBFF:FE30:CFB3',
37 '91.198.174.58',
38 '2620:0:862:1:A6BA:DBFF:FE38:FFDA',
39 '208.80.152.16',
40 '208.80.152.17',
41 '208.80.152.18',
42 '208.80.152.19',
43 '91.198.174.102',
44 '91.198.174.103',
45 '91.198.174.104',
46 '91.198.174.105',
47 '91.198.174.106',
48 '91.198.174.107',
49 '91.198.174.81',
50 '2620:0:862:1:26B6:FDFF:FEF5:B2D4',
51 '91.198.174.82',
52 '2620:0:862:1:26B6:FDFF:FEF5:ABB4',
53 '10.20.0.113',
54 '2620:0:862:102:26B6:FDFF:FEF5:AD9C',
55 '10.20.0.114',
56 '2620:0:862:102:26B6:FDFF:FEF5:7C38',
58 array(
59 '0.0.0.0' => false,
60 '255.255.255.255' => false,
61 '10.64.0.122' => false,
62 '10.64.0.123' => true,
63 '10.64.0.124' => true,
64 '10.64.0.129' => true,
65 '10.64.0.130' => false,
66 '91.198.174.81' => true,
67 '91.198.174.80' => false,
68 '0::0' => false,
69 'ffff:ffff:ffff:ffff:FFFF:FFFF:FFFF:FFFF' => false,
70 '2001:db8::1234' => false,
71 '2620:0:862:1:26b6:fdff:fef5:abb3' => false,
72 '2620:0:862:1:26b6:fdff:fef5:abb4' => true,
73 '2620:0:862:1:26b6:fdff:fef5:abb5' => false,
76 array(
77 'new_cidr_set',
78 array(
79 '208.80.154.0/26',
80 '2620:0:861:1::/64',
81 '208.80.154.128/26',
82 '2620:0:861:2::/64',
83 '208.80.154.64/26',
84 '2620:0:861:3::/64',
85 '208.80.155.96/27',
86 '2620:0:861:4::/64',
87 '10.64.0.0/22',
88 '2620:0:861:101::/64',
89 '10.64.16.0/22',
90 '2620:0:861:102::/64',
91 '10.64.32.0/22',
92 '2620:0:861:103::/64',
93 '10.64.48.0/22',
94 '2620:0:861:107::/64',
95 '91.198.174.0/25',
96 '2620:0:862:1::/64',
97 '10.20.0.0/24',
98 '2620:0:862:102::/64',
99 '10.128.0.0/24',
100 '2620:0:863:101::/64',
101 '10.2.4.26',
103 array(
104 '0.0.0.0' => false,
105 '255.255.255.255' => false,
106 '10.2.4.25' => false,
107 '10.2.4.26' => true,
108 '10.2.4.27' => false,
109 '10.20.0.255' => true,
110 '10.128.0.0' => true,
111 '10.64.17.55' => true,
112 '10.64.20.0' => false,
113 '10.64.27.207' => false,
114 '10.64.31.255' => false,
115 '0::0' => false,
116 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => false,
117 '2001:DB8::1' => false,
118 '2620:0:861:106::45' => false,
119 '2620:0:862:103::' => false,
120 '2620:0:862:102:10:20:0:113' => true,
123 array(
124 'empty_set',
125 array(),
126 array(
127 '0.0.0.0' => false,
128 '255.255.255.255' => false,
129 '10.2.4.25' => false,
130 '10.2.4.26' => false,
131 '10.2.4.27' => false,
132 '10.20.0.255' => false,
133 '10.128.0.0' => false,
134 '10.64.17.55' => false,
135 '10.64.20.0' => false,
136 '10.64.27.207' => false,
137 '10.64.31.255' => false,
138 '0::0' => false,
139 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => false,
140 '2001:DB8::1' => false,
141 '2620:0:861:106::45' => false,
142 '2620:0:862:103::' => false,
143 '2620:0:862:102:10:20:0:113' => false,
146 array(
147 'edge_cases',
148 array(
149 '0.0.0.0',
150 '255.255.255.255',
151 '::',
152 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
153 '10.10.10.10/25', // host bits intentional
155 array(
156 '0.0.0.0' => true,
157 '255.255.255.255' => true,
158 '10.2.4.25' => false,
159 '10.2.4.26' => false,
160 '10.2.4.27' => false,
161 '10.20.0.255' => false,
162 '10.128.0.0' => false,
163 '10.64.17.55' => false,
164 '10.64.20.0' => false,
165 '10.64.27.207' => false,
166 '10.64.31.255' => false,
167 '0::0' => true,
168 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => true,
169 '2001:DB8::1' => false,
170 '2620:0:861:106::45' => false,
171 '2620:0:862:103::' => false,
172 '2620:0:862:102:10:20:0:113' => false,
173 '10.10.9.255' => false,
174 '10.10.10.0' => true,
175 '10.10.10.1' => true,
176 '10.10.10.10' => true,
177 '10.10.10.126' => true,
178 '10.10.10.127' => true,
179 '10.10.10.128' => false,
180 '10.10.10.177' => false,
181 '10.10.10.255' => false,
182 '10.10.11.0' => false,
185 array(
186 'exercise_optimizer',
187 array(
188 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112',
189 'ffff:ffff:ffff:ffff:ffff:ffff:fffe:0/112',
190 'ffff:ffff:ffff:ffff:ffff:ffff:fffd:0/112',
191 'ffff:ffff:ffff:ffff:ffff:ffff:fffc:0/112',
192 'ffff:ffff:ffff:ffff:ffff:ffff:fffb:0/112',
193 'ffff:ffff:ffff:ffff:ffff:ffff:fffa:0/112',
194 'ffff:ffff:ffff:ffff:ffff:ffff:fff9:8000/113',
195 'ffff:ffff:ffff:ffff:ffff:ffff:fff9:0/113',
196 'ffff:ffff:ffff:ffff:ffff:ffff:fff8:0/112',
197 'ffff:ffff:ffff:ffff:ffff:ffff:fff7:0/112',
198 'ffff:ffff:ffff:ffff:ffff:ffff:fff6:0/112',
199 'ffff:ffff:ffff:ffff:ffff:ffff:fff5:0/112',
200 'ffff:ffff:ffff:ffff:ffff:ffff:fff4:0/112',
201 'ffff:ffff:ffff:ffff:ffff:ffff:fff3:0/112',
202 'ffff:ffff:ffff:ffff:ffff:ffff:fff2:0/112',
203 'ffff:ffff:ffff:ffff:ffff:ffff:fff1:0/112',
204 'ffff:ffff:ffff:ffff:ffff:ffff:fff0:0/112',
205 'ffff:ffff:ffff:ffff:ffff:ffff:ffef:0/112',
206 'ffff:ffff:ffff:ffff:ffff:ffff:ffee:0/112',
207 'ffff:ffff:ffff:ffff:ffff:ffff:ffec:0/111',
208 'ffff:ffff:ffff:ffff:ffff:ffff:ffeb:0/112',
209 'ffff:ffff:ffff:ffff:ffff:ffff:ffea:0/112',
210 'ffff:ffff:ffff:ffff:ffff:ffff:ffe9:0/112',
211 'ffff:ffff:ffff:ffff:ffff:ffff:ffe8:0/112',
212 'ffff:ffff:ffff:ffff:ffff:ffff:ffe7:0/112',
213 'ffff:ffff:ffff:ffff:ffff:ffff:ffe6:0/112',
214 'ffff:ffff:ffff:ffff:ffff:ffff:ffe5:0/112',
215 'ffff:ffff:ffff:ffff:ffff:ffff:ffe4:0/112',
216 'ffff:ffff:ffff:ffff:ffff:ffff:ffe3:0/112',
217 'ffff:ffff:ffff:ffff:ffff:ffff:ffe2:0/112',
218 'ffff:ffff:ffff:ffff:ffff:ffff:ffe1:0/112',
219 'ffff:ffff:ffff:ffff:ffff:ffff:ffe0:0/110',
220 'ffff:ffff:ffff:ffff:ffff:ffff:ffc0:0/107',
221 'ffff:ffff:ffff:ffff:ffff:ffff:ffa0:0/107',
223 array(
224 '0.0.0.0' => false,
225 '255.255.255.255' => false,
226 '::' => false,
227 'ffff:ffff:ffff:ffff:ffff:ffff:ff9f:ffff' => false,
228 'ffff:ffff:ffff:ffff:ffff:ffff:ffa0:0' => true,
229 'ffff:ffff:ffff:ffff:ffff:ffff:ffc0:1234' => true,
230 'ffff:ffff:ffff:ffff:ffff:ffff:ffed:ffff' => true,
231 'ffff:ffff:ffff:ffff:ffff:ffff:fff4:4444' => true,
232 'ffff:ffff:ffff:ffff:ffff:ffff:fff9:8080' => true,
233 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' => true,
240 * Validates IPSet loading and matching code
242 * @covers IPSet
243 * @dataProvider provideIPSets
245 public function testIPSet( $desc, array $cfg, array $tests ) {
246 $ipset = new IPSet( $cfg );
247 foreach ( $tests as $ip => $expected ) {
248 $result = $ipset->match( $ip );
249 $this->assertEquals( $expected, $result, "Incorrect match() result for $ip in dataset $desc" );