Some more updates for regression testing.

This commit is contained in:
brectanus
2008-05-27 23:52:16 +00:00
parent 4bc1fc39f0
commit 7ad2766e76
7 changed files with 325 additions and 26 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/perl
#!@PERL@
#
# Run regression tests.
@@ -29,6 +30,7 @@ my $SROOT_DIR = "$REG_DIR/server_root";
my $CONF_DIR = "$SROOT_DIR/conf";
my $LOGS_DIR = "$SROOT_DIR/logs";
my $PID_FILE = "$LOGS_DIR/httpd.pid";
my $HTTPD = q(@APXS_HTTPD@);
my $PASSED = 0;
my $TOTAL = 0;
my %C = ();
@@ -37,6 +39,11 @@ my $UA_NAME = "ModSecurity Regression Tests/1.2.3";
my $UA = LWP::UserAgent->new;
$UA->agent($UA_NAME);
# Hack for testing the script w/o configure
if ($HTTPD eq "\@APXS_HTTPD\@") {
$HTTPD = "/usr/local/apache2/bin/httpd";
}
$SIG{TERM} = $SIG{INT} = \&handle_interrupt;
my %opt;
@@ -74,8 +81,13 @@ EOT
usage() if ($opt{h});
### Check httpd binary
$opt{a} = "@APXS_HTTPD@" unless (defined $opt{a});
usage("Invalid Apache startup script: $opt{a}\n") unless (-e $opt{a});
if (defined $opt{a}) {
$HTTPD = $opt{a};
}
else {
$opt{a} = $HTTPD;
}
usage("Invalid Apache startup script: $HTTPD\n") unless (-e $HTTPD);
### Defaults
$opt{A} = "$LOGS_DIR/modsec_audit.log" unless (defined $opt{A});
@@ -86,7 +98,7 @@ $opt{H} = "$SROOT_DIR/htdocs" unless (defined $opt{H});
$opt{p} = 8088 unless (defined $opt{p});
unless (defined $opt{S}) {
my $httpd_root = `$opt{a} -V`;
my $httpd_root = `$HTTPD -V`;
($opt{S} = $httpd_root) =~ s/.*-D HTTPD_ROOT="([^"]*)".*/$1/sm;
}
@@ -178,7 +190,8 @@ sub runfile {
$CONF_DIR, $t{type}, $cfg, $n;
# dbg("Writing test config to: $conf_fn");
open(CONF, ">$conf_fn") or die "Failed to open conf \"$conf_fn\": $!\n";
print CONF (ref $t{conf} eq "CODE" ? &{$t{conf}} : $t{conf});
print CONF (ref $t{conf} eq "CODE" ? eval { &{$t{conf}} } : $t{conf});
msg("$@") if ($@);
close CONF;
$httpd_up = httpd_start("Include $conf_fn") ? 0 : 1;
}
@@ -223,15 +236,15 @@ sub runfile {
}
}
}
else {
msg("Failed to start httpd.");
$rc = 1;
}
# Run any arbitrary perl tests
if ($rc == 0 and exists $t{test} and defined $t{test}) {
dbg("Executing perl test(s)...");
$rc = &{$t{test}};
$rc = eval { &{$t{test}} };
if (! defined $rc) {
msg("Error running test: $@");
$rc = -1;
}
dbg("Perl tests returned: $rc");
}
@@ -257,6 +270,10 @@ sub runfile {
}
}
}
else {
msg("Failed to start httpd.");
$rc = 1;
}
if ($rc == 0) {
$pass++;
@@ -307,7 +324,8 @@ sub do_request {
# Allow test to execute code
if (ref $r eq "CODE") {
$r = &$r;
$r = eval { &$r };
msg("$@") unless (defined $r);
}
if (ref $r eq "HTTP::Request") {
@@ -334,13 +352,16 @@ sub match_response {
elsif ($name eq "content") {
return $& if ($resp->content =~ m/$re/m);
}
elsif ($name eq "raw") {
return $& if ($resp->as_string =~ m/$re/m);
}
return;
}
sub match_log {
my($name, $re, $timeout) = @_;
my $t0 = gettimeofday();
my $t0 = gettimeofday;
my($fh,$rbuf) = ($LOG{$name}{fd}, \$LOG{$name}{buf});
my $n = length($$rbuf);
@@ -350,7 +371,7 @@ sub match_log {
do {
$n += $fh->sysread($$rbuf, 1024, $n);
# dbg("Match \"$re\" in \"$$rbuf\" ($n)");
# dbg("Match \"$re\" in $name \"$$rbuf\" ($n)");
return $& if ($$rbuf =~ m/$re/m);
# TODO: Use select()/poll()
sleep 0.1;
@@ -413,7 +434,7 @@ sub done {
sub httpd_start {
httpd_reset_logs();
my @p = (
$opt{a},
$HTTPD,
-d => $opt{S},
-f => $opt{C},
(map { (-c => $_) } ("Listen localhost:$opt{p}", @_)),
@@ -459,7 +480,7 @@ sub httpd_start {
sub httpd_stop {
httpd_reset_logs();
my @p = (
$opt{a},
$HTTPD,
-d => $opt{S},
-f => $opt{C},
(map { (-c => $_) } ("Listen localhost:$opt{p}", @_)),
@@ -505,7 +526,7 @@ sub httpd_stop {
sub httpd_reload {
httpd_reset_logs();
my @p = (
$opt{a},
$HTTPD,
-d => $opt{S},
-f => $opt{C},
(map { (-c => $_) } ("Listen localhost:$opt{p}", @_)),