]> git.donarmstrong.com Git - debbugs.git/blob - t/06_mail_handling.t
support -done being set in a psuedoheader
[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 => 127;
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 use Encode qw(decode encode);
26
27 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
28 $SIG{CHLD} = sub {};
29 my %config = create_debbugs_configuration();
30
31
32 my $sendmail_dir = $config{sendmail_dir};
33 my $spool_dir = $config{spool_dir};
34 my $config_dir = $config{config_dir};
35
36
37
38 # We're going to use create mime message to create these messages, and
39 # then just send them to receive.
40
41 send_message(to=>'submit@bugs.something',
42              headers => [To   => 'submit@bugs.something',
43                          From => 'foo@bugs.something',
44                          Subject => 'Submiting a bug',
45                         ],
46              body => <<EOF) or fail('Unable to send message');
47 Package: foo
48 Severity: normal
49
50 This is a silly bug
51 EOF
52
53 # now we check to see that we have a bug, and nextnumber has been incremented
54 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
55 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
56 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
57 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
58
59 # next, we check to see that (at least) the proper messages have been
60 # sent out. 1) ack to submitter 2) mail to maintainer
61
62 # This keeps track of the previous size of the sendmail directory
63 my $SD_SIZE = 0;
64 $SD_SIZE =
65     num_messages_sent($SD_SIZE,2,
66                       $sendmail_dir,
67                       'submit messages appear to have been sent out properly',
68                      );
69
70
71 # now send a message to the bug
72
73 send_message(to => '1@bugs.something',
74              headers => [To   => '1@bugs.something',
75                          From => 'foo@bugs.something',
76                          Subject => 'Sending a message to a bug',
77                         ],
78              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
79 Package: foo
80 Severity: normal
81
82 This is a silly bug
83 EOF
84
85 $SD_SIZE =
86     num_messages_sent($SD_SIZE,2,
87                       $sendmail_dir,
88                       '1@bugs.something messages appear to have been sent out properly');
89
90 # just check to see that control doesn't explode
91 send_message(to => 'control@bugs.something',
92              headers => [To   => 'control@bugs.something',
93                          From => 'foo@bugs.something',
94                          Subject => 'Munging a bug',
95                         ],
96              body => <<EOF) or fail 'message to control@bugs.something failed';
97 severity 1 wishlist
98 retitle 1 new title
99 thanks
100 EOF
101
102 $SD_SIZE =
103    num_messages_sent($SD_SIZE,1,
104                      $sendmail_dir,
105                      'control@bugs.something messages appear to have been sent out properly');
106 # now we need to check to make sure the control message was processed without errors
107 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
108    'control@bugs.something message was parsed without errors');
109 # now we need to check to make sure that the control message actually did anything
110 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
111 eval "use Debbugs::Status qw(read_bug writebug);";
112 my $status = read_bug(bug=>1);
113 ok($status->{subject} eq 'new title','bug 1 retitled');
114 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
115
116 # now check to see if we can close a bug using a psuedoheader done
117 send_message(to => '1-done@bugs.something',
118              headers => [To   => 'control@bugs.something',
119                          From => 'foo@bugs.something',
120                          Subject => 'Munging a bug',
121                         ],
122              body => <<'EOF') or fail 'message to control@bugs.something failed';
123 Done: Me Developer <me@bugs.something>
124
125 I'm closing this bug for reasons
126 EOF
127
128 $status = read_bug(bug=>1);
129 ok($status->{done} eq 'Me Developer <me@bugs.something>');
130
131
132 # now we're going to go through and methododically test all of the control commands.
133 my @control_commands =
134      (
135       severity_wishlist => {command => 'severity',
136                             value   => 'wishlist',
137                             status_key => 'severity',
138                             status_value => 'wishlist',
139                            },
140       reassign_bar_baz => {command => 'reassign',
141                            value   => 'bar,baz',
142                            status_key => 'package',
143                            status_value => 'bar,baz',
144                           },
145       reassign_foo => {command => 'reassign',
146                        value   => 'foo',
147                        status_key => 'package',
148                        status_value => 'foo',
149                       },
150       'found_1.0'        => {command => 'found',
151                              value   => '1.0',
152                              status_key => 'found_versions',
153                              status_value => ['1.0'],
154                             },
155       'notfound_1.0'     => {command => 'notfound',
156                              value   => '1.0',
157                              status_key => 'found_versions',
158                              status_value => [],
159                             },
160       'found_1.0~5+1b2'  => {command => 'found',
161                              value   => '1.0~5+1b2',
162                              status_key => 'found_versions',
163                              status_value => ['1.0~5+1b2'],
164                             },
165       'notfound_1.0~5+1b2' => {command => 'notfound',
166                                value   => '1.0~5+1b2',
167                                status_key => 'found_versions',
168                                status_value => [],
169                               },
170       'fixed_1.1'        => {command => 'fixed',
171                              value   => '1.1',
172                              status_key => 'fixed_versions',
173                              status_value => ['1.1'],
174                             },
175       'notfixed_1.1'     => {command => 'notfixed',
176                              value   => '1.1',
177                              status_key => 'fixed_versions',
178                              status_value => [],
179                             },
180       'found_1.0~5+1b2'  => {command => 'found',
181                              value   => '1.0~5+1b2',
182                              status_key => 'found_versions',
183                              status_value => ['1.0~5+1b2'],
184                             },
185       'fixed_1.2'        => {command => 'fixed',
186                              value   => '1.2',
187                              status_key => 'fixed_versions',
188                              status_value => ['1.2'],
189                             },
190       close              => {command => 'close',
191                              value   => '',
192                              status_key => 'done',
193                              status_value => 'foo@bugs.something',
194                             },
195       'found_1.3'        => {command => 'found',
196                              value   => '1.3',
197                              status_key => 'done',
198                              status_value => '',
199                             },
200       submitter_foo      => {command => 'submitter',
201                              value   => 'foo@bar.com',
202                              status_key => 'originator',
203                              status_value => 'foo@bar.com',
204                             },
205
206       forwarded_foo      => {command => 'forwarded',
207                              value   => 'foo@bar.com',
208                              status_key => 'forwarded',
209                              status_value => 'foo@bar.com',
210                             },
211       owner_foo          => {command => 'owner',
212                              value   => 'foo@bar.com',
213                              status_key => 'owner',
214                              status_value => 'foo@bar.com',
215                             },
216       owner_replyto      => {command => 'owner',
217                              value   => '!',
218                              status_key => 'owner',
219                              status_value => 'foo@bugs.something',
220                             },
221       noowner      => {command => 'noowner',
222                        value   => '',
223                        status_key => 'owner',
224                        status_value => '',
225                       },
226       clone        => {command => 'clone',
227                        value   => '-1',
228                        status_key => 'package',
229                        status_value => 'foo',
230                        bug          => '2',
231                       },
232       merge        => {command => 'merge',
233                        value   => '1 2',
234                        status_key => 'mergedwith',
235                        status_value => '2',
236                       },
237       unmerge      => {command => 'unmerge',
238                        value   => '',
239                        status_key => 'mergedwith',
240                        status_value => '',
241                       },
242       forcemerge   => {command => 'forcemerge',
243                        value   => '2',
244                        status_key => 'mergedwith',
245                        status_value => '2',
246                       },
247       unmerge      => {command => 'unmerge',
248                        value   => '',
249                        status_key => 'mergedwith',
250                        status_value => '',
251                       },
252       block        => {command => 'block',
253                        value   => ' with 2',
254                        status_key => 'blockedby',
255                        status_value => '2',
256                       },
257       unblock      => {command => 'unblock',
258                        value   => ' with 2',
259                        status_key => 'blockedby',
260                        status_value => '',
261                       },
262       summary      => {command => 'summary',
263                        value   => '5',
264                        status_key => 'summary',
265                        status_value => 'This is a silly bug',
266                       },
267       nosummary    => {command => 'summary',
268                        value   => '',
269                        status_key => 'summary',
270                        status_value => '',
271                       },
272       outlook      => {command => 'outlook',
273                        value   => '5',
274                        status_key => 'outlook',
275                        status_value => 'This is a silly bug',
276                       },
277       nooutlook    => {command => 'outlook',
278                        value   => '',
279                        status_key => 'outlook',
280                        status_value => '',
281                       },
282       affects      => {command => 'affects',
283                        value   => 'foo',
284                        status_key => 'affects',
285                        status_value => 'foo',
286                       },
287       noaffects    => {command => 'affects',
288                        value   => '',
289                        status_key => 'affects',
290                        status_value => '',
291                       },
292       close        => {command => 'close',
293                        value   => '',
294                        status_key => 'done',
295                        status_value => 'foo@bugs.something',
296                       },
297       archive      => {command => 'archive',
298                        value   => '',
299                        status_key => 'owner',
300                        status_value => '',
301                        location => 'archive',
302                       },
303       unarchive    => {command => 'unarchive',
304                        value   => '',
305                        status_key => 'owner',
306                        status_value => '',
307                       },
308       tag          => {command => 'tag',
309                        value   => ' = patch',
310                        status_key => 'keywords',
311                        status_value => 'patch',
312                       },
313       untag        => {command => 'tag',
314                        value   => ' - patch',
315                        status_key => 'keywords',
316                        status_value => '',
317                       },
318       plustag      => {command => 'tag',
319                        value   => ' + patch',
320                        status_key => 'keywords',
321                        status_value => 'patch',
322                       },
323       utf8_retitle => {command => 'retitle',
324                        value   => 'Thïs is a ütff8 title [♥♡☙☎]',
325                        status_key => 'subject',
326                        status_value => decode("utf8",'Thïs is a ütff8 title [♥♡☙☎]'),
327                       },
328      );
329
330 # In order for the archive/unarchive to work, we have to munge the summary file slightly
331 $status = read_bug(bug => 1);
332 $status->{unarchived} = time;
333 writebug(1,$status);
334 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
335      # just check to see that control doesn't explode
336      $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
337           and $control_command->{value} !~ /^\s/;
338      send_message(to => 'control@bugs.something',
339                   headers => [To   => 'control@bugs.something',
340                               From => 'foo@bugs.something',
341                               Subject => "Munging a bug with $command",
342                              ],
343                   body => <<EOF) or fail 'message to control@bugs.something failed';
344 debug 10
345 $control_command->{command} 1$control_command->{value}
346 thanks
347 EOF
348                                   ;
349      $SD_SIZE =
350          num_messages_sent($SD_SIZE,1,
351                            $sendmail_dir,
352                            'control@bugs.something messages appear to have been sent out properly');
353      # now we need to check to make sure the control message was processed without errors
354      ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
355         'control@bugs.something'. "$command message was parsed without errors");
356      # now we need to check to make sure that the control message actually did anything
357      my $status;
358      $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
359                         exists $control_command->{location}?(location => $control_command->{location}):(),
360                        );
361      is_deeply($status->{$control_command->{status_key}},
362                $control_command->{status_value},
363                "bug " .
364                (exists $control_command->{bug}?$control_command->{bug}:1).
365                " $command"
366               )
367           or fail(Dumper($status));
368 }
369
370 # verify that archive/unarchive can then be modified afterwards
371
372 send_message(to => 'control@bugs.something',
373              headers => [To   => 'control@bugs.something',
374                          From => 'foo@bugs.something',
375                          Subject => "Munging a bug with unarchivearchive",
376                         ],
377              body => <<'EOF') or fail 'message to control@bugs.something failed';
378 debug 10
379 archive 1
380 unarchive 1
381 submitter 1 bar@baz.com
382 thanks
383 EOF
384                                   ;
385 $SD_SIZE =
386     num_messages_sent($SD_SIZE,1,
387                       $sendmail_dir,
388                       'control@bugs.something messages appear to have been sent out properly');
389 # now we need to check to make sure the control message was processed without errors
390 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
391    'control@bugs.something'. "unarchive/archive message was parsed without errors");