On 07/03/2016 02:56 AM, Luca Toscano wrote:
Patch committed to trunk in http://svn.apache.org/r1751138
Updated backport proposal and trunk's CHANGES.

Attached is an httpd-test patch with some regression cases for this change. (I'm not sure what the review/commit policies are for that repo; can anyone enlighten me?)

Note that apr_date_parse_rfc() handles many more strange and semi-broken cases than just RFC 822/1123. I am +1 for those but wanted to bring it up to everyone's attention, just in case.

--Jacob
>From 298f1b53e1da2d5e933f1a69332bbce436c0f482 Mon Sep 17 00:00:00 2001
From: Jacob Champion <champio...@gmail.com>
Date: Thu, 21 Jul 2016 14:56:55 -0700
Subject: [PATCH] Add Last-Modified header replacement tests

Per the long conversation culminating in

    https://lists.apache.org/thread.html/909bb1b18b723ed0127b062d0f4d18779d2c7a2acddcbd57c7021f51@%3Cdev.httpd.apache.org%3E

test that httpd's CGI implementation does the following:

- replaces future Last-Modified dates with the current date/time
- transforms RFC 822/1123 Last-Modified dates into RFC 723x (GMT)
- completely removes unintelligible Last-Modified headers
---
 t/htdocs/modules/cgi/last-modified.pl.PL | 15 +++++++++++++++
 t/modules/cgi.t                          | 26 +++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 t/htdocs/modules/cgi/last-modified.pl.PL

diff --git a/t/htdocs/modules/cgi/last-modified.pl.PL b/t/htdocs/modules/cgi/last-modified.pl.PL
new file mode 100644
index 0000000..898a3f4
--- /dev/null
+++ b/t/htdocs/modules/cgi/last-modified.pl.PL
@@ -0,0 +1,15 @@
+use strict;
+
+sub unescape($);
+
+my $modified = unescape($ENV{QUERY_STRING});
+
+print "Content-Type: text/plain\n";
+print "Last-Modified: $modified\n\n";
+
+# Naive unescape -- only cares about %20 (space).
+sub unescape($) {
+    my $str = shift(@_);
+    $str =~ s/%20/ /g;
+    return $str;
+}
diff --git a/t/modules/cgi.t b/t/modules/cgi.t
index d191d8d..a7221e5 100644
--- a/t/modules/cgi.t
+++ b/t/modules/cgi.t
@@ -115,7 +115,7 @@ if (!$have_apache_2050 || Apache::TestConfig::WINFU()) {
     delete @test{qw(stderr1.pl stderr2.pl stderr3.pl nph-stderr.pl)};
 }
 
-my $tests = ((keys %test) * 2) + (@post_content * 3) + 4;
+my $tests = ((keys %test) * 2) + (@post_content * 3) + 9;
 plan tests => $tests, \&need_cgi;
 
 my ($expected, $actual);
@@ -284,5 +284,29 @@ if (-e $cgi_log) {
 print "# checking that HEAD $path/perl.pl returns 200.\n";
 ok HEAD_RC("$path/perl.pl") == 200;
 
+## Regression tests for Last-Modified header replacement.
+my $r;
+
+$r = GET("$path/last-modified.pl?Sat, 12 Jun 1982 22:12:56 GMT");
+ok t_cmp($r->header('Last-Modified'), 'Sat, 12 Jun 1982 22:12:56 GMT',
+         'valid Last-Modified values are passed along');
+
+$r = GET("$path/last-modified.pl?invalid");
+ok t_cmp($r->header('Last-Modified'), undef,
+         'invalid Last-Modified values are suppressed');
+
+$r = GET("$path/last-modified.pl?Sat, 12 Jun 82 22:12:56 -0700");
+ok t_cmp($r->header('Last-Modified'), 'Sun, 13 Jun 1982 05:12:56 GMT',
+         'RFC 822 Last-Modified values are rewritten');
+
+$r = GET("$path/last-modified.pl?Sat, 12 Jun 1982 22:12:56 -0700");
+ok t_cmp($r->header('Last-Modified'), 'Sun, 13 Jun 1982 05:12:56 GMT',
+         'RFC 1123 Last-Modified values are rewritten');
+
+$r = GET("$path/last-modified.pl?Tue, 25 Dec 9999 03:14:15 GMT");
+ok t_cmp($r->header('Last-Modified'), $r->header('Client-Date'),
+         'future Last-Modified values are replaced');
+
+
 ## clean up
 unlink $cgi_log;
-- 
2.7.4

Reply via email to