]> git.donarmstrong.com Git - debbugs.git/blob - t/06_mail_handling.t
8285792260cdbfee8cd45602f6f39ada2b9e8610
[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 => 114;
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 = 0;
74 $SD_SIZE =
75     num_messages_sent($SD_SIZE,2,
76                       $sendmail_dir,
77                       'submit messages appear to have been sent out properly',
78                      );
79
80
81 # now send a message to the bug
82
83 send_message(to => '1@bugs.something',
84              headers => [To   => '1@bugs.something',
85                          From => 'foo@bugs.something',
86                          Subject => 'Sending a message to a bug',
87                         ],
88              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
89 Package: foo
90 Severity: normal
91
92 This is a silly bug
93 EOF
94
95 $SD_SIZE =
96     num_messages_sent($SD_SIZE,2,
97                       $sendmail_dir,
98                       '1@bugs.something messages appear to have been sent out properly');
99
100 # just check to see that control doesn't explode
101 send_message(to => 'control@bugs.something',
102              headers => [To   => 'control@bugs.something',
103                          From => 'foo@bugs.something',
104                          Subject => 'Munging a bug',
105                         ],
106              body => <<EOF) or fail 'message to control@bugs.something failed';
107 severity 1 wishlist
108 retitle 1 new title
109 thanks
110 EOF
111
112 $SD_SIZE =
113    num_messages_sent($SD_SIZE,1,
114                      $sendmail_dir,
115                      'control@bugs.something messages appear to have been sent out properly');
116 # now we need to check to make sure the control message was processed without errors
117 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
118    'control@bugs.something message was parsed without errors');
119 # now we need to check to make sure that the control message actually did anything
120 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
121 eval "use Debbugs::Status qw(read_bug writebug);";
122 my $status = read_bug(bug=>1);
123 ok($status->{subject} eq 'new title','bug 1 retitled');
124 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
125
126 # now we're going to go through and methododically test all of the control commands.
127 my @control_commands =
128      (
129       severity_wishlist => {command => 'severity',
130                             value   => 'wishlist',
131                             status_key => 'severity',
132                             status_value => 'wishlist',
133                            },
134       reassign_bar_baz => {command => 'reassign',
135                            value   => 'bar,baz',
136                            status_key => 'package',
137                            status_value => 'bar,baz',
138                           },
139       reassign_foo => {command => 'reassign',
140                        value   => 'foo',
141                        status_key => 'package',
142                        status_value => 'foo',
143                       },
144       'found_1.0'        => {command => 'found',
145                              value   => '1.0',
146                              status_key => 'found_versions',
147                              status_value => ['1.0'],
148                             },
149       'notfound_1.0'     => {command => 'notfound',
150                              value   => '1.0',
151                              status_key => 'found_versions',
152                              status_value => [],
153                             },
154       'found_1.0~5+1b2'  => {command => 'found',
155                              value   => '1.0~5+1b2',
156                              status_key => 'found_versions',
157                              status_value => ['1.0~5+1b2'],
158                             },
159       'notfound_1.0~5+1b2' => {command => 'notfound',
160                                value   => '1.0~5+1b2',
161                                status_key => 'found_versions',
162                                status_value => [],
163                               },
164       'fixed_1.1'        => {command => 'fixed',
165                              value   => '1.1',
166                              status_key => 'fixed_versions',
167                              status_value => ['1.1'],
168                             },
169       'notfixed_1.1'     => {command => 'notfixed',
170                              value   => '1.1',
171                              status_key => 'fixed_versions',
172                              status_value => [],
173                             },
174       'found_1.0~5+1b2'  => {command => 'found',
175                              value   => '1.0~5+1b2',
176                              status_key => 'found_versions',
177                              status_value => ['1.0~5+1b2'],
178                             },
179       'fixed_1.2'        => {command => 'fixed',
180                              value   => '1.2',
181                              status_key => 'fixed_versions',
182                              status_value => ['1.2'],
183                             },
184       close              => {command => 'close',
185                              value   => '',
186                              status_key => 'done',
187                              status_value => 'foo@bugs.something',
188                             },
189       'found_1.3'        => {command => 'found',
190                              value   => '1.3',
191                              status_key => 'done',
192                              status_value => '',
193                             },
194       submitter_foo      => {command => 'submitter',
195                              value   => 'foo@bar.com',
196                              status_key => 'originator',
197                              status_value => 'foo@bar.com',
198                             },
199
200       forwarded_foo      => {command => 'forwarded',
201                              value   => 'foo@bar.com',
202                              status_key => 'forwarded',
203                              status_value => 'foo@bar.com',
204                             },
205       owner_foo          => {command => 'owner',
206                              value   => 'foo@bar.com',
207                              status_key => 'owner',
208                              status_value => 'foo@bar.com',
209                             },
210       noowner      => {command => 'noowner',
211                        value   => '',
212                        status_key => 'owner',
213                        status_value => '',
214                       },
215       clone        => {command => 'clone',
216                        value   => '-1',
217                        status_key => 'package',
218                        status_value => 'foo',
219                        bug          => '2',
220                       },
221       merge        => {command => 'merge',
222                        value   => '1 2',
223                        status_key => 'mergedwith',
224                        status_value => '2',
225                       },
226       unmerge      => {command => 'unmerge',
227                        value   => '',
228                        status_key => 'mergedwith',
229                        status_value => '',
230                       },
231       forcemerge   => {command => 'forcemerge',
232                        value   => '2',
233                        status_key => 'mergedwith',
234                        status_value => '2',
235                       },
236       unmerge      => {command => 'unmerge',
237                        value   => '',
238                        status_key => 'mergedwith',
239                        status_value => '',
240                       },
241       block        => {command => 'block',
242                        value   => ' with 2',
243                        status_key => 'blockedby',
244                        status_value => '2',
245                       },
246       unblock      => {command => 'unblock',
247                        value   => ' with 2',
248                        status_key => 'blockedby',
249                        status_value => '',
250                       },
251       summary      => {command => 'summary',
252                        value   => '5',
253                        status_key => 'summary',
254                        status_value => 'This is a silly bug',
255                       },
256       nosummary    => {command => 'summary',
257                        value   => '',
258                        status_key => 'summary',
259                        status_value => '',
260                       },
261       affects      => {command => 'affects',
262                        value   => 'foo',
263                        status_key => 'affects',
264                        status_value => 'foo',
265                       },
266       noaffects    => {command => 'affects',
267                        value   => '',
268                        status_key => 'affects',
269                        status_value => '',
270                       },
271       close        => {command => 'close',
272                        value   => '',
273                        status_key => 'done',
274                        status_value => 'foo@bugs.something',
275                       },
276       archive      => {command => 'archive',
277                        value   => '',
278                        status_key => 'owner',
279                        status_value => '',
280                        location => 'archive',
281                       },
282       unarchive    => {command => 'unarchive',
283                        value   => '',
284                        status_key => 'owner',
285                        status_value => '',
286                       },
287       tag          => {command => 'tag',
288                        value   => ' = patch',
289                        status_key => 'keywords',
290                        status_value => 'patch',
291                       },
292       untag        => {command => 'tag',
293                        value   => ' - patch',
294                        status_key => 'keywords',
295                        status_value => '',
296                       },
297       plustag      => {command => 'tag',
298                        value   => ' + patch',
299                        status_key => 'keywords',
300                        status_value => 'patch',
301                       },
302      );
303
304 # In order for the archive/unarchive to work, we have to munge the summary file slightly
305 $status = read_bug(bug => 1);
306 $status->{unarchived} = time;
307 writebug(1,$status);
308 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
309      # just check to see that control doesn't explode
310      $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
311           and $control_command->{value} !~ /^\s/;
312      send_message(to => 'control@bugs.something',
313                   headers => [To   => 'control@bugs.something',
314                               From => 'foo@bugs.something',
315                               Subject => "Munging a bug with $command",
316                              ],
317                   body => <<EOF) or fail 'message to control@bugs.something failed';
318 debug 10
319 $control_command->{command} 1$control_command->{value}
320 thanks
321 EOF
322                                   ;
323      $SD_SIZE =
324          num_messages_sent($SD_SIZE,1,
325                            $sendmail_dir,
326                            'control@bugs.something messages appear to have been sent out properly');
327      # now we need to check to make sure the control message was processed without errors
328      ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
329         'control@bugs.something'. "$command message was parsed without errors");
330      # now we need to check to make sure that the control message actually did anything
331      my $status;
332      $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
333                         exists $control_command->{location}?(location => $control_command->{location}):(),
334                        );
335      is_deeply($status->{$control_command->{status_key}},
336                $control_command->{status_value},
337                "bug " .
338                (exists $control_command->{bug}?$control_command->{bug}:1).
339                " $command"
340               )
341           or fail(Dumper($status));
342 }
343
344 # verify that archive/unarchive can then be modified afterwards
345
346 send_message(to => 'control@bugs.something',
347              headers => [To   => 'control@bugs.something',
348                          From => 'foo@bugs.something',
349                          Subject => "Munging a bug with unarchivearchive",
350                         ],
351              body => <<'EOF') or fail 'message to control@bugs.something failed';
352 debug 10
353 archive 1
354 unarchive 1
355 submitter 1 bar@baz.com
356 thanks
357 EOF
358                                   ;
359 $SD_SIZE =
360     num_messages_sent($SD_SIZE,1,
361                       $sendmail_dir,
362                       'control@bugs.something messages appear to have been sent out properly');
363 # now we need to check to make sure the control message was processed without errors
364 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
365    'control@bugs.something'. "unarchive/archive message was parsed without errors");