Security fix: Previously it was possible to include unprotected and even content...
[mediawiki.git] / t / inc / IP.t
blob82a61fe130c52e6991b130b24af3e72b1a33d6c0
1 #!/usr/bin/env php
2 <?php
4 require 'Test.php';
6 plan( 1120 );
8 require_ok( 'includes/IP.php' );
10 # some of this test data was taken from Data::Validate::IP
13 # isValid()
16 foreach ( range( 0, 255 ) as $i ) {
17 $a = sprintf( "%03d", $i );
18 $b = sprintf( "%02d", $i );
19 $c = sprintf( "%01d", $i );
20 foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
21 $ip = "$f.$f.$f.$f";
22 ok( IP::isValid( $ip ), "$ip is a valid IPv4 address" );
26 # A bit excessive perhaps? meh..
27 foreach ( range( 256, 999 ) as $i ) {
28 $a = sprintf( "%03d", $i );
29 $b = sprintf( "%02d", $i );
30 $c = sprintf( "%01d", $i );
31 foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
32 $ip = "$f.$f.$f.$f";
33 ok( ! IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
37 $invalid = array(
38 'www.xn--var-xla.net',
39 '216.17.184.G',
40 '216.17.184.1.',
41 '216.17.184',
42 '216.17.184.',
43 '256.17.184.1'
46 foreach ( $invalid as $i ) {
47 ok( ! IP::isValid( $i ), "$i is an invalid IPv4 address" );
51 # isPublic()
54 $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
56 foreach ( $private as $p ) {
57 ok( ! IP::isPublic( $p ), "$p is not a public IP address" );
60 /* vim: set filetype=php: */