mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-18 02:04:26 +00:00
Dashboard: Strip ports from IPs to avoid PHP warnings.
Fixes #41083. Props pento, iandunn, EatonZ, birgire, dd32. git-svn-id: https://develop.svn.wordpress.org/trunk@42016 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -255,4 +255,113 @@ class Test_WP_Community_Events extends WP_UnitTestCase {
|
||||
'filename' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that get_unsafe_client_ip() properly anonymizes all possible address formats
|
||||
*
|
||||
* @dataProvider data_get_unsafe_client_ip_anonymization
|
||||
*
|
||||
* @ticket 41083
|
||||
*/
|
||||
public function test_get_unsafe_client_ip_anonymization( $raw_ip, $expected_result ) {
|
||||
$_SERVER['REMOTE_ADDR'] = $raw_ip;
|
||||
$actual_result = WP_Community_Events::get_unsafe_client_ip();
|
||||
|
||||
$this->assertEquals( $expected_result, $actual_result );
|
||||
}
|
||||
|
||||
public function data_get_unsafe_client_ip_anonymization() {
|
||||
return array(
|
||||
// Invalid IP.
|
||||
array(
|
||||
'', // Raw IP address
|
||||
false, // Expected result
|
||||
),
|
||||
// Invalid IP. Sometimes proxies add things like this, or other arbitrary strings.
|
||||
array(
|
||||
'unknown',
|
||||
false,
|
||||
),
|
||||
// IPv4, no port
|
||||
array(
|
||||
'10.20.30.45',
|
||||
'10.20.30.0',
|
||||
),
|
||||
// IPv4, port
|
||||
array(
|
||||
'10.20.30.45:20000',
|
||||
'10.20.30.0',
|
||||
),
|
||||
// IPv6, no port
|
||||
array(
|
||||
'2a03:2880:2110:df07:face:b00c::1',
|
||||
'2a03:2880:2110:df07::',
|
||||
),
|
||||
// IPv6, port
|
||||
array(
|
||||
'[2a03:2880:2110:df07:face:b00c::1]:20000',
|
||||
'2a03:2880:2110:df07::',
|
||||
),
|
||||
// IPv6, no port, reducible representation
|
||||
array(
|
||||
'0000:0000:0000:0000:0000:0000:0000:0001',
|
||||
'::',
|
||||
),
|
||||
// IPv6, no port, partially reducible representation
|
||||
array(
|
||||
'1000:0000:0000:0000:0000:0000:0000:0001',
|
||||
'1000::',
|
||||
),
|
||||
// IPv6, port, reducible representation
|
||||
array(
|
||||
'[0000:0000:0000:0000:0000:0000:0000:0001]:1234',
|
||||
'::',
|
||||
),
|
||||
// IPv6, port, partially reducible representation
|
||||
array(
|
||||
'[1000:0000:0000:0000:0000:0000:0000:0001]:5678',
|
||||
'1000::',
|
||||
),
|
||||
// IPv6, no port, reduced representation
|
||||
array(
|
||||
'::',
|
||||
'::',
|
||||
),
|
||||
// IPv6, no port, reduced representation
|
||||
array(
|
||||
'::1',
|
||||
'::',
|
||||
),
|
||||
// IPv6, port, reduced representation
|
||||
array(
|
||||
'[::]:20000',
|
||||
'::',
|
||||
),
|
||||
// IPv6, address brackets without port delimiter and number, reduced representation
|
||||
array(
|
||||
'[::1]',
|
||||
'::',
|
||||
),
|
||||
// IPv6, no port, compatibility mode
|
||||
array(
|
||||
'::ffff:10.15.20.25',
|
||||
'::ffff:10.15.20.0',
|
||||
),
|
||||
// IPv6, port, compatibility mode
|
||||
array(
|
||||
'[::ffff:10.15.20.25]:30000',
|
||||
'::ffff:10.15.20.0',
|
||||
),
|
||||
// IPv6, no port, compatibility mode shorthand
|
||||
array(
|
||||
'::127.0.0.1',
|
||||
'::ffff:127.0.0.0',
|
||||
),
|
||||
// IPv6, port, compatibility mode shorthand
|
||||
array(
|
||||
'[::127.0.0.1]:30000',
|
||||
'::ffff:127.0.0.0',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user