1package GunghoTest::PrivateDNS; 2use strict; 3use warnings; 4use Gungho::Inline; 5use Test::More; 6 7sub run 8{ 9 my $class = shift; 10 my %opts = @_; 11 12 my $engine = $opts{engine} || 'POE'; 13 14 Gungho::Inline->run( 15 { 16 user_agent => "Install Test For Gungho $Gungho::VERSION", 17 engine => { 18 module => $engine, 19 }, 20 components => [ 21 'BlockPrivateIP' 22 ] 23 }, 24 { 25 provider => sub { 26 my($p, $c) = @_; 27 28 $c->send_request(Gungho::Request->new(GET => $_)) for qw( 29 http://10.0.0.1 30 http://10.255.255.254 31 http://127.0.0.1 32 http://127.255.255.254 33 http://172.16.0.1 34 http://172.31.255.254 35 http://192.168.0.1 36 http://192.168.255.254 37 http://224.0.0.1 38 ) 39# http://localhost 40 }, 41 handler => sub { 42 my ($p, $c, $req, $res) = @_; 43 is($res->code, 500, 'HTTP status is 500'); 44 # should return blocked error for 127.0.0.1 and localhost, but not for 224.0.0.1 (connect(2) will return a protocol-family error) 45 my $expected = "Access blocked for hostname with private address: " . $req->uri->host; 46 if ($req->uri->host !~ /^224\./) { 47 like($res->content, qr($expected), 'Error message is correct'); 48 } else { 49 unlike($res->content, qr($expected), 'Error message is correct'); 50 } 51 } 52 } 53 ); 54} 55 561; 57