]> git.donarmstrong.com Git - debbugs.git/blob - t/06_mail_handling.t
merge changes from don
[debbugs.git] / t / 06_mail_handling.t
1 # -*- mode: cperl;-*-
2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
3
4 use Test::More tests => 84;
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 # The test functions are placed here to make things easier
22 use lib qw(t/lib);
23 use DebbugsTest qw(:all);
24 use Data::Dumper;
25
26 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
27 $SIG{CHLD} = sub {};
28 my %config;
29 eval {
30      %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
31 };
32 if ($@) {
33      BAIL_OUT($@);
34 }
35
36 my $sendmail_dir = $config{sendmail_dir};
37 my $spool_dir = $config{spool_dir};
38 my $config_dir = $config{config_dir};
39
40 END{
41      if ($ENV{DEBUG}) {
42           diag("spool_dir:   $spool_dir\n");
43           diag("config_dir:   $config_dir\n");
44           diag("sendmail_dir: $sendmail_dir\n");
45      }
46 }
47
48 # We're going to use create mime message to create these messages, and
49 # then just send them to receive.
50
51 send_message(to=>'submit@bugs.something',
52              headers => [To   => 'submit@bugs.something',
53                          From => 'foo@bugs.something',
54                          Subject => 'Submiting a bug',
55                         ],
56              body => <<EOF) or fail('Unable to send message');
57 Package: foo
58 Severity: normal
59
60 This is a silly bug
61 EOF
62
63 # now we check to see that we have a bug, and nextnumber has been incremented
64 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
65 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
66 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
67 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
68
69 # next, we check to see that (at least) the proper messages have been
70 # sent out. 1) ack to submitter 2) mail to maintainer
71
72 # This keeps track of the previous size of the sendmail directory
73 my $SD_SIZE_PREV = 0;
74 my $SD_SIZE_NOW = dirsize($sendmail_dir);
75 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
76 $SD_SIZE_PREV=$SD_SIZE_NOW;
77
78 # now send a message to the bug
79
80 send_message(to => '1@bugs.something',
81              headers => [To   => '1@bugs.something',
82                          From => 'foo@bugs.something',
83                          Subject => 'Sending a message to a bug',
84                         ],
85              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
86 Package: foo
87 Severity: normal
88
89 This is a silly bug
90 EOF
91
92 $SD_SIZE_NOW = dirsize($sendmail_dir);
93 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
94 $SD_SIZE_PREV=$SD_SIZE_NOW;
95
96 # just check to see that control doesn't explode
97 send_message(to => 'control@bugs.something',
98              headers => [To   => 'control@bugs.something',
99                          From => 'foo@bugs.something',
100                          Subject => 'Munging a bug',
101                         ],
102              body => <<EOF) or fail 'message to control@bugs.something failed';
103 severity 1 wishlist
104 retitle 1 new title
105 thanks
106 EOF
107
108 $SD_SIZE_NOW = dirsize($sendmail_dir);
109 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
110 $SD_SIZE_PREV=$SD_SIZE_NOW;
111 # now we need to check to make sure the control message was processed without errors
112 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
113    'control@bugs.something message was parsed without errors');
114 # now we need to check to make sure that the control message actually did anything
115 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
116 eval "use Debbugs::Status qw(read_bug writebug);";
117 my $status = read_bug(bug=>1);
118 ok($status->{subject} eq 'new title','bug 1 retitled');
119 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
120
121 # now we're going to go through and methododically test all of the control commands.
122 my @control_commands =
123      (severity_wishlist => {command => 'severity',
124                             value   => 'wishlist',
125                             status_key => 'severity',
126                             status_value => 'wishlist',
127                            },
128       reassign_bar => {command => 'reassign',
129                        value   => 'bar',
130                        status_key => 'package',
131                        status_value => 'bar',
132                       },
133       reassign_foo => {command => 'reassign',
134                        value   => 'foo',
135                        status_key => 'package',
136                        status_value => 'foo',
137                       },
138       'found_1.0'        => {command => 'found',
139                              value   => '1.0',
140                              status_key => 'found_versions',
141                              status_value => ['1.0'],
142                             },
143       'notfound_1.0'     => {command => 'notfound',
144                              value   => '1.0',
145                              status_key => 'found_versions',
146                              status_value => [],
147                             },
148       'found_1.0~5+1b2'  => {command => 'found',
149                              value   => '1.0~5+1b2',
150                              status_key => 'found_versions',
151                              status_value => ['1.0~5+1b2'],
152                             },
153       'notfound_1.0~5+1b2' => {command => 'notfound',
154                                value   => '1.0~5+1b2',
155                                status_key => 'found_versions',
156                                status_value => [],
157                               },
158       'fixed_1.1'        => {command => 'fixed',
159                              value   => '1.1',
160                              status_key => 'fixed_versions',
161                              status_value => ['1.1'],
162                             },
163       'notfixed_1.1'     => {command => 'notfixed',
164                              value   => '1.1',
165                              status_key => 'fixed_versions',
166                              status_value => [],
167                             },
168       'found_1.0~5+1b2'  => {command => 'found',
169                              value   => '1.0~5+1b2',
170                              status_key => 'found_versions',
171                              status_value => ['1.0~5+1b2'],
172                             },
173       'fixed_1.2'        => {command => 'fixed',
174                              value   => '1.2',
175                              status_key => 'fixed_versions',
176                              status_value => ['1.2'],
177                             },
178       close              => {command => 'close',
179                              value   => '',
180                              status_key => 'done',
181                              status_value => 'foo@bugs.something',
182                             },
183       'found_1.3'        => {command => 'found',
184                              value   => '1.3',
185                              status_key => 'done',
186                              status_value => '',
187                             },
188       submitter_foo      => {command => 'submitter',
189                              value   => 'foo@bar.com',
190                              status_key => 'originator',
191                              status_value => 'foo@bar.com',
192                             },
193
194       forwarded_foo      => {command => 'forwarded',
195                              value   => 'foo@bar.com',
196                              status_key => 'forwarded',
197                              status_value => 'foo@bar.com',
198                             },
199       owner_foo          => {command => 'owner',
200                              value   => 'foo@bar.com',
201                              status_key => 'owner',
202                              status_value => 'foo@bar.com',
203                             },
204       noowner      => {command => 'noowner',
205                        value   => '',
206                        status_key => 'owner',
207                        status_value => '',
208                       },
209       summary      => {command => 'summary',
210                        value   => '5',
211                        status_key => 'summary',
212                        status_value => 'This is a silly bug',
213                       },
214       nosummary    => {command => 'summary',
215                        value   => '',
216                        status_key => 'summary',
217                        status_value => '',
218                       },
219       affects      => {command => 'affects',
220                        value   => 'foo',
221                        status_key => 'affects',
222                        status_value => 'foo',
223                       },
224       noaffects    => {command => 'affects',
225                        value   => '',
226                        status_key => 'affects',
227                        status_value => '',
228                       },
229       close        => {command => 'close',
230                        value   => '',
231                        status_key => 'done',
232                        status_value => 'foo@bugs.something',
233                       },
234       archive      => {command => 'archive',
235                        value   => '',
236                        status_key => 'owner',
237                        status_value => '',
238                        location => 'archive',
239                       },
240       unarchive    => {command => 'unarchive',
241                        value   => '',
242                        status_key => 'owner',
243                        status_value => '',
244                       },
245      );
246
247 # In order for the archive/unarchive to work, we have to munge the summary file slightly
248 $status = read_bug(bug => 1);
249 $status->{unarchived} = time;
250 writebug(1,$status);
251 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
252      # just check to see that control doesn't explode
253      $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
254           and $control_command->{value} !~ /^\s/;
255      send_message(to => 'control@bugs.something',
256                   headers => [To   => 'control@bugs.something',
257                               From => 'foo@bugs.something',
258                               Subject => "Munging a bug with $command",
259                              ],
260                   body => <<EOF) or fail 'message to control@bugs.something failed';
261 debug 10
262 $control_command->{command} 1$control_command->{value}
263 thanks
264 EOF
265                                   ;
266      $SD_SIZE_NOW = dirsize($sendmail_dir);
267      ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
268      $SD_SIZE_PREV=$SD_SIZE_NOW;
269      # now we need to check to make sure the control message was processed without errors
270      ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
271         'control@bugs.something'. "$command message was parsed without errors");
272      # now we need to check to make sure that the control message actually did anything
273      my $status;
274      $status = read_bug(bug=>1,
275                         exists $control_command->{location}?(location => $control_command->{location}):(),
276                        );
277      is_deeply($status->{$control_command->{status_key}},$control_command->{status_value},"bug 1 $command")
278           or fail(Dumper($status));
279 }
280
281 # verify that archive/unarchive can then be modified afterwards
282
283 send_message(to => 'control@bugs.something',
284              headers => [To   => 'control@bugs.something',
285                          From => 'foo@bugs.something',
286                          Subject => "Munging a bug with unarchivearchive",
287                         ],
288              body => <<'EOF') or fail 'message to control@bugs.something failed';
289 archive 1
290 unarchive 1
291 submitter 1 bar@baz.com
292 thanks
293 EOF
294                                   ;
295 $SD_SIZE_NOW = dirsize($sendmail_dir);
296 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
297 $SD_SIZE_PREV=$SD_SIZE_NOW;
298 # now we need to check to make sure the control message was processed without errors
299 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
300    'control@bugs.something'. "unarchive/archive message was parsed without errors");