4 use Test::More tests => 19;
9 # Here, we're going to shoot messages through a set of things that can
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.
17 use File::Temp qw(tempdir);
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
25 use DebbugsTest qw(:all);
27 my %config = create_debbugs_configuration();
31 send_message(to=>'submit@bugs.something',
32 headers => [To => 'submit@bugs.something',
33 From => 'foo@bugs.something',
34 Subject => 'Submitting a bug',
36 body => <<EOF) or fail('Unable to send message');
40 This is a silly bug which contains an unescaped From line.
48 # start up an HTTP::Server::Simple
49 my $bugreport_cgi_handler = sub {
50 # I do not understand why this is necessary.
51 $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
53 open($fh,'-|',-e './cgi/version.cgi'? 'perl -Ilib -T ./cgi/bugreport.cgi' : 'perl -Ilib -T ../cgi/bugreport.cgi');
57 if (/^\s*$/ and $status) {
58 print "HTTP/1.1 $status OK\n";
64 if (/^Status:\s*(\d+)/i) {
75 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
76 'forked HTTP::Server::Simple successfully');
78 my $mech = Test::WWW::Mechanize->new();
80 $mech->get_ok('http://localhost:'.$port.'/?bug=1',
82 ok($mech->content() =~ qr/\<title\>\#1.+Submitting a bug/i,
83 'Title of bug is submitting a bug');
84 my $etag = $mech->response->header('Etag');
85 $mech->get('http://localhost:'.$port.'/?bug=1',
86 'If-None-Match' => $etag);
87 is($mech->res->code, RC_NOT_MODIFIED,
88 'Not modified when the same ETag sent for bug');
90 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mbox=yes',
92 ok($mech->content() =~ qr/Subject: Submitting a bug/i,
93 'Subject of bug maibox is right');
94 ok($mech->content() =~ qr/^From /m,
95 'Starts with a From appropriately');
96 ok($mech->content() =~ qr/^(>F|=46)rom line/m,
97 'From line escaped appropriately');
98 print STDERR $mech->content();
100 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
102 ok($mech->content() !~ qr/[\x01\x02\x03\x05\x06\x07]/i,
103 'No unescaped states');
104 $etag = $mech->response->header('Etag');
105 $mech->get('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
106 'If-None-Match' => $etag);
107 is($mech->res->code, RC_NOT_MODIFIED,
108 'Not modified when the same ETag sent for bug maintmbox');
110 # now test the output of some control commands
111 my @control_commands =
113 reassign_foo => {command => 'reassign',
115 regex => qr{<strong>bug reassigned from package '<a href="pkgreport\.cgi\?package=foo">foo</a>' to '<a href="pkgreport\.cgi\?package=bar">bar</a>},
117 forwarded_foo => {command => 'forwarded',
118 value => 'https://foo.invalid/bugs?id=1',
119 regex => qr{<strong>Set bug forwarded-to-address to '<a href="https://foo\.invalid/bugs\?id=1">https://foo\.invalid/bugs\?id=1</a>'\.},
121 forwarded_foo_2 => {command => 'forwarded',
122 value => 'https://foo.example/bugs?id=1',
123 regex => qr{<strong>Changed bug forwarded-to-address to '<a href="https://foo\.example/bugs\?id=1">https://foo\.example/bugs\?id=1</a>' from '<a href="https://foo\.invalid/bugs\?id=1">https://foo\.invalid/bugs\?id=1</a>'\.},
125 clone => {command => 'clone',
127 regex => qr{<strong>Bug <a href="bugreport.cgi\?bug=1">1</a> cloned as bug <a href="bugreport.cgi\?bug=2">2</a>},
131 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
132 # just check to see that control doesn't explode
133 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
134 and $control_command->{value} !~ /^\s/;
135 send_message(to => 'control@bugs.something',
136 headers => [To => 'control@bugs.something',
137 From => 'foo@bugs.something',
138 Subject => "Munging a bug with $command",
140 body => <<EOF) or fail 'message to control@bugs.something failed';
142 $control_command->{command} 1$control_command->{value}
146 # Now test that the output has changed accordingly
147 $mech->get_ok('http://localhost:'.$port.'/?bug=1',
149 like($mech->content(), $control_command->{regex},
150 'Page matches regex');
153 # Other tests for bugs in the page should be added here eventually