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