]> git.donarmstrong.com Git - debbugs.git/blob - t/07_bugreport.t
fbbb09fdd6a1600be859908e6ce0d07646cd2850
[debbugs.git] / t / 07_bugreport.t
1 # -*- mode: cperl;-*-
2
3
4 use Test::More tests => 18;
5
6 use warnings;
7 use strict;
8
9 # Here, we're going to shoot messages through a set of things that can
10 # happen.
11
12 # First, we're going to send mesages to receive.
13 # To do so, we'll first send a message to submit,
14 # then send messages to the newly created bugnumber.
15
16 use IO::File;
17 use File::Temp qw(tempdir);
18 use Cwd qw(getcwd);
19 use Debbugs::MIME qw(create_mime_message);
20 use File::Basename qw(dirname basename);
21 use Test::WWW::Mechanize;
22 use HTTP::Status qw(RC_NOT_MODIFIED);
23 # The test functions are placed here to make things easier
24 use lib qw(t/lib);
25 use DebbugsTest qw(:all);
26
27 my %config = create_debbugs_configuration();
28
29
30 # create a bug
31 send_message(to=>'submit@bugs.something',
32              headers => [To   => 'submit@bugs.something',
33                          From => 'foo@bugs.something',
34                          Subject => 'Submitting a bug',
35                         ],
36              body => <<EOF) or fail('Unable to send message');
37 Package: foo
38 Severity: normal
39
40 This is a silly bug
41 EOF
42
43
44 # test bugreport.cgi
45
46 # start up an HTTP::Server::Simple
47 my $bugreport_cgi_handler = sub {
48     # I do not understand why this is necessary.
49     $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
50     my $fh;
51     open($fh,'-|',-e './cgi/version.cgi'? 'perl -Ilib -T ./cgi/bugreport.cgi' : 'perl -Ilib -T ../cgi/bugreport.cgi');
52     my $headers;
53     my $status = 200;
54     while (<$fh>) {
55         if (/^\s*$/ and $status) {
56             print "HTTP/1.1 $status OK\n";
57             print $headers;
58             $status = 0;
59             print $_;
60         } elsif ($status) {
61             $headers .= $_;
62             if (/^Status:\s*(\d+)/i) {
63                 $status = $1;
64             }
65         } else {
66             print $_;
67         }
68     }
69 };
70
71 my $port = 11342;
72
73 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
74    'forked HTTP::Server::Simple successfully');
75
76 my $mech = Test::WWW::Mechanize->new();
77
78 $mech->get_ok('http://localhost:'.$port.'/?bug=1',
79               'Page received ok');
80 ok($mech->content() =~ qr/\<title\>\#1.+Submitting a bug/i,
81    'Title of bug is submitting a bug');
82 my $etag = $mech->response->header('Etag');
83 $mech->get('http://localhost:'.$port.'/?bug=1',
84            'If-None-Match' => $etag);
85 is($mech->res->code, RC_NOT_MODIFIED,
86    'Not modified when the same ETag sent for bug');
87
88 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mbox=yes',
89               'Page received ok');
90 ok($mech->content() =~ qr/Subject: Submitting a bug/i,
91    'Subject of bug maibox is right');
92 ok($mech->content() =~ qr/^From /m,
93    'Starts with a From appropriately');
94
95 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
96               'Page received ok');
97 ok($mech->content() !~ qr/[\x01\x02\x03\x05\x06\x07]/i,
98    'No unescaped states');
99 $etag = $mech->response->header('Etag');
100 $mech->get('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
101            'If-None-Match' => $etag);
102 is($mech->res->code, RC_NOT_MODIFIED,
103    'Not modified when the same ETag sent for bug maintmbox');
104
105 # now test the output of some control commands
106 my @control_commands =
107      (
108       reassign_foo => {command => 'reassign',
109                        value   => 'bar',
110                        regex => qr{<strong>bug reassigned from package &#39;<a href="pkgreport\.cgi\?package=foo">foo</a>&#39; to &#39;<a href="pkgreport\.cgi\?package=bar">bar</a>},
111                       },
112       forwarded_foo      => {command => 'forwarded',
113                              value   => 'https://foo.invalid/bugs?id=1',
114                              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;\.},
115                             },
116       forwarded_foo_2    => {command => 'forwarded',
117                              value   => 'https://foo.example/bugs?id=1',
118                              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;\.},
119                             },
120       clone        => {command => 'clone',
121                        value   => '-1',
122                        regex   => qr{<strong>Bug <a href="bugreport.cgi\?bug=1">1</a> cloned as bug <a href="bugreport.cgi\?bug=2">2</a>},
123                       },
124      );
125
126 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
127   # just check to see that control doesn't explode
128   $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
129     and $control_command->{value} !~ /^\s/;
130   send_message(to => 'control@bugs.something',
131                headers => [To   => 'control@bugs.something',
132                            From => 'foo@bugs.something',
133                            Subject => "Munging a bug with $command",
134                           ],
135                body => <<EOF) or fail 'message to control@bugs.something failed';
136 debug 10
137 $control_command->{command} 1$control_command->{value}
138 thanks
139 EOF
140                                   ;
141   # Now test that the output has changed accordingly
142   $mech->get_ok('http://localhost:'.$port.'/?bug=1',
143                 'Page received ok');
144   like($mech->content(), $control_command->{regex},
145        'Page matches regex');
146 }
147
148 # Other tests for bugs in the page should be added here eventually
149