]> git.donarmstrong.com Git - debbugs.git/blob - t/06_mail_handling.t
f0b2b375c9ef6db564e7c8b58daf983751bdfc93
[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 => 126;
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;
30 eval {
31      %config = create_debbugs_configuration();
32 };
33 if ($@) {
34      BAIL_OUT($@);
35 }
36
37 my $sendmail_dir = $config{sendmail_dir};
38 my $spool_dir = $config{spool_dir};
39 my $config_dir = $config{config_dir};
40
41
42
43 # We're going to use create mime message to create these messages, and
44 # then just send them to receive.
45
46 send_message(to=>'submit@bugs.something',
47              headers => [To   => 'submit@bugs.something',
48                          From => 'foo@bugs.something',
49                          Subject => 'Submiting a bug',
50                         ],
51              body => <<EOF) or fail('Unable to send message');
52 Package: foo
53 Severity: normal
54
55 This is a silly bug
56 EOF
57
58 # now we check to see that we have a bug, and nextnumber has been incremented
59 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
60 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
61 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
62 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
63
64 # next, we check to see that (at least) the proper messages have been
65 # sent out. 1) ack to submitter 2) mail to maintainer
66
67 # This keeps track of the previous size of the sendmail directory
68 my $SD_SIZE = 0;
69 $SD_SIZE =
70     num_messages_sent($SD_SIZE,2,
71                       $sendmail_dir,
72                       'submit messages appear to have been sent out properly',
73                      );
74
75
76 # now send a message to the bug
77
78 send_message(to => '1@bugs.something',
79              headers => [To   => '1@bugs.something',
80                          From => 'foo@bugs.something',
81                          Subject => 'Sending a message to a bug',
82                         ],
83              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
84 Package: foo
85 Severity: normal
86
87 This is a silly bug
88 EOF
89
90 $SD_SIZE =
91     num_messages_sent($SD_SIZE,2,
92                       $sendmail_dir,
93                       '1@bugs.something messages appear to have been sent out properly');
94
95 # just check to see that control doesn't explode
96 send_message(to => 'control@bugs.something',
97              headers => [To   => 'control@bugs.something',
98                          From => 'foo@bugs.something',
99                          Subject => 'Munging a bug',
100                         ],
101              body => <<EOF) or fail 'message to control@bugs.something failed';
102 severity 1 wishlist
103 retitle 1 new title
104 thanks
105 EOF
106
107 $SD_SIZE =
108    num_messages_sent($SD_SIZE,1,
109                      $sendmail_dir,
110                      'control@bugs.something messages appear to have been sent out properly');
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      (
124       severity_wishlist => {command => 'severity',
125                             value   => 'wishlist',
126                             status_key => 'severity',
127                             status_value => 'wishlist',
128                            },
129       reassign_bar_baz => {command => 'reassign',
130                            value   => 'bar,baz',
131                            status_key => 'package',
132                            status_value => 'bar,baz',
133                           },
134       reassign_foo => {command => 'reassign',
135                        value   => 'foo',
136                        status_key => 'package',
137                        status_value => 'foo',
138                       },
139       'found_1.0'        => {command => 'found',
140                              value   => '1.0',
141                              status_key => 'found_versions',
142                              status_value => ['1.0'],
143                             },
144       'notfound_1.0'     => {command => 'notfound',
145                              value   => '1.0',
146                              status_key => 'found_versions',
147                              status_value => [],
148                             },
149       'found_1.0~5+1b2'  => {command => 'found',
150                              value   => '1.0~5+1b2',
151                              status_key => 'found_versions',
152                              status_value => ['1.0~5+1b2'],
153                             },
154       'notfound_1.0~5+1b2' => {command => 'notfound',
155                                value   => '1.0~5+1b2',
156                                status_key => 'found_versions',
157                                status_value => [],
158                               },
159       'fixed_1.1'        => {command => 'fixed',
160                              value   => '1.1',
161                              status_key => 'fixed_versions',
162                              status_value => ['1.1'],
163                             },
164       'notfixed_1.1'     => {command => 'notfixed',
165                              value   => '1.1',
166                              status_key => 'fixed_versions',
167                              status_value => [],
168                             },
169       'found_1.0~5+1b2'  => {command => 'found',
170                              value   => '1.0~5+1b2',
171                              status_key => 'found_versions',
172                              status_value => ['1.0~5+1b2'],
173                             },
174       'fixed_1.2'        => {command => 'fixed',
175                              value   => '1.2',
176                              status_key => 'fixed_versions',
177                              status_value => ['1.2'],
178                             },
179       close              => {command => 'close',
180                              value   => '',
181                              status_key => 'done',
182                              status_value => 'foo@bugs.something',
183                             },
184       'found_1.3'        => {command => 'found',
185                              value   => '1.3',
186                              status_key => 'done',
187                              status_value => '',
188                             },
189       submitter_foo      => {command => 'submitter',
190                              value   => 'foo@bar.com',
191                              status_key => 'originator',
192                              status_value => 'foo@bar.com',
193                             },
194
195       forwarded_foo      => {command => 'forwarded',
196                              value   => 'foo@bar.com',
197                              status_key => 'forwarded',
198                              status_value => 'foo@bar.com',
199                             },
200       owner_foo          => {command => 'owner',
201                              value   => 'foo@bar.com',
202                              status_key => 'owner',
203                              status_value => 'foo@bar.com',
204                             },
205       owner_replyto      => {command => 'owner',
206                              value   => '!',
207                              status_key => 'owner',
208                              status_value => 'foo@bugs.something',
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       outlook      => {command => 'outlook',
262                        value   => '5',
263                        status_key => 'outlook',
264                        status_value => 'This is a silly bug',
265                       },
266       nooutlook    => {command => 'outlook',
267                        value   => '',
268                        status_key => 'outlook',
269                        status_value => '',
270                       },
271       affects      => {command => 'affects',
272                        value   => 'foo',
273                        status_key => 'affects',
274                        status_value => 'foo',
275                       },
276       noaffects    => {command => 'affects',
277                        value   => '',
278                        status_key => 'affects',
279                        status_value => '',
280                       },
281       close        => {command => 'close',
282                        value   => '',
283                        status_key => 'done',
284                        status_value => 'foo@bugs.something',
285                       },
286       archive      => {command => 'archive',
287                        value   => '',
288                        status_key => 'owner',
289                        status_value => '',
290                        location => 'archive',
291                       },
292       unarchive    => {command => 'unarchive',
293                        value   => '',
294                        status_key => 'owner',
295                        status_value => '',
296                       },
297       tag          => {command => 'tag',
298                        value   => ' = patch',
299                        status_key => 'keywords',
300                        status_value => 'patch',
301                       },
302       untag        => {command => 'tag',
303                        value   => ' - patch',
304                        status_key => 'keywords',
305                        status_value => '',
306                       },
307       plustag      => {command => 'tag',
308                        value   => ' + patch',
309                        status_key => 'keywords',
310                        status_value => 'patch',
311                       },
312       utf8_retitle => {command => 'retitle',
313                        value   => 'Thïs is a ütff8 title [♥♡☙☎]',
314                        status_key => 'subject',
315                        status_value => decode("utf8",'Thïs is a ütff8 title [♥♡☙☎]'),
316                       },
317      );
318
319 # In order for the archive/unarchive to work, we have to munge the summary file slightly
320 $status = read_bug(bug => 1);
321 $status->{unarchived} = time;
322 writebug(1,$status);
323 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
324      # just check to see that control doesn't explode
325      $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
326           and $control_command->{value} !~ /^\s/;
327      send_message(to => 'control@bugs.something',
328                   headers => [To   => 'control@bugs.something',
329                               From => 'foo@bugs.something',
330                               Subject => "Munging a bug with $command",
331                              ],
332                   body => <<EOF) or fail 'message to control@bugs.something failed';
333 debug 10
334 $control_command->{command} 1$control_command->{value}
335 thanks
336 EOF
337                                   ;
338      $SD_SIZE =
339          num_messages_sent($SD_SIZE,1,
340                            $sendmail_dir,
341                            'control@bugs.something messages appear to have been sent out properly');
342      # now we need to check to make sure the control message was processed without errors
343      ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
344         'control@bugs.something'. "$command message was parsed without errors");
345      # now we need to check to make sure that the control message actually did anything
346      my $status;
347      $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
348                         exists $control_command->{location}?(location => $control_command->{location}):(),
349                        );
350      is_deeply($status->{$control_command->{status_key}},
351                $control_command->{status_value},
352                "bug " .
353                (exists $control_command->{bug}?$control_command->{bug}:1).
354                " $command"
355               )
356           or fail(Dumper($status));
357 }
358
359 # verify that archive/unarchive can then be modified afterwards
360
361 send_message(to => 'control@bugs.something',
362              headers => [To   => 'control@bugs.something',
363                          From => 'foo@bugs.something',
364                          Subject => "Munging a bug with unarchivearchive",
365                         ],
366              body => <<'EOF') or fail 'message to control@bugs.something failed';
367 debug 10
368 archive 1
369 unarchive 1
370 submitter 1 bar@baz.com
371 thanks
372 EOF
373                                   ;
374 $SD_SIZE =
375     num_messages_sent($SD_SIZE,1,
376                       $sendmail_dir,
377                       'control@bugs.something messages appear to have been sent out properly');
378 # now we need to check to make sure the control message was processed without errors
379 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
380    'control@bugs.something'. "unarchive/archive message was parsed without errors");