Skip to content

Commit c45f32c

Browse files
covenerEric Covener
andauthored
2.4.68 expr updates (#18)
Co-authored-by: Eric Covener <ecovener@us.ibm.com>
1 parent 7ce6745 commit c45f32c

2 files changed

Lines changed: 51 additions & 19 deletions

File tree

t/apache/expr.t

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ my @test_cases = (
115115
[ q[toupper(escape('?')) = '%3F' ] => 1 ],
116116
[ q[tolower(toupper(escape('?'))) = '%3f' ] => 1 ],
117117
[ q[%{toupper:%{escape:?}} = '%3F' ] => 1 ],
118-
[ q[file('] . $file_foo . q[') = 'foo\n' ] => 1 ],
119118
# unary operators
120119
[ q[-n ''] => 0 ],
121120
[ q[-z ''] => 1 ],
@@ -198,11 +197,13 @@ push @test_cases, @bool_test_cases;
198197
push @test_cases, map { ["!($_->[0])" => neg($_->[1]) ] } @bool_test_cases;
199198

200199
if (have_min_apache_version("2.3.13")) {
200+
my $restrict2_result = have_min_apache_version('2.4.68') ? undef : 1;
201201
push(@test_cases, (
202202
# functions
203-
[ q[filesize('] . $file_foo . q[') = 4 ] => 1 ],
204-
[ q[filesize('] . $file_notexist . q[') = 0 ] => 1 ],
205-
[ q[filesize('] . $file_zero . q[') = 0 ] => 1 ],
203+
[ q[filesize('] . $file_foo . q[') = 4 ] => $restrict2_result ],
204+
[ q[filesize('] . $file_notexist . q[') = 0 ] => $restrict2_result ],
205+
[ q[filesize('] . $file_zero . q[') = 0 ] => $restrict2_result ],
206+
[ q[file('] . $file_foo . q[') = 'foo\n' ] => $restrict2_result ],
206207
# unary operators
207208
[ qq[-d '$file_foo' ] => 0 ],
208209
[ qq[-e '$file_foo' ] => 1 ],

t/modules/headers.t

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,27 @@ my @testcases = (
115115
[ ],
116116
[ 'Test-Header' => 'foo' ],
117117
],
118+
# 500 error test - invalid regex pattern
119+
[
120+
"Header edit Test-Header (unclosed bar", # malformed regex (unmatched parenthesis)
121+
[ ],
122+
[ ],
123+
500,
124+
],
118125
);
126+
if (have_min_apache_version('2.4.68')) {
127+
push(@testcases,
128+
(
129+
# edit*
130+
[
131+
"Header set Test-Header \"expr=%{base64:%{file:$htaccess}}\"", # no file() in htaccess
132+
[ ],
133+
[ ],
134+
500,
135+
],
136+
)
137+
);
138+
}
119139
if (have_min_apache_version('2.5.1')) {
120140
push(@testcases,
121141
(
@@ -297,6 +317,9 @@ sub test_header2 {
297317
my @test = @_;
298318
my $h = HTTP::Headers->new;
299319

320+
# Extract expected status code (default to 200 if not specified)
321+
my $expected_status = $test[0][3] // 200;
322+
300323
print "\n\n\n";
301324
for (my $i = 0; $i < scalar @{$test[0][1]}; $i += 2) {
302325
print "Header sent n°" . $i/2 . ":\n";
@@ -312,22 +335,30 @@ sub test_header2 {
312335
##
313336
my $r = HTTP::Request->new('GET', "http://$hostport/modules/headers/htaccess/", $h);
314337
my $res = $ua->request($r);
315-
ok t_cmp($res->code, 200, "Checking return code is '200'");
338+
ok t_cmp($res->code, $expected_status, "Checking return code is '$expected_status'");
316339

317-
my $isok = 1;
318-
for (my $i = 0; $i < scalar @{$test[0][2]}; $i += 2) {
319-
print "\n";
320-
print "Header received n°" . $i/2 . ":\n";
321-
print " header: " . $test[0][2][$i] . "\n";
322-
print " expected: " . $test[0][2][$i+1] . "\n";
323-
if ($res->header($test[0][2][$i])) {
324-
print " received: " . $res->header($test[0][2][$i]) . "\n";
325-
} else {
326-
print " received: <undefined>\n";
340+
# Only validate headers if we expect a successful response
341+
if ($expected_status == 200) {
342+
my $isok = 1;
343+
for (my $i = 0; $i < scalar @{$test[0][2]}; $i += 2) {
344+
print "\n";
345+
print "Header received n°" . $i/2 . ":\n";
346+
print " header: " . $test[0][2][$i] . "\n";
347+
print " expected: " . $test[0][2][$i+1] . "\n";
348+
if ($res->header($test[0][2][$i])) {
349+
print " received: " . $res->header($test[0][2][$i]) . "\n";
350+
} else {
351+
print " received: <undefined>\n";
352+
}
353+
$isok = $isok && $res->header($test[0][2][$i]) && $test[0][2][$i+1] eq $res->header($test[0][2][$i]);
327354
}
328-
$isok = $isok && $res->header($test[0][2][$i]) && $test[0][2][$i+1] eq $res->header($test[0][2][$i]);
329-
}
330-
print "\nResponse received is:\n" . $res->as_string;
355+
print "\nResponse received is:\n" . $res->as_string;
331356

332-
ok $isok;
357+
ok $isok;
358+
} else {
359+
# For error responses, skip header validation
360+
print "\nExpected error response received (status $expected_status)\n";
361+
print "Response received is:\n" . $res->as_string;
362+
ok 1;
363+
}
333364
}

0 commit comments

Comments
 (0)