From 326208d02c7b53c224410f9e5e8add51e4a69c06 Mon Sep 17 00:00:00 2001 From: brectanus Date: Mon, 16 Jun 2008 17:20:50 +0000 Subject: [PATCH] Newer apaches default to text/plain instead of null. Make matching files a bit more robust. --- .../config/10-response-directives.t | 14 +-- apache2/t/regression/misc/00-phases.t | 12 +-- apache2/t/run-regression-tests.pl.in | 85 +++++++++++++------ 3 files changed, 73 insertions(+), 38 deletions(-) diff --git a/apache2/t/regression/config/10-response-directives.t b/apache2/t/regression/config/10-response-directives.t index 99f0a858..60617a29 100644 --- a/apache2/t/regression/config/10-response-directives.t +++ b/apache2/t/regression/config/10-response-directives.t @@ -33,7 +33,7 @@ SecDebugLog $ENV{DEBUG_LOG} SecDebugLogLevel 9 SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecRule RESPONSE_BODY "TEST" "phase:4,deny" ), match_log => { @@ -54,7 +54,7 @@ SecDebugLog $ENV{DEBUG_LOG} SecDebugLogLevel 9 SecResponseBodyAccess Off - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecRule RESPONSE_BODY "TEST" "phase:4,deny" ), match_log => { @@ -76,7 +76,7 @@ conf => qq( SecRuleEngine On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecResponseBodyLimit 8192 ), match_log => { @@ -95,7 +95,7 @@ conf => qq( SecRuleEngine On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecResponseBodyLimit 9000 ), match_log => { @@ -114,7 +114,7 @@ conf => qq( SecRuleEngine On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecResponseBodyLimit 8000 ), match_log => { @@ -135,7 +135,7 @@ conf => qq( SecRuleEngine On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecResponseBodyLimit 5 SecResponseBodyLimitAction Reject ), @@ -155,7 +155,7 @@ conf => qq( SecRuleEngine On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecResponseBodyLimit 5 SecDebugLog $ENV{DEBUG_LOG} SecDebugLogLevel 4 diff --git a/apache2/t/regression/misc/00-phases.t b/apache2/t/regression/misc/00-phases.t index f3c5d1f1..97a40a52 100644 --- a/apache2/t/regression/misc/00-phases.t +++ b/apache2/t/regression/misc/00-phases.t @@ -8,7 +8,7 @@ SecRuleEngine On SecRequestBodyAccess On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecRule REQUEST_LINE "^POST" "phase:1,pass,log,auditlog" SecRule ARGS "val1" "phase:1,pass,log,auditlog" SecRule RESPONSE_HEADERS:Last-Modified "." "phase:1,pass,log,auditlog" @@ -38,7 +38,7 @@ SecRuleEngine On SecRequestBodyAccess On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecRule REQUEST_LINE "^POST" "phase:2,pass,log,auditlog" SecRule ARGS "val1" "phase:2,pass,log,auditlog" SecRule RESPONSE_HEADERS:Last-Modified "." "phase:2,pass,log,auditlog" @@ -68,7 +68,7 @@ SecRuleEngine On SecRequestBodyAccess On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecRule REQUEST_LINE "^POST" "phase:3,pass,log,auditlog" SecRule ARGS "val1" "phase:3,pass,log,auditlog" SecRule RESPONSE_HEADERS:Last-Modified "." "phase:3,pass,log,auditlog" @@ -98,7 +98,9 @@ SecRuleEngine On SecRequestBodyAccess On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null + SecDebugLog "$ENV{DEBUG_LOG}" + SecDebugLogLevel 9 SecRule REQUEST_LINE "^POST" "phase:4,pass,log,auditlog" SecRule ARGS "val1" "phase:4,pass,log,auditlog" SecRule RESPONSE_HEADERS:Last-Modified "." "phase:4,pass,log,auditlog" @@ -127,7 +129,7 @@ SecRuleEngine On SecRequestBodyAccess On SecResponseBodyAccess On - SecResponseBodyMimeType null + SecResponseBodyMimeType text/plain null SecRule REQUEST_LINE "^POST" "phase:5,pass,log,auditlog" SecRule ARGS "val1" "phase:5,pass,log,auditlog" SecRule RESPONSE_HEADERS:Last-Modified "." "phase:5,pass,log,auditlog" diff --git a/apache2/t/run-regression-tests.pl.in b/apache2/t/run-regression-tests.pl.in index e99bb82b..032c5b41 100755 --- a/apache2/t/run-regression-tests.pl.in +++ b/apache2/t/run-regression-tests.pl.in @@ -416,6 +416,11 @@ sub match_log { msg("Warning: Empty regular expression.") if (!defined $re or $re eq ""); + unless (defined $fh) { + msg("Error: File \"$name\" is not opened for matching."); + return; + } + $timeout = 0 unless (defined $timeout); do { @@ -432,10 +437,16 @@ sub match_log { sub match_file { my($neg,$fn) = ($_[0] =~ m/^(-?)(.*)$/); unless (exists $FILE{$fn}) { - $FILE{$fn}{fn} = $fn; - $FILE{$fn}{fd} = new FileHandle($fn, O_RDONLY); - $FILE{$fn}{fd}->blocking(0); - $FILE{$fn}{buf} = ""; + eval { + $FILE{$fn}{fn} = $fn; + $FILE{$fn}{fd} = new FileHandle($fn, O_RDONLY) or die "$!\n"; + $FILE{$fn}{fd}->blocking(0); + $FILE{$fn}{buf} = ""; + }; + if ($@) { + msg("Warning: Failed to open file \"$fn\": $@"); + return; + } } return match_log($_[0], $_[1]); # timeout makes no sense } @@ -650,38 +661,60 @@ sub httpd_reset_fd { } # Error - $FILE{error}{fn} = $opt{E}; - $FILE{error}{fd} = new FileHandle($opt{E}, O_RDWR|O_CREAT); - $FILE{error}{fd}->blocking(0); - $FILE{error}{fd}->sysseek(0, 2); - $FILE{error}{buf} = ""; + eval { + $FILE{error}{fn} = $opt{E}; + $FILE{error}{fd} = new FileHandle($opt{E}, O_RDWR|O_CREAT) or die "$!\n"; + $FILE{error}{fd}->blocking(0); + $FILE{error}{fd}->sysseek(0, 2); + $FILE{error}{buf} = ""; + }; + if ($@) { + msg("Warning: Failed to open file \"$opt{E}\": $@"); + return undef; + } # Audit - $FILE{audit}{fn} = $opt{A}; - $FILE{audit}{fd} = new FileHandle($opt{A}, O_RDWR|O_CREAT); - $FILE{audit}{fd}->blocking(0); - $FILE{audit}{fd}->sysseek(0, 2); - $FILE{audit}{buf} = ""; + eval { + $FILE{audit}{fn} = $opt{A}; + $FILE{audit}{fd} = new FileHandle($opt{A}, O_RDWR|O_CREAT) or die "$!\n"; + $FILE{audit}{fd}->blocking(0); + $FILE{audit}{fd}->sysseek(0, 2); + $FILE{audit}{buf} = ""; + }; + if ($@) { + msg("Warning: Failed to open file \"$opt{A}\": $@"); + return undef; + } # Debug - $FILE{debug}{fn} = $opt{D}; - $FILE{debug}{fd} = new FileHandle($opt{D}, O_RDWR|O_CREAT); - $FILE{debug}{fd}->blocking(0); - $FILE{debug}{fd}->sysseek(0, 2); - $FILE{debug}{buf} = ""; + eval { + $FILE{debug}{fn} = $opt{D}; + $FILE{debug}{fd} = new FileHandle($opt{D}, O_RDWR|O_CREAT) or die "$!\n"; + $FILE{debug}{fd}->blocking(0); + $FILE{debug}{fd}->sysseek(0, 2); + $FILE{debug}{buf} = ""; + }; + if ($@) { + msg("Warning: Failed to open file \"$opt{D}\": $@"); + return undef; + } # Any extras listed in "match_log" if ($t and exists $t->{match_log}) { for my $k (keys %{ $t->{match_log} || {} }) { my($neg,$fn) = ($k =~ m/^(-?)(.*)$/); next if (!$fn or exists $FILE{$fn}); - #dbg("Opening additional log: $fn"); - $FILE{$fn}{fn} = $fn; - $FILE{$fn}{fd} = new FileHandle($fn, O_RDWR|O_CREAT); - $FILE{$fn}{fd}->blocking(0); - $FILE{$fn}{fd}->sysseek(0, 2); - $FILE{$fn}{buf} = ""; - + eval { + $FILE{$fn}{fn} = $fn; + $FILE{$fn}{fd} = new FileHandle($fn, O_RDWR|O_CREAT) or die "$!\n"; + $FILE{$fn}{fd}->blocking(0); + $FILE{$fn}{fd}->sysseek(0, 2); + $FILE{$fn}{buf} = ""; + }; + if ($@) { + msg("Warning: Failed to open file \"$fn\": $@"); + return undef; + } } } }