]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - t/inc/IP.t
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / t / inc / IP.t
1 #!/usr/bin/env php
2 <?php
3
4 require 'Test.php';
5
6 plan( 1120 );
7
8 require_ok( 'includes/IP.php' );
9
10 # some of this test data was taken from Data::Validate::IP
11
12 #
13 # isValid()
14 #
15
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" );
23         }
24 }
25
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" );
34         }
35 }
36
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'
44 );
45
46 foreach ( $invalid as $i ) {
47         ok( ! IP::isValid( $i ), "$i is an invalid IPv4 address" );
48 }
49
50 #
51 # isPublic()
52 #
53
54 $private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
55
56 foreach ( $private as $p ) {
57         ok( ! IP::isPublic( $p ), "$p is not a public IP address" ); 
58 }
59
60 /* vim: set filetype=php: */
61 ?>