6 class IPSetTest
extends PHPUnit_Framework_TestCase
{
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() {
36 '2620:0:862:1:A6BA:DBFF:FE30:CFB3',
38 '2620:0:862:1:A6BA:DBFF:FE38:FFDA',
50 '2620:0:862:1:26B6:FDFF:FEF5:B2D4',
52 '2620:0:862:1:26B6:FDFF:FEF5:ABB4',
54 '2620:0:862:102:26B6:FDFF:FEF5:AD9C',
56 '2620:0:862:102:26B6:FDFF:FEF5:7C38',
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,
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,
88 '2620:0:861:101::/64',
90 '2620:0:861:102::/64',
92 '2620:0:861:103::/64',
94 '2620:0:861:107::/64',
98 '2620:0:862:102::/64',
100 '2620:0:863:101::/64',
105 '255.255.255.255' => false,
106 '10.2.4.25' => false,
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,
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,
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,
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,
152 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
153 '10.10.10.10/25', // host bits intentional
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,
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,
186 'exercise_optimizer',
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',
225 '255.255.255.255' => 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
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" );