[Rt-commit] r5926 - in rt/branches/3.7-EXPERIMENTAL: .
ruz at bestpractical.com
ruz at bestpractical.com
Wed Sep 13 18:01:07 EDT 2006
Author: ruz
Date: Wed Sep 13 18:01:06 2006
New Revision: 5926
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/lib/t/regression/06mailgateway.t
Log:
r3730 at cubic-pc: cubic | 2006-09-14 02:10:53 +0400
mailgate tests
* helper functions: create_ticket_via_mailgate, via_gate, latest_created
* fetch ticket ID from gate output
* make code more re-entrant, but still there is problems with users
* split code into isolated blocks
Modified: rt/branches/3.7-EXPERIMENTAL/lib/t/regression/06mailgateway.t
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/lib/t/regression/06mailgateway.t (original)
+++ rt/branches/3.7-EXPERIMENTAL/lib/t/regression/06mailgateway.t Wed Sep 13 18:01:06 2006
@@ -52,34 +52,111 @@
=cut
use strict;
-use Test::More tests => 57;
+use warnings;
+
+use Test::More tests => 64;
+
use RT;
RT::LoadConfig();
RT::Init();
-use RT::I18N;
-no warnings 'once';
-my $url = RT->Config->Get('WebURL');
+use RT::Tickets;
-# Make sure that when we call the mailgate wrong, it tempfails
+use IPC::Open2;
+use MIME::Entity;
+use Digest::MD5;
+use LWP::UserAgent;
-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 - $@");
-print MAIL <<EOF;
+
+my $url = RT->Config->Get('WebURL');
+
+our $mailgate = $RT::BinPath .'/rt-mailgate';
+die "Couldn't find mailgate ($mailgate) command" unless -f $mailgate;
+$mailgate .= ' --debug';
+
+sub run_gate {
+ my %args = (
+ url => $url,
+ message => '',
+ action => 'correspond',
+ queue => 'General',
+ @_
+ );
+ my $message = delete $args{'message'};
+
+ my $cmd = $mailgate;
+ while( my ($k,$v) = each %args ) {
+ next unless $v;
+ $cmd .= " --$k '$v'";
+ }
+ $cmd .= ' 2>&1';
+
+ DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+ my ($child_out, $child_in);
+ my $pid = open2($child_out, $child_in, $cmd);
+ if ( UNIVERSAL::isa($message, 'MIME::Entity') ) {
+ $message->print( $child_in );
+ } else {
+ print $child_in $message;
+ }
+ close $child_in;
+ my $result = do { local $/; <$child_out> };
+ close $child_out;
+ waitpid $pid, 0;
+ return ($?, $result);
+}
+
+sub create_ticket_via_gate {
+ my $message = shift;
+ my ($status, $gate_result) = run_gate( message => $message, @_ );
+ my $id;
+ unless ( $status >> 8 ) {
+ ($id) = ($gate_result =~ /Ticket:\s*(\d+)/i);
+ unless ( $id ) {
+ diag "Couldn't find ticket id in text:\n$gate_result" if $ENV{'TEST_VERBOSE'};
+ }
+ }
+ return ($status, $id);
+}
+
+sub latest_ticket {
+ my $tickets = RT::Tickets->new( $RT::SystemUser );
+ $tickets->OrderBy( FIELD => 'id', ORDER => 'DESC' );
+ $tickets->Limit( FIELD => 'id', OPERATOR => '>', VALUE => '0' );
+ $tickets->RowsPerPage( 1 );
+ return $tickets->First;
+}
+
+diag "Make sure that when we call the mailgate wrong, it tempfails" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: root\@localhost
To: rt\@@{[RT->Config->Get('rtname')]}
Subject: This is a test of new ticket creation
Foob!
EOF
-close (MAIL);
-
-# Check the return value
-is ( $? >> 8, 75, "The error message above is expected The mail gateway exited with a failure. yay");
-
-
-# {{{ Test new ticket creation by root who is privileged and superuser
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --debug --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text, url => 'http://this.test.for.non-connection.is.expected.to.generate.an.error');
+ is ($status >> 8, 75, "The mail gateway exited with a failure");
+ ok (!$id, "No ticket id");
+}
+
+
+my $everyone_group;
+diag "revoke rights tests depend on";
+{
+ $everyone_group = RT::Group->new( $RT::SystemUser );
+ $everyone_group->LoadSystemInternalGroup( 'Everyone' );
+ ok ($everyone_group->Id, "Found group 'everyone'");
+
+ foreach( qw(CreateTicket ReplyToTicket CommentOnTicket) ) {
+ $everyone_group->PrincipalObj->RevokeRight(Right => $_);
+ }
+}
+
+diag "Test new ticket creation by root who is privileged and superuser" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: root\@localhost
To: rt\@@{[RT->Config->Get('rtname')]}
Subject: This is a test of new ticket creation
@@ -87,27 +164,21 @@
Blah!
Foob!
EOF
-close (MAIL);
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-use RT::Tickets;
-my $tickets = RT::Tickets->new($RT::SystemUser);
-$tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
-$tickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
-my $tick = $tickets->First();
-ok (UNIVERSAL::isa($tick,'RT::Ticket'));
-ok ($tick->Id, "found ticket ".$tick->Id);
-ok ($tick->Subject eq 'This is a test of new ticket creation', "Created the ticket");
-
-# }}}
-
-
-# {{{This is a test of new ticket creation as an unknown user
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok ($id, "Created ticket");
+
+ my $tick = latest_ticket();
+ isa_ok ($tick, 'RT::Ticket');
+ ok ($tick->Id, "found ticket");
+ is ($tick->Id, $id, "correct ticket id");
+ ok ($tick->Subject eq 'This is a test of new ticket creation', "Created the ticket");
+}
+
+diag "This is a test of new ticket creation as an unknown user" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: doesnotexist\@@{[RT->Config->Get('rtname')]}
To: rt\@@{[RT->Config->Get('rtname')]}
Subject: This is a test of new ticket creation as an unknown user
@@ -115,35 +186,30 @@
Blah!
Foob!
EOF
-close (MAIL);
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-$tickets = RT::Tickets->new($RT::SystemUser);
-$tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
-$tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0');
-$tick = $tickets->First();
-ok ($tick->Id, "found ticket ".$tick->Id);
-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");
-my $u = RT::User->new($RT::SystemUser);
-$u->Load("doesnotexist\@@{[RT->Config->Get('rtname')]}");
-ok( $u->Id == 0, " user does not exist and was not created by failed ticket submission");
-
-
-# }}}
-
-# {{{ now everybody can create tickets. can a random unkown user create tickets?
-
-my $g = RT::Group->new($RT::SystemUser);
-$g->LoadSystemInternalGroup('Everyone');
-ok( $g->Id, "Found 'everybody'");
-
-my ($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
-ok ($val, "Granted everybody the right to create tickets - $msg");
-
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok (!$id, "no ticket created");
+
+ my $tick = latest_ticket();
+ isa_ok ($tick, 'RT::Ticket');
+ ok ($tick->Id, "found ticket ".$tick->Id);
+ 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");
+
+ my $u = RT::User->new($RT::SystemUser);
+ $u->Load("doesnotexist\@@{[RT->Config->Get('rtname')]}");
+ ok( !$u->Id, "user does not exist and was not created by failed ticket submission");
+}
+
+diag "grant everybody with CreateTicket right";
+{
+ my ($val, $msg) = $everyone_group->PrincipalObj->GrantRight( Right => 'CreateTicket' );
+ ok ($val, "Granted everybody the right to create tickets") or diag "error: $msg";
+}
+
+my $ticket_id;
+diag "now everybody can create tickets. can a random unkown user create tickets?" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: doesnotexist\@@{[RT->Config->Get('rtname')]}
To: rt\@@{[RT->Config->Get('rtname')]}
Subject: This is a test of new ticket creation as an unknown user
@@ -151,208 +217,177 @@
Blah!
Foob!
EOF
-close (MAIL);
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-
-$tickets = RT::Tickets->new($RT::SystemUser);
-$tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
-$tickets->Limit(FIELD => 'id' ,OPERATOR => '>', VALUE => '0');
-$tick = $tickets->First();
-ok ($tick->Id, "found ticket ".$tick->Id);
-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");
- $u = RT::User->new($RT::SystemUser);
-$u->Load("doesnotexist\@@{[RT->Config->Get('rtname')]}");
-ok( $u->Id != 0, " user does not exist and was created by ticket submission");
-
-# }}}
-
-
-# {{{ can another random reply to a ticket without being granted privs? answer should be no.
-
-
-#($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
-#ok ($val, "Granted everybody the right to create tickets - $msg");
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok ($id, "ticket created");
+
+ my $tick = latest_ticket();
+ isa_ok ($tick, 'RT::Ticket');
+ ok ($tick->Id, "found ticket ".$tick->Id);
+ is ($tick->Id, $id, "correct ticket id");
+ 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");
+
+ my $u = RT::User->new( $RT::SystemUser );
+ $u->Load( "doesnotexist\@@{[RT->Config->Get('rtname')]}" );
+ ok ($u->Id, "user does not exist and was created by ticket submission");
+ $ticket_id = $id;
+}
+
+diag "can another random reply to a ticket without being granted privs? answer should be no." if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: doesnotexist-2\@@{[RT->Config->Get('rtname')]}
To: rt\@@{[RT->Config->Get('rtname')]}
-Subject: [@{[RT->Config->Get('rtname')]} #@{[$tick->Id]}] This is a test of a reply as an unknown user
+Subject: [@{[RT->Config->Get('rtname')]} #$ticket_id] This is a test of a reply as an unknown user
Blah! (Should not work.)
Foob!
EOF
-close (MAIL);
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-$u = RT::User->new($RT::SystemUser);
-$u->Load('doesnotexist-2@'.RT->Config->Get('rtname'));
-ok( $u->Id == 0, " user does not exist and was not created by ticket correspondence submission");
-# }}}
-
-
-# {{{ can another random reply to a ticket after being granted privs? answer should be yes
-
-
-($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'ReplyToTicket');
-ok ($val, "Granted everybody the right to reply to tickets - $msg");
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok (!$id, "no way to reply to the ticket");
+
+ my $u = RT::User->new($RT::SystemUser);
+ $u->Load('doesnotexist-2@'.RT->Config->Get('rtname'));
+ ok( !$u->Id, " user does not exist and was not created by ticket correspondence submission");
+}
+
+diag "grant everyone 'ReplyToTicket' right" if $ENV{'TEST_VERBOSE'};
+{
+ my ($val,$msg) = $everyone_group->PrincipalObj->GrantRight(Right => 'ReplyToTicket');
+ ok ($val, "Granted everybody the right to reply to tickets - $msg");
+}
+
+diag "can another random reply to a ticket after being granted privs? answer should be yes" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: doesnotexist-2\@@{[RT->Config->Get('rtname')]}
To: rt\@@{[RT->Config->Get('rtname')]}
-Subject: [@{[RT->Config->Get('rtname')]} #@{[$tick->Id]}] This is a test of a reply as an unknown user
+Subject: [@{[RT->Config->Get('rtname')]} #$ticket_id] This is a test of a reply as an unknown user
Blah!
Foob!
EOF
-close (MAIL);
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ is ($id, $ticket_id, "replied to the ticket");
+
+ my $u = RT::User->new($RT::SystemUser);
+ $u->Load('doesnotexist-2@'.RT->Config->Get('rtname'));
+ ok ($u->Id, "user exists and was created by ticket correspondence submission");
+}
-$u = RT::User->new($RT::SystemUser);
-$u->Load('doesnotexist-2@'.RT->Config->Get('rtname'));
-ok( $u->Id != 0, " user exists and was created by ticket correspondence submission");
-
-# }}}
-
-# {{{ can another random comment on a ticket without being granted privs? answer should be no.
-
-
-#($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CreateTicket');
-#ok ($val, "Granted everybody the right to create tickets - $msg");
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+diag "can another random comment on a ticket without being granted privs? answer should be no" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: doesnotexist-3\@@{[RT->Config->Get('rtname')]}
To: rt\@@{[RT->Config->Get('rtname')]}
-Subject: [@{[RT->Config->Get('rtname')]} #@{[$tick->Id]}] This is a test of a comment as an unknown user
+Subject: [@{[RT->Config->Get('rtname')]} #$ticket_id] This is a test of a comment as an unknown user
Blah! (Should not work.)
Foob!
EOF
-close (MAIL);
-
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-$u = RT::User->new($RT::SystemUser);
-$u->Load('doesnotexist-3@'.RT->Config->Get('rtname'));
-ok( $u->Id == 0, " user does not exist and was not created by ticket comment submission");
-
-# }}}
-# {{{ can another random reply to a ticket after being granted privs? answer should be yes
-
-
-($val,$msg) = $g->PrincipalObj->GrantRight(Right => 'CommentOnTicket');
-ok ($val, "Granted everybody the right to reply to tickets - $msg");
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action comment"), "Opened the mailgate - $@");
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text, action => 'comment');
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok (!$id, "no way to comment on the ticket");
+
+ my $u = RT::User->new($RT::SystemUser);
+ $u->Load('doesnotexist-3@'.RT->Config->Get('rtname'));
+ ok( !$u->Id, " user does not exist and was not created by ticket comment submission");
+}
+
+
+diag "grant everyone 'ReplyToTicket' right" if $ENV{'TEST_VERBOSE'};
+{
+ my ($val,$msg) = $everyone_group->PrincipalObj->GrantRight(Right => 'CommentOnTicket');
+ ok ($val, "Granted everybody the right to reply to tickets - $msg");
+}
+
+diag "can another random reply to a ticket after being granted privs? answer should be yes" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: doesnotexist-3\@@{[RT->Config->Get('rtname')]}
To: rt\@@{[RT->Config->Get('rtname')]}
-Subject: [@{[RT->Config->Get('rtname')]} #@{[$tick->Id]}] This is a test of a comment as an unknown user
+Subject: [@{[RT->Config->Get('rtname')]} #$ticket_id] This is a test of a comment as an unknown user
Blah!
Foob!
EOF
-close (MAIL);
-
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-$u = RT::User->new($RT::SystemUser);
-$u->Load('doesnotexist-3@'.RT->Config->Get('rtname'));
-ok( $u->Id != 0, " user exists and was created by ticket comment submission");
-
-# }}}
-
-# {{{ Testing preservation of binary attachments
-
-# Get a binary blob (Best Practical logo)
-
-# Create a mime entity with an attachment
-
-use MIME::Entity;
-my $entity = MIME::Entity->build( From => 'root at localhost',
- To => 'rt at localhost',
- Subject => 'binary attachment test',
- Data => ['This is a test of a binary attachment']);
-
-# currently in lib/t/autogen
-
-my $LOGO_FILE = $RT::MasonComponentRoot.'/NoAuth/images/bplogo.gif';
-
-$entity->attach(Path => $LOGO_FILE,
- Type => 'image/gif',
- Encoding => 'base64');
-
-# Create a ticket with a binary attachment
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-
-$entity->print(\*MAIL);
-
-close (MAIL);
-
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-$tickets = RT::Tickets->new($RT::SystemUser);
-$tickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
-$tickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
- $tick = $tickets->First();
-ok (UNIVERSAL::isa($tick,'RT::Ticket'));
-ok ($tick->Id, "found ticket ".$tick->Id);
-ok ($tick->Subject eq 'binary attachment test', "Created the ticket - ".$tick->Id);
-
-my $file = `cat $LOGO_FILE`;
-ok ($file, "Read in the logo image");
-
-
- use Digest::MD5;
-warn "for the raw file the content is ".Digest::MD5::md5_base64($file);
-
-
-
-# Verify that the binary attachment is valid in the database
-my $attachments = RT::Attachments->new($RT::SystemUser);
-$attachments->Limit(FIELD => 'ContentType', VALUE => 'image/gif');
-ok ($attachments->Count == 1, 'Found only one gif in the database');
-my $attachment = $attachments->First;
-ok($attachment->Id);
-my $acontent = $attachment->Content;
-
- warn "coming from the database, the content is ".Digest::MD5::md5_base64($acontent);
-
-is( $acontent, $file, 'The attachment isn\'t screwed up in the database.');
-# Log in as root
-use Getopt::Long;
-use LWP::UserAgent;
-
-
-# Grab the binary attachment via the web ui
-my $ua = LWP::UserAgent->new();
-
-my $full_url = "$url/Ticket/Attachment/".$attachment->TransactionId."/".$attachment->id."/bplogo.gif?&user=root&pass=password";
-my $r = $ua->get( $full_url);
-
-
-# Verify that the downloaded attachment is the same as what we uploaded.
-is($file, $r->content, 'The attachment isn\'t screwed up in download');
-
-
-
-# }}}
-
-# {{{ Simple I18N testing
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text, action => 'comment');
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ is ($id, $ticket_id, "replied to the ticket");
+
+ my $u = RT::User->new($RT::SystemUser);
+ $u->Load('doesnotexist-3@'.RT->Config->Get('rtname'));
+ ok ($u->Id, " user exists and was created by ticket comment submission");
+}
+
+diag "Testing preservation of binary attachments" if $ENV{'TEST_VERBOSE'};
+{
+ # Get a binary blob (Best Practical logo)
+ my $LOGO_FILE = $RT::MasonComponentRoot .'/NoAuth/images/bplogo.gif';
+
+ # Create a mime entity with an attachment
+ my $entity = MIME::Entity->build(
+ From => 'root at localhost',
+ To => 'rt at localhost',
+ Subject => 'binary attachment test',
+ Data => ['This is a test of a binary attachment'],
+ );
+
+ $entity->attach(
+ Path => $LOGO_FILE,
+ Type => 'image/gif',
+ Encoding => 'base64',
+ );
+ # Create a ticket with a binary attachment
+ my ($status, $id) = create_ticket_via_gate($entity);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok ($id, "created ticket");
+
+ my $tick = latest_ticket();
+ isa_ok ($tick, 'RT::Ticket');
+ ok ($tick->Id, "found ticket ".$tick->Id);
+ is ($tick->Id, $id, "correct ticket id");
+ ok ($tick->Subject eq 'binary attachment test', "Created the ticket - ".$tick->Id);
+
+ my $file = `cat $LOGO_FILE`;
+ ok ($file, "Read in the logo image");
+ diag "for the raw file the md5 hex is ". Digest::MD5::md5_hex($file) if $ENV{'TEST_VERBOSE'};
+
+ # Verify that the binary attachment is valid in the database
+ my $attachments = RT::Attachments->new($RT::SystemUser);
+ $attachments->Limit(FIELD => 'ContentType', VALUE => 'image/gif');
+ my $txn_alias = $attachments->Join(
+ ALIAS1 => 'main',
+ FIELD1 => 'TransactionId',
+ TABLE2 => 'Transactions',
+ FIELD2 => 'id',
+ );
+ $attachments->Limit( ALIAS => $txn_alias, FIELD => 'ObjectType', VALUE => 'RT::Ticket' );
+ $attachments->Limit( ALIAS => $txn_alias, FIELD => 'ObjectId', VALUE => $id );
+ is ($attachments->Count, 1, 'Found only one gif attached to the ticket');
+ my $attachment = $attachments->First;
+ ok ($attachment->Id, 'loaded attachment object');
+ my $acontent = $attachment->Content;
+
+ diag "coming from the database, md5 hex is ".Digest::MD5::md5_hex($acontent) if $ENV{'TEST_VERBOSE'};
+ is ($acontent, $file, 'The attachment isn\'t screwed up in the database.');
+
+ # Grab the binary attachment via the web ui
+ my $ua = new LWP::UserAgent;
+ my $full_url = "$url/Ticket/Attachment/". $attachment->TransactionId
+ ."/". $attachment->id. "/bplogo.gif?&user=root&pass=password";
+ my $r = $ua->get( $full_url );
+
+ # Verify that the downloaded attachment is the same as what we uploaded.
+ is ($file, $r->content, 'The attachment isn\'t screwed up in download');
+}
+
+diag "Simple I18N testing" if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: root\@localhost
To: rtemail\@@{[RT->Config->Get('rtname')]}
Subject: This is a test of I18N ticket creation
@@ -363,30 +398,32 @@
\303\241\303\251\303\255\303\263\303\272
bye
EOF
-close (MAIL);
-
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-my $unitickets = RT::Tickets->new($RT::SystemUser);
-$unitickets->OrderBy(FIELD => 'id', ORDER => 'DESC');
-$unitickets->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
-my $unitick = $unitickets->First();
-ok (UNIVERSAL::isa($unitick,'RT::Ticket'));
-ok ($unitick->Id, "found ticket ".$unitick->Id);
-ok ($unitick->Subject eq 'This is a test of I18N ticket creation', "Created the ticket - ". $unitick->Subject);
-
-
-
-my $unistring = "\303\241\303\251\303\255\303\263\303\272";
-Encode::_utf8_on($unistring);
-is ($unitick->Transactions->First->Content, $unitick->Transactions->First->Attachments->First->Content, "Content is ". $unitick->Transactions->First->Attachments->First->Content);
-ok($unitick->Transactions->First->Attachments->First->Content =~ /$unistring/i, $unitick->Id." appears to be unicode ". $unitick->Transactions->First->Attachments->First->Id);
-# supposedly I18N fails on the second message sent in.
-
-ok(open(MAIL, "|$RT::BinPath/rt-mailgate --url $url --queue general --action correspond"), "Opened the mailgate - $@");
-
-print MAIL <<EOF;
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok ($id, "created ticket");
+
+ my $tick = latest_ticket();
+ isa_ok ($tick, 'RT::Ticket');
+ ok ($tick->Id, "found ticket ". $tick->Id);
+ is ($tick->Id, $id, "correct ticket");
+ ok ($tick->Subject eq 'This is a test of I18N ticket creation', "Created the ticket - ". $tick->Subject);
+
+ my $unistring = "\303\241\303\251\303\255\303\263\303\272";
+ Encode::_utf8_on($unistring);
+ is (
+ $tick->Transactions->First->Content,
+ $tick->Transactions->First->Attachments->First->Content,
+ "Content is ". $tick->Transactions->First->Attachments->First->Content
+ );
+ ok (
+ $tick->Transactions->First->Content =~ /$unistring/i,
+ $tick->Id." appears to be unicode ". $tick->Transactions->First->Attachments->First->Id
+ );
+}
+
+diag "supposedly I18N fails on the second message sent in." if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<EOF;
From: root\@localhost
To: rtemail\@@{[RT->Config->Get('rtname')]}
Subject: This is a test of I18N ticket creation
@@ -397,30 +434,27 @@
\303\241\303\251\303\255\303\263\303\272
bye
EOF
-close (MAIL);
-
-#Check the return value
-is ($? >> 8, 0, "The mail gateway exited normally. yay");
-
-my $tickets2 = RT::Tickets->new($RT::SystemUser);
-$tickets2->OrderBy(FIELD => 'id', ORDER => 'DESC');
-$tickets2->Limit(FIELD => 'id', OPERATOR => '>', VALUE => '0');
-my $tick2 = $tickets2->First();
-ok (UNIVERSAL::isa($tick2,'RT::Ticket'));
-ok ($tick2->Id, "found ticket ".$tick2->Id);
-ok ($tick2->Subject eq 'This is a test of I18N ticket creation', "Created the ticket");
-
-
-
-$unistring = "\303\241\303\251\303\255\303\263\303\272";
-Encode::_utf8_on($unistring);
-
-ok ($tick2->Transactions->First->Content =~ $unistring, "It appears to be unicode - ".$tick2->Transactions->First->Content);
-
-# }}}
+ my ($status, $id) = create_ticket_via_gate($text);
+ is ($status >> 8, 0, "The mail gateway exited normally");
+ ok ($id, "created ticket");
+
+ my $tick = latest_ticket();
+ isa_ok ($tick, 'RT::Ticket');
+ ok ($tick->Id, "found ticket ". $tick->Id);
+ is ($tick->Id, $id, "correct ticket");
+ ok ($tick->Subject eq 'This is a test of I18N ticket creation', "Created the ticket");
+
+ my $unistring = "\303\241\303\251\303\255\303\263\303\272";
+ Encode::_utf8_on($unistring);
+
+ ok (
+ $tick->Transactions->First->Content =~ $unistring,
+ "It appears to be unicode - ". $tick->Transactions->First->Content
+ );
+}
-($val,$msg) = $g->PrincipalObj->RevokeRight(Right => 'CreateTicket');
+my ($val,$msg) = $everyone_group->PrincipalObj->RevokeRight(Right => 'CreateTicket');
ok ($val, $msg);
=for later
More information about the Rt-commit
mailing list