2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 117;
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.
31 %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
37 my $sendmail_dir = $config{sendmail_dir};
38 my $spool_dir = $config{spool_dir};
39 my $config_dir = $config{config_dir};
43 diag("spool_dir: $spool_dir\n");
44 diag("config_dir: $config_dir\n");
45 diag("sendmail_dir: $sendmail_dir\n");
49 # We're going to use create mime message to create these messages, and
50 # then just send them to receive.
52 send_message(to=>'submit@bugs.something',
53 headers => [To => 'submit@bugs.something',
54 From => 'foo@bugs.something',
55 Subject => 'Submiting a bug',
57 body => <<EOF) or fail('Unable to send message');
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');
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
73 # This keeps track of the previous size of the sendmail directory
76 num_messages_sent($SD_SIZE,2,
78 'submit messages appear to have been sent out properly',
82 # now send a message to the bug
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',
89 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
97 num_messages_sent($SD_SIZE,2,
99 '1@bugs.something messages appear to have been sent out properly');
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',
107 body => <<EOF) or fail 'message to control@bugs.something failed';
114 num_messages_sent($SD_SIZE,1,
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');
127 # now we're going to go through and methododically test all of the control commands.
128 my @control_commands =
130 severity_wishlist => {command => 'severity',
132 status_key => 'severity',
133 status_value => 'wishlist',
135 reassign_bar_baz => {command => 'reassign',
137 status_key => 'package',
138 status_value => 'bar,baz',
140 reassign_foo => {command => 'reassign',
142 status_key => 'package',
143 status_value => 'foo',
145 'found_1.0' => {command => 'found',
147 status_key => 'found_versions',
148 status_value => ['1.0'],
150 'notfound_1.0' => {command => 'notfound',
152 status_key => 'found_versions',
155 'found_1.0~5+1b2' => {command => 'found',
156 value => '1.0~5+1b2',
157 status_key => 'found_versions',
158 status_value => ['1.0~5+1b2'],
160 'notfound_1.0~5+1b2' => {command => 'notfound',
161 value => '1.0~5+1b2',
162 status_key => 'found_versions',
165 'fixed_1.1' => {command => 'fixed',
167 status_key => 'fixed_versions',
168 status_value => ['1.1'],
170 'notfixed_1.1' => {command => 'notfixed',
172 status_key => 'fixed_versions',
175 'found_1.0~5+1b2' => {command => 'found',
176 value => '1.0~5+1b2',
177 status_key => 'found_versions',
178 status_value => ['1.0~5+1b2'],
180 'fixed_1.2' => {command => 'fixed',
182 status_key => 'fixed_versions',
183 status_value => ['1.2'],
185 close => {command => 'close',
187 status_key => 'done',
188 status_value => 'foo@bugs.something',
190 'found_1.3' => {command => 'found',
192 status_key => 'done',
195 submitter_foo => {command => 'submitter',
196 value => 'foo@bar.com',
197 status_key => 'originator',
198 status_value => 'foo@bar.com',
201 forwarded_foo => {command => 'forwarded',
202 value => 'foo@bar.com',
203 status_key => 'forwarded',
204 status_value => 'foo@bar.com',
206 owner_foo => {command => 'owner',
207 value => 'foo@bar.com',
208 status_key => 'owner',
209 status_value => 'foo@bar.com',
211 noowner => {command => 'noowner',
213 status_key => 'owner',
216 clone => {command => 'clone',
218 status_key => 'package',
219 status_value => 'foo',
222 merge => {command => 'merge',
224 status_key => 'mergedwith',
227 unmerge => {command => 'unmerge',
229 status_key => 'mergedwith',
232 forcemerge => {command => 'forcemerge',
234 status_key => 'mergedwith',
237 unmerge => {command => 'unmerge',
239 status_key => 'mergedwith',
242 block => {command => 'block',
244 status_key => 'blockedby',
247 unblock => {command => 'unblock',
249 status_key => 'blockedby',
252 summary => {command => 'summary',
254 status_key => 'summary',
255 status_value => 'This is a silly bug',
257 nosummary => {command => 'summary',
259 status_key => 'summary',
262 affects => {command => 'affects',
264 status_key => 'affects',
265 status_value => 'foo',
267 noaffects => {command => 'affects',
269 status_key => 'affects',
272 close => {command => 'close',
274 status_key => 'done',
275 status_value => 'foo@bugs.something',
277 archive => {command => 'archive',
279 status_key => 'owner',
281 location => 'archive',
283 unarchive => {command => 'unarchive',
285 status_key => 'owner',
288 tag => {command => 'tag',
290 status_key => 'keywords',
291 status_value => 'patch',
293 untag => {command => 'tag',
295 status_key => 'keywords',
298 plustag => {command => 'tag',
300 status_key => 'keywords',
301 status_value => 'patch',
303 utf8_retitle => {command => 'retitle',
304 value => 'Thïs is a ütff8 title [♥♡☙☎]',
305 status_key => 'subject',
306 status_value => decode("utf8",'Thïs is a ütff8 title [♥♡☙☎]'),
310 # In order for the archive/unarchive to work, we have to munge the summary file slightly
311 $status = read_bug(bug => 1);
312 $status->{unarchived} = time;
314 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
315 # just check to see that control doesn't explode
316 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
317 and $control_command->{value} !~ /^\s/;
318 send_message(to => 'control@bugs.something',
319 headers => [To => 'control@bugs.something',
320 From => 'foo@bugs.something',
321 Subject => "Munging a bug with $command",
323 body => <<EOF) or fail 'message to control@bugs.something failed';
325 $control_command->{command} 1$control_command->{value}
330 num_messages_sent($SD_SIZE,1,
332 'control@bugs.something messages appear to have been sent out properly');
333 # now we need to check to make sure the control message was processed without errors
334 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
335 'control@bugs.something'. "$command message was parsed without errors");
336 # now we need to check to make sure that the control message actually did anything
338 $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
339 exists $control_command->{location}?(location => $control_command->{location}):(),
341 is_deeply($status->{$control_command->{status_key}},
342 $control_command->{status_value},
344 (exists $control_command->{bug}?$control_command->{bug}:1).
347 or fail(Dumper($status));
350 # verify that archive/unarchive can then be modified afterwards
352 send_message(to => 'control@bugs.something',
353 headers => [To => 'control@bugs.something',
354 From => 'foo@bugs.something',
355 Subject => "Munging a bug with unarchivearchive",
357 body => <<'EOF') or fail 'message to control@bugs.something failed';
361 submitter 1 bar@baz.com
366 num_messages_sent($SD_SIZE,1,
368 'control@bugs.something messages appear to have been sent out properly');
369 # now we need to check to make sure the control message was processed without errors
370 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
371 'control@bugs.something'. "unarchive/archive message was parsed without errors");