From: Darian Anthony Patrick Date: Wed, 10 Jun 2015 19:07:48 +0000 (-0700) Subject: Check for link-local addresses in isPublic X-Git-Tag: 1.31.0-rc.0~11100^2 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=a0616269a103841ae3f2e0c0520b5ca98a754bfc;hp=a8454a95639910c9ac196d80d07d6c2f62f106ad;p=lhc%2Fweb%2Fwiklou.git Check for link-local addresses in isPublic Bug: T102032 Change-Id: Id1b6b9efc2c47a94a1a81cf4479cd756d22a2c80 --- diff --git a/includes/utils/IP.php b/includes/utils/IP.php index 4441236d94..dfcbe7850f 100644 --- a/includes/utils/IP.php +++ b/includes/utils/IP.php @@ -375,6 +375,8 @@ class IP { '127.0.0.0/8', # loopback 'fc00::/7', # RFC 4193 (local) '0:0:0:0:0:0:0:1', # loopback + '169.254.0.0/16', # link-local + 'fe80::/10', # link-local ) ); } return !$privateSet->match( $ip ); diff --git a/tests/phpunit/includes/utils/IPTest.php b/tests/phpunit/includes/utils/IPTest.php index acc9dfc55c..65464c48b2 100644 --- a/tests/phpunit/includes/utils/IPTest.php +++ b/tests/phpunit/includes/utils/IPTest.php @@ -130,7 +130,7 @@ class IPTest extends PHPUnit_Framework_TestCase { array( ':', 'A colon is not an IP' ), array( '124.24.52', 'IPv4 not enough quads' ), array( '24.324.52.13', 'IPv4 out of range' ), - array( '.24.52.13', 'IPv4 starts with period' ), + array( '.24.52.13', 'IPv4 starts with period' ), ); } @@ -347,16 +347,31 @@ class IPTest extends PHPUnit_Framework_TestCase { /** * @covers IP::isPublic + * @dataProvider provideIsPublic */ - public function testPrivateIPs() { - $private = array( 'fc00::3', 'fc00::ff', '::1', '10.0.0.1', '172.16.0.1', '192.168.0.1' ); - foreach ( $private as $p ) { - $this->assertFalse( IP::isPublic( $p ), "$p is not a public IP address" ); - } - $public = array( '2001:5c0:1000:a::133', 'fc::3', '00FC::' ); - foreach ( $public as $p ) { - $this->assertTrue( IP::isPublic( $p ), "$p is a public IP address" ); - } + public function testIsPublic( $expected, $input ) { + $result = IP::isPublic( $input ); + $this->assertEquals( $expected, $result ); + } + + /** + * Provider for IP::testIsPublic() + */ + public static function provideIsPublic() { + return array( + array( false, 'fc00::3' ), # RFC 4193 (local) + array( false, 'fc00::ff'), # RFC 4193 (local) + array( false, '127.1.2.3'), # loopback + array( false, '::1'), # loopback + array( false, 'fe80::1'), # link-local + array( false, '169.254.1.1'), # link-local + array( false, '10.0.0.1'), # RFC 1918 (private) + array( false, '172.16.0.1'), # RFC 1918 (private) + array( false, '192.168.0.1'), # RFC 1918 (private) + array( true, '2001:5c0:1000:a::133'), # public + array( true, 'fc::3'), # public + array( true, '00FC::') # public + ); } // Private wrapper used to test CIDR Parsing.