2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 126;
9 # Here, we're going to shoot messages through a set of things that can
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.
17 use File::Temp qw(tempdir);
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
23 use DebbugsTest qw(:all);
25 use Encode qw(decode encode);
27 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
29 my %config = create_debbugs_configuration();
32 my $sendmail_dir = $config{sendmail_dir};
33 my $spool_dir = $config{spool_dir};
34 my $config_dir = $config{config_dir};
38 # We're going to use create mime message to create these messages, and
39 # then just send them to receive.
41 send_message(to=>'submit@bugs.something',
42 headers => [To => 'submit@bugs.something',
43 From => 'foo@bugs.something',
44 Subject => 'Submiting a bug',
46 body => <<EOF) or fail('Unable to send message');
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');
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
62 # This keeps track of the previous size of the sendmail directory
65 num_messages_sent($SD_SIZE,2,
67 'submit messages appear to have been sent out properly',
71 # now send a message to the bug
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',
78 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
86 num_messages_sent($SD_SIZE,2,
88 '1@bugs.something messages appear to have been sent out properly');
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',
96 body => <<EOF) or fail 'message to control@bugs.something failed';
103 num_messages_sent($SD_SIZE,1,
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');
116 # now we're going to go through and methododically test all of the control commands.
117 my @control_commands =
119 severity_wishlist => {command => 'severity',
121 status_key => 'severity',
122 status_value => 'wishlist',
124 reassign_bar_baz => {command => 'reassign',
126 status_key => 'package',
127 status_value => 'bar,baz',
129 reassign_foo => {command => 'reassign',
131 status_key => 'package',
132 status_value => 'foo',
134 'found_1.0' => {command => 'found',
136 status_key => 'found_versions',
137 status_value => ['1.0'],
139 'notfound_1.0' => {command => 'notfound',
141 status_key => 'found_versions',
144 'found_1.0~5+1b2' => {command => 'found',
145 value => '1.0~5+1b2',
146 status_key => 'found_versions',
147 status_value => ['1.0~5+1b2'],
149 'notfound_1.0~5+1b2' => {command => 'notfound',
150 value => '1.0~5+1b2',
151 status_key => 'found_versions',
154 'fixed_1.1' => {command => 'fixed',
156 status_key => 'fixed_versions',
157 status_value => ['1.1'],
159 'notfixed_1.1' => {command => 'notfixed',
161 status_key => 'fixed_versions',
164 'found_1.0~5+1b2' => {command => 'found',
165 value => '1.0~5+1b2',
166 status_key => 'found_versions',
167 status_value => ['1.0~5+1b2'],
169 'fixed_1.2' => {command => 'fixed',
171 status_key => 'fixed_versions',
172 status_value => ['1.2'],
174 close => {command => 'close',
176 status_key => 'done',
177 status_value => 'foo@bugs.something',
179 'found_1.3' => {command => 'found',
181 status_key => 'done',
184 submitter_foo => {command => 'submitter',
185 value => 'foo@bar.com',
186 status_key => 'originator',
187 status_value => 'foo@bar.com',
190 forwarded_foo => {command => 'forwarded',
191 value => 'foo@bar.com',
192 status_key => 'forwarded',
193 status_value => 'foo@bar.com',
195 owner_foo => {command => 'owner',
196 value => 'foo@bar.com',
197 status_key => 'owner',
198 status_value => 'foo@bar.com',
200 owner_replyto => {command => 'owner',
202 status_key => 'owner',
203 status_value => 'foo@bugs.something',
205 noowner => {command => 'noowner',
207 status_key => 'owner',
210 clone => {command => 'clone',
212 status_key => 'package',
213 status_value => 'foo',
216 merge => {command => 'merge',
218 status_key => 'mergedwith',
221 unmerge => {command => 'unmerge',
223 status_key => 'mergedwith',
226 forcemerge => {command => 'forcemerge',
228 status_key => 'mergedwith',
231 unmerge => {command => 'unmerge',
233 status_key => 'mergedwith',
236 block => {command => 'block',
238 status_key => 'blockedby',
241 unblock => {command => 'unblock',
243 status_key => 'blockedby',
246 summary => {command => 'summary',
248 status_key => 'summary',
249 status_value => 'This is a silly bug',
251 nosummary => {command => 'summary',
253 status_key => 'summary',
256 outlook => {command => 'outlook',
258 status_key => 'outlook',
259 status_value => 'This is a silly bug',
261 nooutlook => {command => 'outlook',
263 status_key => 'outlook',
266 affects => {command => 'affects',
268 status_key => 'affects',
269 status_value => 'foo',
271 noaffects => {command => 'affects',
273 status_key => 'affects',
276 close => {command => 'close',
278 status_key => 'done',
279 status_value => 'foo@bugs.something',
281 archive => {command => 'archive',
283 status_key => 'owner',
285 location => 'archive',
287 unarchive => {command => 'unarchive',
289 status_key => 'owner',
292 tag => {command => 'tag',
294 status_key => 'keywords',
295 status_value => 'patch',
297 untag => {command => 'tag',
299 status_key => 'keywords',
302 plustag => {command => 'tag',
304 status_key => 'keywords',
305 status_value => 'patch',
307 utf8_retitle => {command => 'retitle',
308 value => 'Thïs is a ütff8 title [♥♡☙☎]',
309 status_key => 'subject',
310 status_value => decode("utf8",'Thïs is a ütff8 title [♥♡☙☎]'),
314 # In order for the archive/unarchive to work, we have to munge the summary file slightly
315 $status = read_bug(bug => 1);
316 $status->{unarchived} = time;
318 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
319 # just check to see that control doesn't explode
320 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
321 and $control_command->{value} !~ /^\s/;
322 send_message(to => 'control@bugs.something',
323 headers => [To => 'control@bugs.something',
324 From => 'foo@bugs.something',
325 Subject => "Munging a bug with $command",
327 body => <<EOF) or fail 'message to control@bugs.something failed';
329 $control_command->{command} 1$control_command->{value}
334 num_messages_sent($SD_SIZE,1,
336 'control@bugs.something messages appear to have been sent out properly');
337 # now we need to check to make sure the control message was processed without errors
338 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
339 'control@bugs.something'. "$command message was parsed without errors");
340 # now we need to check to make sure that the control message actually did anything
342 $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
343 exists $control_command->{location}?(location => $control_command->{location}):(),
345 is_deeply($status->{$control_command->{status_key}},
346 $control_command->{status_value},
348 (exists $control_command->{bug}?$control_command->{bug}:1).
351 or fail(Dumper($status));
354 # verify that archive/unarchive can then be modified afterwards
356 send_message(to => 'control@bugs.something',
357 headers => [To => 'control@bugs.something',
358 From => 'foo@bugs.something',
359 Subject => "Munging a bug with unarchivearchive",
361 body => <<'EOF') or fail 'message to control@bugs.something failed';
365 submitter 1 bar@baz.com
370 num_messages_sent($SD_SIZE,1,
372 'control@bugs.something messages appear to have been sent out properly');
373 # now we need to check to make sure the control message was processed without errors
374 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
375 'control@bugs.something'. "unarchive/archive message was parsed without errors");