9 use IO::CaptureOutput qw(capture);
11 # check whether we can talk to ourself or not ...
14 delete $ENV{PERL_LWP_ENV_PROXY};
17 my $perl = $Config{'perlpath'};
18 $perl = $^X if $^O eq 'VMS' or -x $^X and $^X =~ m,^([a-z]:)?/,i;
20 my $loc = dirname($0);
24 # First we ensure that we can talk to ourself ...
26 system( $perl, File::Spec->catfile( $loc, "talk-to-ourself.pl" ) );
28 $status and BAIL_OUT("Can't talk to ourself");
30 require IO::Socket; # make sure this work before we try to make a HTTP::Daemon
31 use POSIX ":sys_wait_h"; # for nonblocking read
33 # Seconds we make a daemon in another process
35 my ( $daemon_pipe, $daemon_pid );
36 local $SIG{CHLD} = sub {
38 my $pid = waitpid( -1, WNOHANG );
39 $pid == $daemon_pid or return;
45 $daemon_pid = open( $daemon_pipe,
46 "$perl " . File::Spec->catfile( $loc, "mock-daemon.pl" ) . " --httpd-opts Timeout=10 --httpd-opts hdf=1 |" )
47 or die "Can't exec daemon: $!";
49 END { $daemon_pid and kill( $daemon_pid => 0 ); $daemon_pipe and close($daemon_pipe); }
51 my $greeting = <$daemon_pipe>;
52 $greeting =~ /(<[^>]+>)/;
55 my $base = URI->new($1);
60 $u = $u->abs( $_[1] ) if @_ > 1;
64 note "Will access HTTP server at $base\n";
66 use WWW::Mechanize::Script;
73 "min_bytes_code" => 2,
74 "max_bytes_code" => 1,
75 "regex_forbid_code" => 2,
76 "regex_require_code" => 2,
77 "text_forbid_code" => 2,
78 "text_require_code" => 2,
79 "min_elapsed_time_code" => 1,
80 "max_elapsed_time_code" => 2,
82 "request" => { "method" => "GET" }
86 { "CODE_NAMES" => [ "OK", "WARNING", "CRITICAL", "UNKNOWN", "DEPENDENT", "EXCEPTION" ] },
90 "[% CODE_NAMES.\$CODE; IF MESSAGES.size > 0 %] - [% MESSAGES.join(', '); END %]\n",
94 "template" => "[% USE Dumper; Dumper.dump(RESPONSE) %]",
102 "uri" => url("/etc/passwd", $base),
105 "test_name" => "passwd1",
106 "text_require" => [ "/root", "daemon", ":bin:" ],
107 "text_forbid" => [ "staff", ],
113 "uri" => url("/etc/passwd", $base),
116 "test_name" => "passwd2",
117 "min_rtime" => "0.01",
124 "uri" => url("/etc/passwd", $base),
127 "test_name" => "passwd3",
129 "max_bytes" => "65536",
135 "uri" => url("/etc/passwd", $base),
138 "test_name" => "passwd4",
140 "(?:\\:\\d){2}", # uid/gid
141 "(?:/\\w+){2}", # shell ;)
143 "regex_forbid" => [ "^\\w+:\\w{2,}", ], # password
149 "uri" => url("/etc/master.passwd", $base),
152 "test_name" => "exit_status",
158 my $wms = WWW::Mechanize::Script->new( \%cfg );
160 isa_ok($wms, "WWW::Mechanize::Script") or BAIL_OUT("Need WWW::Mechanize::Script");
162 my ( $code, @msgs ) = (0);
163 my ( $stdout, $stderr );
165 eval { ( $code, @msgs ) = $wms->run_script(@script); };
166 #} \$stdout, \$stderr;
168 cmp_ok($code, '==', 0, "Test script runs without error");
169 is_deeply( \@msgs, [], "No messages" );