Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions t/apache/expr.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ my @test_cases = (
[ q[toupper(escape('?')) = '%3F' ] => 1 ],
[ q[tolower(toupper(escape('?'))) = '%3f' ] => 1 ],
[ q[%{toupper:%{escape:?}} = '%3F' ] => 1 ],
[ q[file('] . $file_foo . q[') = 'foo\n' ] => 1 ],
# unary operators
[ q[-n ''] => 0 ],
[ q[-z ''] => 1 ],
Expand Down Expand Up @@ -198,11 +197,13 @@ push @test_cases, @bool_test_cases;
push @test_cases, map { ["!($_->[0])" => neg($_->[1]) ] } @bool_test_cases;

if (have_min_apache_version("2.3.13")) {
my $restrict2_result = have_min_apache_version('2.4.68') ? undef : 1;
push(@test_cases, (
# functions
[ q[filesize('] . $file_foo . q[') = 4 ] => 1 ],
[ q[filesize('] . $file_notexist . q[') = 0 ] => 1 ],
[ q[filesize('] . $file_zero . q[') = 0 ] => 1 ],
[ q[filesize('] . $file_foo . q[') = 4 ] => $restrict2_result ],
[ q[filesize('] . $file_notexist . q[') = 0 ] => $restrict2_result ],
[ q[filesize('] . $file_zero . q[') = 0 ] => $restrict2_result ],
[ q[file('] . $file_foo . q[') = 'foo\n' ] => $restrict2_result ],
# unary operators
[ qq[-d '$file_foo' ] => 0 ],
[ qq[-e '$file_foo' ] => 1 ],
Expand Down
61 changes: 46 additions & 15 deletions t/modules/headers.t
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,27 @@ my @testcases = (
[ ],
[ 'Test-Header' => 'foo' ],
],
# 500 error test - invalid regex pattern
[
"Header edit Test-Header (unclosed bar", # malformed regex (unmatched parenthesis)
[ ],
[ ],
500,
],
);
if (have_min_apache_version('2.4.68')) {
push(@testcases,
(
# edit*
[
"Header set Test-Header \"expr=%{base64:%{file:$htaccess}}\"", # no file() in htaccess
[ ],
[ ],
500,
],
)
);
}
if (have_min_apache_version('2.5.1')) {
push(@testcases,
(
Expand Down Expand Up @@ -297,6 +317,9 @@ sub test_header2 {
my @test = @_;
my $h = HTTP::Headers->new;

# Extract expected status code (default to 200 if not specified)
my $expected_status = $test[0][3] // 200;

print "\n\n\n";
for (my $i = 0; $i < scalar @{$test[0][1]}; $i += 2) {
print "Header sent n°" . $i/2 . ":\n";
Expand All @@ -312,22 +335,30 @@ sub test_header2 {
##
my $r = HTTP::Request->new('GET', "http://$hostport/modules/headers/htaccess/", $h);
my $res = $ua->request($r);
ok t_cmp($res->code, 200, "Checking return code is '200'");
ok t_cmp($res->code, $expected_status, "Checking return code is '$expected_status'");

my $isok = 1;
for (my $i = 0; $i < scalar @{$test[0][2]}; $i += 2) {
print "\n";
print "Header received n°" . $i/2 . ":\n";
print " header: " . $test[0][2][$i] . "\n";
print " expected: " . $test[0][2][$i+1] . "\n";
if ($res->header($test[0][2][$i])) {
print " received: " . $res->header($test[0][2][$i]) . "\n";
} else {
print " received: <undefined>\n";
# Only validate headers if we expect a successful response
if ($expected_status == 200) {
my $isok = 1;
for (my $i = 0; $i < scalar @{$test[0][2]}; $i += 2) {
print "\n";
print "Header received n°" . $i/2 . ":\n";
print " header: " . $test[0][2][$i] . "\n";
print " expected: " . $test[0][2][$i+1] . "\n";
if ($res->header($test[0][2][$i])) {
print " received: " . $res->header($test[0][2][$i]) . "\n";
} else {
print " received: <undefined>\n";
}
$isok = $isok && $res->header($test[0][2][$i]) && $test[0][2][$i+1] eq $res->header($test[0][2][$i]);
}
$isok = $isok && $res->header($test[0][2][$i]) && $test[0][2][$i+1] eq $res->header($test[0][2][$i]);
}
print "\nResponse received is:\n" . $res->as_string;
print "\nResponse received is:\n" . $res->as_string;

ok $isok;
ok $isok;
} else {
# For error responses, skip header validation
print "\nExpected error response received (status $expected_status)\n";
print "Response received is:\n" . $res->as_string;
ok 1;
}
}
Loading