import rt 3.4.6
[freeside.git] / rt / lib / t / regression / 06mailgateway.t
1 #!/usr/bin/perl -w
2 # BEGIN BPS TAGGED BLOCK {{{
3
4 # COPYRIGHT:
5 #  
6 # This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
7 #                                          <jesse.com>
8
9 # (Except where explicitly superseded by other copyright notices)
10
11
12 # LICENSE:
13
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
17 # from www.gnu.org.
18
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 # General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28
29 # CONTRIBUTION SUBMISSION POLICY:
30
31 # (The following paragraph is not intended to limit the rights granted
32 # to you to modify and distribute this software under the terms of
33 # the GNU General Public License and is only of importance to you if
34 # you choose to contribute your changes and enhancements to the
35 # community by submitting them to Best Practical Solutions, LLC.)
36
37 # By intentionally submitting any modifications, corrections or
38 # derivatives to this work, or any other work intended for use with
39 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
40 # you are the copyright holder for those contributions and you grant
41 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
42 # royalty-free, perpetual, license to use, copy, create derivative
43 # works based on those contributions, and sublicense and distribute
44 # those contributions and any derivatives thereof.
45
46 # END BPS TAGGED BLOCK }}}
47
48 =head1 NAME
49
50 rt-mailgate - Mail interface to RT3.
51
52 =cut
53
54 use strict;
55 use Test::More tests => 104;
56
57 use RT;
58 RT::LoadConfig();
59 RT::Init();
60 use RT::I18N;
61
62 no warnings 'once';
63 my $url = join( ':', grep $_, "http://localhost", $RT::WebPort ) . $RT::WebPath ."/";
64
65 # Make sure that when we call the mailgate wrong, it tempfails
66
67 $! = '';
68 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url http://this.test.for.non-connection.is.expected.to.generate.an.error"), "Opened the mailgate - The error below is expected - $@");
69 print MAIL <<EOF;
70 From: root\@localhost
71 To: rt\@$RT::rtname
72 Subject: This is a test of new ticket creation
73
74 Foob!
75 EOF
76 close (MAIL);
77
78 # Check the return value
79 is ( $? >> 8, 75, "The error message above is expected The mail gateway exited with a failure. yay");
80
81
82 # {{{ Test new ticket creation by root who is privileged and superuser
83
84 $! = '';
85 ok(open(MAIL, "|$RT::BinPath/rt-mailgate  --debug --url $url --queue general --action correspond"), "Opened the mailgate - $!");
86 print MAIL <<EOF;
87 From: root\@localhost
88 To: rt\@$RT::rtname
89 Subject: This is a test of new ticket creation
90
91 Blah!
92 Foob!
93 EOF
94 close (MAIL);
95
96 #Check the return value
97 is ($? >> 8, 0, "The mail gateway exited normally. yay");
98
99 use RT::Tickets;
100 my $tickets = RT::Tickets->new($RT::SystemUser);
101 $tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
102 $tickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
103 my $tick = $tickets->First();
104 ok (UNIVERSAL::isa($tick,'RT::Ticket'));
105 ok ($tick->Id, "found ticket ".$tick->Id);
106 ok ($tick->Subject eq 'This is a test of new ticket creation', "Created the ticket");
107
108 # }}}
109
110
111 # {{{This is a test of new ticket creation as an unknown user
112
113 $! = '';
114 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
115 print MAIL <<EOF;
116 From: doesnotexist\@$RT::rtname
117 To: rt\@$RT::rtname
118 Subject: This is a test of new ticket creation as an unknown user
119
120 Blah!
121 Foob!
122 EOF
123 close (MAIL);
124 #Check the return value
125 is ($? >> 8, 0, "The mail gateway exited normally. yay");
126
127 $tickets = RT::Tickets->new($RT::SystemUser);
128 $tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
129 $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0');
130 $tick = $tickets->First();
131 ok ($tick->Id, "found ticket ".$tick->Id);
132 ok ($tick->Subject ne 'This is a test of new ticket creation as an unknown user', "failed to create the new ticket from an unprivileged account");
133 my $u = RT::User->new($RT::SystemUser);
134 $u->Load("doesnotexist\@$RT::rtname");
135 ok( $u->Id == 0, " user does not exist and was not created by failed ticket submission");
136
137
138 # }}}
139
140 # {{{ now everybody can create tickets.  can a random unkown user create tickets?
141
142 my $g = RT::Group->new($RT::SystemUser);
143 $g->LoadSystemInternalGroup('Everyone');
144 ok( $g->Id, "Found 'everybody'");
145
146 my ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
147 ok ($val, "Granted everybody the right to create tickets - $msg");
148
149
150 $! = '';
151 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
152 print MAIL <<EOF;
153 From: doesnotexist\@$RT::rtname
154 To: rt\@$RT::rtname
155 Subject: This is a test of new ticket creation as an unknown user
156
157 Blah!
158 Foob!
159 EOF
160 close (MAIL);
161 #Check the return value
162 is ($? >> 8, 0, "The mail gateway exited normally. yay");
163
164
165 $tickets = RT::Tickets->new($RT::SystemUser);
166 $tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
167 $tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0');
168 $tick = $tickets->First();
169 ok ($tick->Id, "found ticket ".$tick->Id);
170 ok ($tick->Subject eq 'This is a test of new ticket creation as an unknown user', "failed to create the new ticket from an unprivileged account");
171  $u = RT::User->new($RT::SystemUser);
172 $u->Load("doesnotexist\@$RT::rtname");
173 ok( $u->Id != 0, " user does not exist and was created by ticket submission");
174
175 # }}}
176
177
178 # {{{  can another random reply to a ticket without being granted privs? answer should be no.
179
180
181 #($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
182 #ok ($val, "Granted everybody the right to create tickets - $msg");
183
184 $! = '';
185 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
186 print MAIL <<EOF;
187 From: doesnotexist-2\@$RT::rtname
188 To: rt\@$RT::rtname
189 Subject: [$RT::rtname #@{[$tick->Id]}] This is a test of a reply as an unknown user
190
191 Blah!  (Should not work.)
192 Foob!
193 EOF
194 close (MAIL);
195 #Check the return value
196 is ($? >> 8, 0, "The mail gateway exited normally. yay");
197
198 $u = RT::User->new($RT::SystemUser);
199 $u->Load('doesnotexist-2@$RT::rtname');
200 ok( $u->Id == 0, " user does not exist and was not created by ticket correspondence submission");
201 # }}}
202
203
204 # {{{  can another random reply to a ticket after being granted privs? answer should be yes
205
206
207 ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'ReplyToTicket');
208 ok ($val, "Granted everybody the right to reply to  tickets - $msg");
209
210 $! = '';
211 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
212 print MAIL <<EOF;
213 From: doesnotexist-2\@$RT::rtname
214 To: rt\@$RT::rtname
215 Subject: [$RT::rtname #@{[$tick->Id]}] This is a test of a reply as an unknown user
216
217 Blah!
218 Foob!
219 EOF
220 close (MAIL);
221 #Check the return value
222 is ($? >> 8, 0, "The mail gateway exited normally. yay");
223
224
225 $u = RT::User->new($RT::SystemUser);
226 $u->Load("doesnotexist-2\@$RT::rtname");
227 ok( $u->Id != 0, " user exists and was created by ticket correspondence submission");
228
229 # }}}
230
231 # {{{  can another random comment on a ticket without being granted privs? answer should be no.
232
233
234 #($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
235 #ok ($val, "Granted everybody the right to create tickets - $msg");
236
237 $! = '';
238 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $!");
239 print MAIL <<EOF;
240 From: doesnotexist-3\@$RT::rtname
241 To: rt\@$RT::rtname
242 Subject: [$RT::rtname #@{[$tick->Id]}] This is a test of a comment as an unknown user
243
244 Blah!  (Should not work.)
245 Foob!
246 EOF
247 close (MAIL);
248
249 #Check the return value
250 is ($? >> 8, 0, "The mail gateway exited normally. yay");
251
252 $u = RT::User->new($RT::SystemUser);
253 $u->Load("doesnotexist-3\@$RT::rtname");
254 ok( $u->Id == 0, " user does not exist and was not created by ticket comment submission");
255
256 # }}}
257 # {{{  can another random reply to a ticket after being granted privs? answer should be yes
258
259
260 ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CommentOnTicket');
261 ok ($val, "Granted everybody the right to reply to  tickets - $msg");
262
263 $! = '';
264 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $!");
265 print MAIL <<EOF;
266 From: doesnotexist-3\@$RT::rtname
267 To: rt\@$RT::rtname
268 Subject: [$RT::rtname #@{[$tick->Id]}] This is a test of a comment as an unknown user
269
270 Blah!
271 Foob!
272 EOF
273 close (MAIL);
274
275 #Check the return value
276 is ($? >> 8, 0, "The mail gateway exited normally. yay");
277
278 $u = RT::User->new($RT::SystemUser);
279 $u->Load("doesnotexist-3\@$RT::rtname");
280 ok( $u->Id != 0, " user exists and was created by ticket comment submission");
281
282 # }}}
283
284 # {{{ Testing preservation of binary attachments
285
286 # Get a binary blob (Best Practical logo) 
287
288 # Create a mime entity with an attachment
289
290 use MIME::Entity;
291 my $entity = MIME::Entity->build( From => 'root@localhost',
292                                  To => 'rt@localhost',
293                                 Subject => 'binary attachment test',
294                                 Data => ['This is a test of a binary attachment']);
295
296 # currently in lib/t/autogen
297
298 my $LOGO_FILE = $RT::MasonComponentRoot.'/NoAuth/images/bplogo.gif';
299
300 $entity->attach(Path => $LOGO_FILE,
301                 Type => 'image/gif',
302                 Encoding => 'base64');
303
304 # Create a ticket with a binary attachment
305 $! = '';
306 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
307
308 $entity->print(\*MAIL);
309
310 close (MAIL);
311
312 #Check the return value
313 is ($? >> 8, 0, "The mail gateway exited normally. yay");
314
315 $tickets = RT::Tickets->new($RT::SystemUser);
316 $tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
317 $tickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
318  $tick = $tickets->First();
319 ok (UNIVERSAL::isa($tick,'RT::Ticket'));
320 ok ($tick->Id, "found ticket ".$tick->Id);
321 ok ($tick->Subject eq 'binary attachment test', "Created the ticket - ".$tick->Id);
322
323 my $file = `cat $LOGO_FILE`;
324 ok ($file, "Read in the logo image");
325
326
327         use Digest::MD5;
328 warn "for the raw file the content is ".Digest::MD5::md5_base64($file);
329
330
331
332 # Verify that the binary attachment is valid in the database
333 my $attachments = RT::Attachments->new($RT::SystemUser);
334 $attachments->Limit(FIELD => 'ContentType', VALUE => 'image/gif');
335 ok ($attachments->Count == 1, 'Found only one gif in the database');
336 my $attachment = $attachments->First;
337 ok($attachment->Id);
338 my $acontent = $attachment->Content;
339
340         warn "coming from the  database, the content is ".Digest::MD5::md5_base64($acontent);
341
342 is( $acontent, $file, 'The attachment isn\'t screwed up in the database.');
343 # Log in as root
344 use Getopt::Long;
345 use LWP::UserAgent;
346
347
348 # Grab the binary attachment via the web ui
349 my $ua      = LWP::UserAgent->new();
350
351 my $full_url = "$url/Ticket/Attachment/".$attachment->TransactionId."/".$attachment->id."/bplogo.gif?&user=root&pass=password";
352 my $r = $ua->get( $full_url);
353
354
355 # Verify that the downloaded attachment is the same as what we uploaded.
356 is($file, $r->content, 'The attachment isn\'t screwed up in download');
357
358
359
360 # }}}
361
362 # {{{ Simple I18N testing
363
364 $! = '';
365 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
366                                                                          
367 print MAIL <<EOF;
368 From: root\@localhost
369 To: rtemail\@$RT::rtname
370 Subject: This is a test of I18N ticket creation
371 Content-Type: text/plain; charset="utf-8"
372
373 2 accented lines
374 \303\242\303\252\303\256\303\264\303\273
375 \303\241\303\251\303\255\303\263\303\272
376 bye
377 EOF
378 close (MAIL);
379
380 #Check the return value
381 is ($? >> 8, 0, "The mail gateway exited normally. yay");
382
383 my $unitickets = RT::Tickets->new($RT::SystemUser);
384 $unitickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
385 $unitickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
386 my $unitick = $unitickets->First();
387 ok (UNIVERSAL::isa($unitick,'RT::Ticket'));
388 ok ($unitick->Id, "found ticket ".$unitick->Id);
389 ok ($unitick->Subject eq 'This is a test of I18N ticket creation', "Created the ticket - ". $unitick->Subject);
390
391
392
393 my $unistring = "\303\241\303\251\303\255\303\263\303\272";
394 Encode::_utf8_on($unistring);
395 is ($unitick->Transactions->First->Content, $unitick->Transactions->First->Attachments->First->Content, "Content is ". $unitick->Transactions->First->Attachments->First->Content);
396 ok($unitick->Transactions->First->Attachments->First->Content =~ /$unistring/i, $unitick->Id." appears to be unicode ". $unitick->Transactions->First->Attachments->First->Id);
397 # supposedly I18N fails on the second message sent in.
398
399 $! = '';
400 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $!");
401                                                                          
402 print MAIL <<EOF;
403 From: root\@localhost
404 To: rtemail\@$RT::rtname
405 Subject: This is a test of I18N ticket creation
406 Content-Type: text/plain; charset="utf-8"
407
408 2 accented lines
409 \303\242\303\252\303\256\303\264\303\273
410 \303\241\303\251\303\255\303\263\303\272
411 bye
412 EOF
413 close (MAIL);
414
415 #Check the return value
416 is ($? >> 8, 0, "The mail gateway exited normally. yay");
417
418 my $tickets2 = RT::Tickets->new($RT::SystemUser);
419 $tickets2->OrderBy(FIELD => 'id', ORDER => 'DESC');
420 $tickets2->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
421 my $tick2 = $tickets2->First();
422 ok (UNIVERSAL::isa($tick2,'RT::Ticket'));
423 ok ($tick2->Id, "found ticket ".$tick2->Id);
424 ok ($tick2->Subject eq 'This is a test of I18N ticket creation', "Created the ticket");
425
426
427
428 $unistring = "\303\241\303\251\303\255\303\263\303\272";
429 Encode::_utf8_on($unistring);
430
431 ok ($tick2->Transactions->First->Content =~ $unistring, "It appears to be unicode - ".$tick2->Transactions->First->Content);
432
433 # }}}
434
435
436 ($val,$msg) = $g->PrincipalObj->RevokeRight(Right => 'CreateTicket');
437 ok ($val, $msg);
438
439 ##=for later
440
441 SKIP: {
442 skip "Advanced mailgate actions require an unsafe configuration", 47 unless $RT::UnsafeEmailCommands;
443
444 #create new queue to be shure we don't mess with rights
445 use RT::Queue;
446 my $queue = RT::Queue->new($RT::SystemUser);
447 my ($qid) = $queue->Create( Name => 'ext-mailgate');
448 ok( $qid, 'queue created for ext-mailgate tests' );
449
450 # {{{ Check take and resolve actions
451
452 # create ticket that is owned by nobody
453 use RT::Ticket;
454 $tick = RT::Ticket->new($RT::SystemUser);
455 my ($id) = $tick->Create( Queue => 'ext-mailgate', Subject => 'test');
456 ok( $id, 'new ticket created' );
457 is( $tick->Owner, $RT::Nobody->Id, 'owner of the new ticket is nobody' );
458
459 $! = '';
460 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take"), "Opened the mailgate - $!");
461 print MAIL <<EOF;
462 From: root\@localhost
463 Subject: [$RT::rtname \#$id] test
464
465 EOF
466 close (MAIL);
467 is ($? >> 8, 0, "The mail gateway exited normally");
468
469 $tick = RT::Ticket->new($RT::SystemUser);
470 $tick->Load( $id );
471 is( $tick->Id, $id, 'load correct ticket');
472 is( $tick->OwnerObj->EmailAddress, 'root@localhost', 'successfuly take ticket via email');
473
474 # check that there is no text transactions writen
475 is( $tick->Transactions->Count, 2, 'no superfluous transactions');
476
477 my $status;
478 ($status, $msg) = $tick->SetOwner( $RT::Nobody->Id, 'Force' );
479 ok( $status, 'successfuly changed owner: '. ($msg||'') );
480 is( $tick->Owner, $RT::Nobody->Id, 'set owner back to nobody');
481
482
483
484 $! = '';
485 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $RT::WebURL --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $@");
486 print MAIL <<EOF;
487 From: root\@localhost
488 Subject: [$RT::rtname \#$id] correspondence
489
490 test
491 EOF
492 close (MAIL);
493 is ($? >> 8, 0, "The mail gateway exited normally");
494
495 DBIx::SearchBuilder::Record::Cachable->FlushCache;
496
497 $tick = RT::Ticket->new($RT::SystemUser);
498 $tick->Load( $id );
499 is( $tick->Id, $id, "load correct ticket #$id");
500 is( $tick->OwnerObj->EmailAddress, 'root@localhost', 'successfuly take ticket via email');
501 my $txns = $tick->Transactions;
502 $txns->Limit( FIELD => 'Type', VALUE => 'Correspond');
503 $txns->OrderBy( FIELD => 'id', ORDER => 'DESC' );
504 # +1 because of auto open
505 is( $tick->Transactions->Count, 6, 'no superfluous transactions');
506 is( $txns->First->Subject, "[$RT::rtname \#$id] correspondence", 'successfuly add correspond within take via email' );
507
508 $! = '';
509 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action resolve --debug"), "Opened the mailgate - $!");
510 print MAIL <<EOF;
511 From: root\@localhost
512 Subject: [$RT::rtname \#$id] test
513
514 EOF
515 close (MAIL);
516 is ($? >> 8, 0, "The mail gateway exited normally");
517
518 DBIx::SearchBuilder::Record::Cachable->FlushCache;
519
520 $tick = RT::Ticket->new($RT::SystemUser);
521 $tick->Load( $id );
522 is( $tick->Id, $id, 'load correct ticket');
523 is( $tick->Status, 'resolved', 'successfuly resolved ticket via email');
524 is( $tick->Transactions->Count, 7, 'no superfluous transactions');
525
526 use RT::User;
527 my $user = RT::User->new( $RT::SystemUser );
528 my ($uid) = $user->Create( Name => 'ext-mailgate',
529                            EmailAddress => 'ext-mailgate@localhost',
530                            Privileged => 1,
531                            Password => 'qwe123',
532                          );
533 ok( $uid, 'user created for ext-mailgate tests' );
534 ok( !$user->HasRight( Right => 'OwnTicket', Object => $queue ), "User can't own ticket" );
535
536 $tick = RT::Ticket->new($RT::SystemUser);
537 ($id) = $tick->Create( Queue => $qid, Subject => 'test' );
538 ok( $id, 'create new ticket' );
539
540 $! = '';
541 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take"), "Opened the mailgate - $!");
542 print MAIL <<EOF;
543 From: ext-mailgate\@localhost
544 Subject: [example.com \#$id] test
545
546 EOF
547 close (MAIL);
548 is ( $? >> 8, 0, "mailgate exited normally" );
549 DBIx::SearchBuilder::Record::Cachable->FlushCache;
550
551 cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" );
552
553 ($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'ReplyToTicket' );
554 ok( $status, "successfuly granted right: $msg" );
555 my $ace_id = $status;
556 ok( $user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "User can reply to ticket" );
557
558 $! = '';
559 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action correspond-take"), "Opened the mailgate - $!");
560 print MAIL <<EOF;
561 From: ext-mailgate\@localhost
562 Subject: [example.com \#$id] test
563
564 correspond-take
565 EOF
566 close (MAIL);
567 is ( $? >> 8, 0, "mailgate exited normally" );
568 DBIx::SearchBuilder::Record::Cachable->FlushCache;
569
570 cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" );
571 is( $tick->Transactions->Count, 3, "one transactions added" );
572
573 $! = '';
574 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $!");
575 print MAIL <<EOF;
576 From: ext-mailgate\@localhost
577 Subject: [example.com \#$id] test
578
579 correspond-take
580 EOF
581 close (MAIL);
582 is ( $? >> 8, 0, "mailgate exited normally" );
583 DBIx::SearchBuilder::Record::Cachable->FlushCache;
584
585 cmp_ok( $tick->Owner, '!=', $user->id, "we didn't change owner" );
586 is( $tick->Transactions->Count, 3, "no transactions added, user can't take ticket first" );
587
588 # revoke ReplyToTicket right
589 use RT::ACE;
590 my $ace = RT::ACE->new($RT::SystemUser);
591 $ace->Load( $ace_id );
592 $ace->Delete;
593 my $acl = RT::ACL->new($RT::SystemUser);
594 $acl->Limit( FIELD => 'RightName', VALUE => 'ReplyToTicket' );
595 $acl->LimitToObject( $RT::System );
596 while( my $ace = $acl->Next ) {
597         $ace->Delete;
598 }
599
600 ok( !$user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "User can't reply to ticket any more" );
601
602
603 my $group = RT::Group->new( $RT::SystemUser );
604 ok( $group->LoadQueueRoleGroup( Queue => $qid, Type=> 'Owner' ), "load queue owners role group" );
605 $ace = RT::ACE->new( $RT::SystemUser );
606 ($ace_id, $msg) = $group->PrincipalObj->GrantRight( Right => 'ReplyToTicket', Object => $queue );
607 ok( $ace_id, "Granted queue owners role group with ReplyToTicket right" );
608
609 ($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'OwnTicket' );
610 ok( $status, "successfuly granted right: $msg" );
611 ($status, $msg) = $user->PrincipalObj->GrantRight( Object => $queue, Right => 'TakeTicket' );
612 ok( $status, "successfuly granted right: $msg" );
613
614 $! = '';
615 ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue ext-mailgate --action take-correspond"), "Opened the mailgate - $!");
616 print MAIL <<EOF;
617 From: ext-mailgate\@localhost
618 Subject: [example.com \#$id] test
619
620 take-correspond with reply right granted to owner role
621 EOF
622 close (MAIL);
623 is ( $? >> 8, 0, "mailgate exited normally" );
624 DBIx::SearchBuilder::Record::Cachable->FlushCache;
625
626 $tick->Load( $id );
627 is( $tick->Owner, $user->id, "we changed owner" );
628 ok( $user->HasRight( Right => 'ReplyToTicket', Object => $tick ), "owner can reply to ticket" );
629 is( $tick->Transactions->Count, 5, "transactions added" );
630
631
632 # }}}
633 };
634
635
636 1;
637