]> git.donarmstrong.com Git - debbugs.git/blob - t/07_bugreport.t
abstract out create config in tests
[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;
28 eval {
29      %config = create_debbugs_configuration();
30 };
31 if ($@) {
32      BAIL_OUT($@);
33 }
34
35 # create a bug
36 send_message(to=>'submit@bugs.something',
37              headers => [To   => 'submit@bugs.something',
38                          From => 'foo@bugs.something',
39                          Subject => 'Submitting a bug',
40                         ],
41              body => <<EOF) or fail('Unable to send message');
42 Package: foo
43 Severity: normal
44
45 This is a silly bug
46 EOF
47
48
49 # test bugreport.cgi
50
51 # start up an HTTP::Server::Simple
52 my $bugreport_cgi_handler = sub {
53     # I do not understand why this is necessary.
54     $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
55     my $fh;
56     open($fh,'-|',-e './cgi/version.cgi'? 'perl -I. -T ./cgi/bugreport.cgi' : 'perl -I. -T ../cgi/bugreport.cgi');
57     my $headers;
58     my $status = 200;
59     while (<$fh>) {
60         if (/^\s*$/ and $status) {
61             print "HTTP/1.1 $status OK\n";
62             print $headers;
63             $status = 0;
64             print $_;
65         } elsif ($status) {
66             $headers .= $_;
67             if (/^Status:\s*(\d+)/i) {
68                 $status = $1;
69             }
70         } else {
71             print $_;
72         }
73     }
74 };
75
76 my $port = 11342;
77
78 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
79    'forked HTTP::Server::Simple successfully');
80
81 my $mech = Test::WWW::Mechanize->new();
82
83 $mech->get_ok('http://localhost:'.$port.'/?bug=1',
84               'Page received ok');
85 ok($mech->content() =~ qr/\<title\>\#1.+Submitting a bug/i,
86    'Title of bug is submitting a bug');
87 my $etag = $mech->response->header('Etag');
88 $mech->get('http://localhost:'.$port.'/?bug=1',
89            'If-None-Match' => $etag);
90 is($mech->res->code, RC_NOT_MODIFIED,
91    'Not modified when the same ETag sent for bug');
92
93 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mbox=yes',
94               'Page received ok');
95 ok($mech->content() =~ qr/Subject: Submitting a bug/i,
96    'Subject of bug maibox is right');
97 ok($mech->content() =~ qr/^From /m,
98    'Starts with a From appropriately');
99
100 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
101               'Page received ok');
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');
109
110 # now test the output of some control commands
111 my @control_commands =
112      (
113       reassign_foo => {command => 'reassign',
114                        value   => 'bar',
115                        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>},
116                       },
117       forwarded_foo      => {command => 'forwarded',
118                              value   => 'https://foo.invalid/bugs?id=1',
119                              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;\.},
120                             },
121       forwarded_foo_2    => {command => 'forwarded',
122                              value   => 'https://foo.example/bugs?id=1',
123                              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;\.},
124                             },
125       clone        => {command => 'clone',
126                        value   => '-1',
127                        regex   => qr{<strong>Bug <a href="bugreport.cgi\?bug=1">1</a> cloned as bug <a href="bugreport.cgi\?bug=2">2</a>},
128                       },
129      );
130
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",
139                           ],
140                body => <<EOF) or fail 'message to control@bugs.something failed';
141 debug 10
142 $control_command->{command} 1$control_command->{value}
143 thanks
144 EOF
145                                   ;
146   # Now test that the output has changed accordingly
147   $mech->get_ok('http://localhost:'.$port.'/?bug=1',
148                 'Page received ok');
149   like($mech->content(), $control_command->{regex},
150        'Page matches regex');
151 }
152
153 # Other tests for bugs in the page should be added here eventually
154