]> git.donarmstrong.com Git - debbugs.git/blobdiff - t/07_bugreport.t
Fix unescaped From in bugreport (closes: #983847)
[debbugs.git] / t / 07_bugreport.t
index 80dfc9220f85150007388a7340ce0b575d043eee..0e99f7f1ad69e4dbc7074c7fbf7eb27f6dc15f18 100644 (file)
@@ -1,7 +1,7 @@
 # -*- mode: cperl;-*-
 
 
-use Test::More tests => 14;
+use Test::More tests => 19;
 
 use warnings;
 use strict;
@@ -19,26 +19,13 @@ use Cwd qw(getcwd);
 use Debbugs::MIME qw(create_mime_message);
 use File::Basename qw(dirname basename);
 use Test::WWW::Mechanize;
+use HTTP::Status qw(RC_NOT_MODIFIED);
 # The test functions are placed here to make things easier
 use lib qw(t/lib);
 use DebbugsTest qw(:all);
 
-my %config;
-eval {
-     %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
-};
-if ($@) {
-     BAIL_OUT($@);
-}
+my %config = create_debbugs_configuration();
 
-# Output some debugging information if there's an error
-END{
-     if ($ENV{DEBUG}) {
-         foreach my $key (keys %config) {
-              diag("$key: $config{$key}\n");
-         }
-     }
-}
 
 # create a bug
 send_message(to=>'submit@bugs.something',
@@ -50,7 +37,9 @@ send_message(to=>'submit@bugs.something',
 Package: foo
 Severity: normal
 
-This is a silly bug
+This is a silly bug which contains an unescaped From line.
+
+From line
 EOF
 
 
@@ -58,11 +47,27 @@ EOF
 
 # start up an HTTP::Server::Simple
 my $bugreport_cgi_handler = sub {
-     # I do not understand why this is necessary.
-     $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
-     my $content = qx(perl -I. -T cgi/bugreport.cgi);
-     $content =~ s/^\s*Content-Type:[^\n]+\n*//si;
-     print $content;
+    # I do not understand why this is necessary.
+    $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
+    my $fh;
+    open($fh,'-|',-e './cgi/version.cgi'? 'perl -Ilib -T ./cgi/bugreport.cgi' : 'perl -Ilib -T ../cgi/bugreport.cgi');
+    my $headers;
+    my $status = 200;
+    while (<$fh>) {
+        if (/^\s*$/ and $status) {
+            print "HTTP/1.1 $status OK\n";
+            print $headers;
+            $status = 0;
+            print $_;
+        } elsif ($status) {
+            $headers .= $_;
+            if (/^Status:\s*(\d+)/i) {
+                $status = $1;
+            }
+        } else {
+            print $_;
+        }
+    }
 };
 
 my $port = 11342;
@@ -76,6 +81,11 @@ $mech->get_ok('http://localhost:'.$port.'/?bug=1',
              'Page received ok');
 ok($mech->content() =~ qr/\<title\>\#1.+Submitting a bug/i,
    'Title of bug is submitting a bug');
+my $etag = $mech->response->header('Etag');
+$mech->get('http://localhost:'.$port.'/?bug=1',
+          'If-None-Match' => $etag);
+is($mech->res->code, RC_NOT_MODIFIED,
+   'Not modified when the same ETag sent for bug');
 
 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mbox=yes',
               'Page received ok');
@@ -83,12 +93,19 @@ ok($mech->content() =~ qr/Subject: Submitting a bug/i,
    'Subject of bug maibox is right');
 ok($mech->content() =~ qr/^From /m,
    'Starts with a From appropriately');
+ok($mech->content() =~ qr/^(>F|=46)rom line/m,
+   'From line escaped appropriately');
+print STDERR $mech->content();
 
 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
               'Page received ok');
-print STDERR $mech->content();
 ok($mech->content() !~ qr/[\x01\x02\x03\x05\x06\x07]/i,
    'No unescaped states');
+$etag = $mech->response->header('Etag');
+$mech->get('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
+          'If-None-Match' => $etag);
+is($mech->res->code, RC_NOT_MODIFIED,
+   'Not modified when the same ETag sent for bug maintmbox');
 
 # now test the output of some control commands
 my @control_commands =
@@ -101,6 +118,10 @@ my @control_commands =
                             value   => 'https://foo.invalid/bugs?id=1',
                             regex   => qr{<strong>Set bug forwarded-to-address to &#39;<a href="https://foo\.invalid/bugs\?id=1">https://foo\.invalid/bugs\?id=1</a>&#39;\.},
                            },
+      forwarded_foo_2    => {command => 'forwarded',
+                            value   => 'https://foo.example/bugs?id=1',
+                            regex   => qr{<strong>Changed bug forwarded-to-address to &#39;<a href="https://foo\.example/bugs\?id=1">https://foo\.example/bugs\?id=1</a>&#39; from &#39;<a href="https://foo\.invalid/bugs\?id=1">https://foo\.invalid/bugs\?id=1</a>&#39;\.},
+                           },
       clone        => {command => 'clone',
                       value   => '-1',
                       regex   => qr{<strong>Bug <a href="bugreport.cgi\?bug=1">1</a> cloned as bug <a href="bugreport.cgi\?bug=2">2</a>},