- Timestamp:
- 05/02/2018 12:48:23 AM (6 years ago)
- Location:
- branches/4.9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
- Property svn:mergeinfo changed
/trunk merged: 42971,43081
- Property svn:mergeinfo changed
-
branches/4.9/tests/phpunit/tests/admin/includesCommunityEvents.php
r42016 r43082 260 260 * Test that get_unsafe_client_ip() properly anonymizes all possible address formats 261 261 * 262 * @dataProvider data_get_unsafe_client_ip _anonymization262 * @dataProvider data_get_unsafe_client_ip 263 263 * 264 264 * @ticket 41083 265 265 */ 266 public function test_get_unsafe_client_ip_anonymization( $raw_ip, $expected_result ) { 267 $_SERVER['REMOTE_ADDR'] = $raw_ip; 268 $actual_result = WP_Community_Events::get_unsafe_client_ip(); 266 public function test_get_unsafe_client_ip( $raw_ip, $expected_result ) { 267 $_SERVER['REMOTE_ADDR'] = 'this should not be used'; 268 $_SERVER['HTTP_CLIENT_IP'] = $raw_ip; 269 $actual_result = WP_Community_Events::get_unsafe_client_ip(); 269 270 270 271 $this->assertEquals( $expected_result, $actual_result ); 271 272 } 272 273 273 public function data_get_unsafe_client_ip_anonymization() { 274 return array( 275 // Invalid IP. 274 /** 275 * Provide test cases for `test_get_unsafe_client_ip()`. 276 * 277 * @return array 278 */ 279 public function data_get_unsafe_client_ip() { 280 return array( 281 // Handle '::' returned from `wp_privacy_anonymize_ip()`. 276 282 array( 277 '', // Raw IP address 278 false, // Expected result 279 ), 280 // Invalid IP. Sometimes proxies add things like this, or other arbitrary strings. 283 'or=\"[1000:0000:0000:0000:0000:0000:0000:0001', 284 false, 285 ), 286 287 // Handle '0.0.0.0' returned from `wp_privacy_anonymize_ip()`. 281 288 array( 282 289 'unknown', 283 290 false, 284 291 ), 285 // IPv4, no port 292 293 // Valid IPv4. 286 294 array( 287 '10.20.30.45', 288 '10.20.30.0', 289 ), 290 // IPv4, port 291 array( 292 '10.20.30.45:20000', 293 '10.20.30.0', 294 ), 295 // IPv6, no port 295 '198.143.164.252', 296 '198.143.164.0', 297 ), 298 299 // Valid IPv6. 296 300 array( 297 301 '2a03:2880:2110:df07:face:b00c::1', 298 302 '2a03:2880:2110:df07::', 299 303 ), 300 // IPv6, port301 array(302 '[2a03:2880:2110:df07:face:b00c::1]:20000',303 '2a03:2880:2110:df07::',304 ),305 // IPv6, no port, reducible representation306 array(307 '0000:0000:0000:0000:0000:0000:0000:0001',308 '::',309 ),310 // IPv6, no port, partially reducible representation311 array(312 '1000:0000:0000:0000:0000:0000:0000:0001',313 '1000::',314 ),315 // IPv6, port, reducible representation316 array(317 '[0000:0000:0000:0000:0000:0000:0000:0001]:1234',318 '::',319 ),320 // IPv6, port, partially reducible representation321 array(322 '[1000:0000:0000:0000:0000:0000:0000:0001]:5678',323 '1000::',324 ),325 // IPv6, no port, reduced representation326 array(327 '::',328 '::',329 ),330 // IPv6, no port, reduced representation331 array(332 '::1',333 '::',334 ),335 // IPv6, port, reduced representation336 array(337 '[::]:20000',338 '::',339 ),340 // IPv6, address brackets without port delimiter and number, reduced representation341 array(342 '[::1]',343 '::',344 ),345 // IPv6, no port, compatibility mode346 array(347 '::ffff:10.15.20.25',348 '::ffff:10.15.20.0',349 ),350 // IPv6, port, compatibility mode351 array(352 '[::ffff:10.15.20.25]:30000',353 '::ffff:10.15.20.0',354 ),355 // IPv6, no port, compatibility mode shorthand356 array(357 '::127.0.0.1',358 '::ffff:127.0.0.0',359 ),360 // IPv6, port, compatibility mode shorthand361 array(362 '[::127.0.0.1]:30000',363 '::ffff:127.0.0.0',364 ),365 304 ); 366 305 }
Note: See TracChangeset
for help on using the changeset viewer.