diff options
author | Ivan Kohler <ivan@freeside.biz> | 2012-06-07 00:56:06 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2012-06-07 00:56:06 -0700 |
commit | 43a06151e47d2c59b833cbd8c26d97865ee850b6 (patch) | |
tree | 42c51d94e7fa265461b508d061562be204ccc2c1 /rt/t/web | |
parent | 6587f6ba7d047ddc1686c080090afe7d53365bd4 (diff) |
starting to work...
Diffstat (limited to 'rt/t/web')
-rw-r--r-- | rt/t/web/dashboard_with_deleted_saved_search.t | 89 | ||||
-rw-r--r-- | rt/t/web/dashboards.t | 250 | ||||
-rw-r--r-- | rt/t/web/gnupg-outgoing.t | 363 |
3 files changed, 0 insertions, 702 deletions
diff --git a/rt/t/web/dashboard_with_deleted_saved_search.t b/rt/t/web/dashboard_with_deleted_saved_search.t deleted file mode 100644 index 328095aaf..000000000 --- a/rt/t/web/dashboard_with_deleted_saved_search.t +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env perl -use strict; -use warnings; - -use RT::Test tests => 18; -my ( $url, $m ) = RT::Test->started_ok; -ok( $m->login, 'logged in' ); - -# create a saved search -$m->get_ok( $url . "/Search/Build.html?Query=" . 'id=1' ); - -$m->submit_form( - form_name => 'BuildQuery', - fields => { SavedSearchDescription => 'foo', }, - button => 'SavedSearchSave', -); - -my ( $search_uri, $user_id, $search_id ) = - $m->content =~ /value="(RT::User-(\d+)-SavedSearch-(\d+))"/; -$m->submit_form( - form_name => 'BuildQuery', - fields => { SavedSearchLoad => $search_uri }, - button => 'SavedSearchSave', -); - -$m->content_like( qr/name="SavedSearchDelete"\s+value="Delete"/, - 'found Delete button' ); -$m->content_like( - qr/name="SavedSearchDescription"\s+value="foo"/, - 'found Description input with the value filled' -); - -# create a dashboard with the created search - -$m->get_ok( $url . "/Dashboards/Modify.html?Create=1" ); -$m->submit_form( - form_name => 'ModifyDashboard', - fields => { Name => 'bar' }, -); - -$m->content_like( qr/Saved dashboard bar/i, 'dashboard saved' ); -my $dashboard_queries_link = $m->find_link( text_regex => qr/Queries/ ); -my ( $dashboard_id ) = $dashboard_queries_link->url =~ /id=(\d+)/; - -$m->get_ok( $url . "/Dashboards/Queries.html?id=$dashboard_id" ); - -$m->content_lacks( 'value="Update"', 'no update button' ); - -$m->submit_form( - form_name => 'Dashboard-Searches-body', - fields => - { 'Searches-body-Available' => "search-$search_id-RT::User-$user_id" }, - button => 'add', -); - -$m->content_like( qr/Dashboard updated/i, 'added search foo to dashboard bar' ); - -# delete the created search - -$m->get_ok( $url . "/Search/Build.html?Query=" . 'id=1' ); -$m->submit_form( - form_name => 'BuildQuery', - fields => { SavedSearchLoad => $search_uri }, -); -$m->submit_form( - form_name => 'BuildQuery', - button => 'SavedSearchDelete', -); - -$m->content_lacks( $search_uri, 'deleted search foo' ); - -# here is what we really want to test - -$m->get_ok( $url . "/Dashboards/Queries.html?id=$dashboard_id" ); -$m->content_like( qr/Deleted queries/i, 'found deleted message' ); - -# Update button shows so we can update the deleted search easily -$m->content_contains( 'value="Update"', 'found update button' ); - -$m->submit_form( - form_name => 'Dashboard-Searches-body', - button => 'update', -); - -$m->content_unlike( qr/Deleted queries/i, 'deleted message is gone' ); -$m->content_lacks( 'value="Update"', 'update button is gone too' ); - -$m->get_warnings; # we'll get a lot of warnings because the deleted search - diff --git a/rt/t/web/dashboards.t b/rt/t/web/dashboards.t deleted file mode 100644 index a816eb35c..000000000 --- a/rt/t/web/dashboards.t +++ /dev/null @@ -1,250 +0,0 @@ -#!/usr/bin/perl -w -use strict; - -use RT::Test tests => 109; -my ($baseurl, $m) = RT::Test->started_ok; - -my $url = $m->rt_base_url; - -my $user_obj = RT::User->new($RT::SystemUser); -my ($ret, $msg) = $user_obj->LoadOrCreateByEmail('customer@example.com'); -ok($ret, 'ACL test user creation'); -$user_obj->SetName('customer'); -$user_obj->SetPrivileged(1); -($ret, $msg) = $user_obj->SetPassword('customer'); -$user_obj->PrincipalObj->GrantRight(Right => 'ModifySelf'); -my $currentuser = RT::CurrentUser->new($user_obj); - -my $onlooker = RT::User->new($RT::SystemUser); -($ret, $msg) = $onlooker->LoadOrCreateByEmail('onlooker@example.com'); -ok($ret, 'ACL test user creation'); -$onlooker->SetName('onlooker'); -$onlooker->SetPrivileged(1); -($ret, $msg) = $onlooker->SetPassword('onlooker'); - -my $queue = RT::Queue->new($RT::SystemUser); -$queue->Create(Name => 'SearchQueue'.$$); - -for my $user ($user_obj, $onlooker) { - $user->PrincipalObj->GrantRight(Right => 'ModifySelf'); - for my $right (qw/SeeQueue ShowTicket OwnTicket/) { - $user->PrincipalObj->GrantRight(Right => $right, Object => $queue); - } -} - -ok $m->login(customer => 'customer'), "logged in"; - -$m->get_ok($url."Dashboards/index.html"); -$m->content_lacks('<a href="/Dashboards/Modify.html?Create=1">New</a>', - "No 'new dashboard' link because we have no CreateOwnDashboard"); - -$m->no_warnings_ok; - -$m->get_ok($url."Dashboards/Modify.html?Create=1"); -$m->content_contains("Permission denied"); -$m->content_lacks("Save Changes"); - -$m->warning_like(qr/Permission denied/, "got a permission denied warning"); - -$user_obj->PrincipalObj->GrantRight(Right => 'ModifyOwnDashboard', Object => $RT::System); - -# Modify itself is no longer good enough, you need Create -$m->get_ok($url."Dashboards/Modify.html?Create=1"); -$m->content_contains("Permission denied"); -$m->content_lacks("Save Changes"); - -$m->warning_like(qr/Permission denied/, "got a permission denied warning"); - -$user_obj->PrincipalObj->GrantRight(Right => 'CreateOwnDashboard', Object => $RT::System); - -$m->get_ok($url."Dashboards/Modify.html?Create=1"); -$m->content_lacks("Permission denied"); -$m->content_contains("Create"); - -$m->get_ok($url."Dashboards/index.html"); -$m->content_contains("New", "'New' link because we now have ModifyOwnDashboard"); - -$m->follow_link_ok({text => "New"}); -$m->form_name('ModifyDashboard'); -$m->field("Name" => 'different dashboard'); -$m->content_lacks('Delete', "Delete button hidden because we are creating"); -$m->click_button(value => 'Create'); -$m->content_lacks("No permission to create dashboards"); -$m->content_contains("Saved dashboard different dashboard"); -$m->content_lacks('Delete', "Delete button hidden because we lack DeleteOwnDashboard"); - -$m->get_ok($url."Dashboards/index.html"); -$m->content_lacks("different dashboard", "we lack SeeOwnDashboard"); - -$user_obj->PrincipalObj->GrantRight(Right => 'SeeOwnDashboard', Object => $RT::System); - -$m->get_ok($url."Dashboards/index.html"); -$m->content_contains("different dashboard", "we now have SeeOwnDashboard"); -$m->content_lacks("Permission denied"); - -$m->follow_link_ok({text => "different dashboard"}); -$m->content_contains("Basics"); -$m->content_contains("Queries"); -$m->content_lacks("Subscription", "we don't have the SubscribeDashboard right"); - -$m->follow_link_ok({text => "Basics"}); -$m->content_contains("Modify the dashboard different dashboard"); - -$m->follow_link_ok({text => "Queries"}); -$m->content_contains("Modify the queries of dashboard different dashboard"); -$m->form_name('Dashboard-Searches-body'); -$m->field('Searches-body-Available' => ["search-2-RT::System-1"]); -$m->click_button(name => 'add'); -$m->content_contains("Dashboard updated"); - -my $dashboard = RT::Dashboard->new($currentuser); -my ($id) = $m->content =~ /name="id" value="(\d+)"/; -ok($id, "got an ID, $id"); -$dashboard->LoadById($id); -is($dashboard->Name, "different dashboard"); - -is($dashboard->Privacy, 'RT::User-' . $user_obj->Id, "correct privacy"); -is($dashboard->PossibleHiddenSearches, 0, "all searches are visible"); - -my @searches = $dashboard->Searches; -is(@searches, 1, "one saved search in the dashboard"); -like($searches[0]->Name, qr/newest unowned tickets/, "correct search name"); - -$m->form_name('Dashboard-Searches-body'); -$m->field('Searches-body-Available' => ["search-1-RT::System-1"]); -$m->click_button(name => 'add'); -$m->content_contains("Dashboard updated"); - -RT::Record->FlushCache if RT::Record->can('FlushCache'); -$dashboard = RT::Dashboard->new($currentuser); -$dashboard->LoadById($id); - -@searches = $dashboard->Searches; -is(@searches, 2, "two saved searches in the dashboard"); -like($searches[0]->Name, qr/newest unowned tickets/, "correct existing search name"); -like($searches[1]->Name, qr/highest priority tickets I own/, "correct new search name"); - -my $ticket = RT::Ticket->new($RT::SystemUser); -$ticket->Create( - Queue => $queue->Id, - Requestor => [ $user_obj->Name ], - Owner => $user_obj, - Subject => 'dashboard test', -); - -$m->follow_link_ok({text => 'different dashboard'}); -$m->content_contains("50 highest priority tickets I own"); -$m->content_contains("50 newest unowned tickets"); -$m->content_lacks("Bookmarked Tickets"); -$m->content_contains("dashboard test", "ticket subject"); - -$m->get_ok("/Dashboards/$id/This fragment left intentionally blank"); -$m->content_contains("50 highest priority tickets I own"); -$m->content_contains("50 newest unowned tickets"); -$m->content_lacks("Bookmarked Tickets"); -$m->content_contains("dashboard test", "ticket subject"); - -$m->get_ok("/Dashboards/Subscription.html?DashboardId=$id"); -$m->form_name('SubscribeDashboard'); -$m->click_button(name => 'Save'); -$m->content_contains("Permission denied"); -$m->warning_like(qr/Unable to subscribe to dashboard.*Permission denied/, "got a permission denied warning when trying to subscribe to a dashboard"); - -RT::Record->FlushCache if RT::Record->can('FlushCache'); -is($user_obj->Attributes->Named('Subscription'), 0, "no subscriptions"); - -$user_obj->PrincipalObj->GrantRight(Right => 'SubscribeDashboard', Object => $RT::System); - -$m->get_ok("/Dashboards/Modify.html?id=$id"); -$m->follow_link_ok({text => "Subscription"}); -$m->content_contains("Subscribe to dashboard different dashboard"); -$m->content_contains("Unowned Tickets"); -$m->content_contains("My Tickets"); -$m->content_lacks("Bookmarked Tickets", "only dashboard queries show up"); - -$m->form_name('SubscribeDashboard'); -$m->click_button(name => 'Save'); -$m->content_lacks("Permission denied"); -$m->content_contains("Subscribed to dashboard different dashboard"); - -RT::Record->FlushCache if RT::Record->can('FlushCache'); -TODO: { - local $TODO = "some kind of caching is still happening (it works if I remove the check above)"; - is($user_obj->Attributes->Named('Subscription'), 1, "we have a subscription"); -}; - -$m->get_ok("/Dashboards/Modify.html?id=$id"); -$m->follow_link_ok({text => "Subscription"}); -$m->content_contains("Modify the subscription to dashboard different dashboard"); - -$m->get_ok("/Dashboards/Modify.html?id=$id&Delete=1"); -$m->content_contains("Permission denied", "unable to delete dashboard because we lack DeleteOwnDashboard"); - -$m->warning_like(qr/Couldn't delete dashboard.*Permission denied/, "got a permission denied warning when trying to delete the dashboard"); - -$user_obj->PrincipalObj->GrantRight(Right => 'DeleteOwnDashboard', Object => $RT::System); - -$m->get_ok("/Dashboards/Modify.html?id=$id"); -$m->content_contains('Delete', "Delete button shows because we have DeleteOwnDashboard"); - -$m->form_name('ModifyDashboard'); -$m->click_button(name => 'Delete'); -$m->content_contains("Deleted dashboard $id"); - -$m->get("/Dashboards/Modify.html?id=$id"); -$m->content_lacks("different dashboard", "dashboard was deleted"); -$m->content_contains("Failed to load dashboard $id"); - -$m->warning_like(qr/Failed to load dashboard.*Couldn't find row/, "the dashboard was deleted"); - -$user_obj->PrincipalObj->GrantRight(Right => "SuperUser", Object => $RT::System); - -# now test that we warn about searches others can't see -# first create a personal saved search... -$m->get_ok($url."Search/Build.html"); -$m->follow_link_ok({text => 'Advanced'}); -$m->form_with_fields('Query'); -$m->field(Query => "id > 0"); -$m->submit; - -$m->form_with_fields('SavedSearchDescription'); -$m->field(SavedSearchDescription => "personal search"); -$m->click_button(name => "SavedSearchSave"); - -# then the system-wide dashboard -$m->get_ok($url."Dashboards/Modify.html?Create=1"); - -$m->form_name('ModifyDashboard'); -$m->field("Name" => 'system dashboard'); -$m->field("Privacy" => 'RT::System-1'); -$m->content_lacks('Delete', "Delete button hidden because we are creating"); -$m->click_button(value => 'Create'); -$m->content_lacks("No permission to create dashboards"); -$m->content_contains("Saved dashboard system dashboard"); - -$m->follow_link_ok({text => 'Queries'}); - -$m->form_name('Dashboard-Searches-body'); -$m->field('Searches-body-Available' => ['search-7-RT::User-22']); # XXX: :( :( -$m->click_button(name => 'add'); -$m->content_contains("Dashboard updated"); - -$m->content_contains("The following queries may not be visible to all users who can see this dashboard."); - -$m->follow_link_ok({text => 'system dashboard'}); -$m->content_contains("personal search", "saved search shows up"); -$m->content_contains("dashboard test", "matched ticket shows up"); - -# make sure the onlooker can't see the search... -$onlooker->PrincipalObj->GrantRight(Right => 'SeeDashboard', Object => $RT::System); - -my $omech = RT::Test::Web->new; -ok $omech->login(onlooker => 'onlooker'), "logged in"; -$omech->get_ok("/Dashboards"); - -$omech->follow_link_ok({text => 'system dashboard'}); -$omech->content_lacks("personal search", "saved search doesn't show up"); -$omech->content_lacks("dashboard test", "matched ticket doesn't show up"); - -$m->warning_like(qr/User .* tried to load container user /, "can't see other users' personal searches"); - diff --git a/rt/t/web/gnupg-outgoing.t b/rt/t/web/gnupg-outgoing.t deleted file mode 100644 index a46833c6c..000000000 --- a/rt/t/web/gnupg-outgoing.t +++ /dev/null @@ -1,363 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use warnings; - -use RT::Test tests => 492; - -plan skip_all => 'GnuPG required.' - unless eval 'use GnuPG::Interface; 1'; -plan skip_all => 'gpg executable is required.' - unless RT::Test->find_executable('gpg'); - - -use RT::Action::SendEmail; -use File::Temp qw(tempdir); - -RT::Test->set_mail_catcher; - -use_ok('RT::Crypt::GnuPG'); - -RT->Config->Set( GnuPG => - Enable => 1, - OutgoingMessagesFormat => 'RFC', -); - -RT->Config->Set( GnuPGOptions => - homedir => scalar tempdir( CLEANUP => 1 ), - passphrase => 'rt-test', - 'no-permission-warning' => undef, - 'trust-model' => 'always', -); -RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' ); - -RT::Test->import_gnupg_key('rt-recipient@example.com'); -RT::Test->import_gnupg_key('rt-test@example.com', 'public'); - -my $queue = RT::Test->load_or_create_queue( - Name => 'Regression', - CorrespondAddress => 'rt-recipient@example.com', - CommentAddress => 'rt-recipient@example.com', -); -ok $queue && $queue->id, 'loaded or created queue'; - -RT::Test->set_rights( - Principal => 'Everyone', - Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'], -); - -my ($baseurl, $m) = RT::Test->started_ok; -ok $m->login, 'logged in'; - -my @variants = ( - {}, - { Sign => 1 }, - { Encrypt => 1 }, - { Sign => 1, Encrypt => 1 }, -); - -# collect emails -my %mail = ( - plain => [], - signed => [], - encrypted => [], - signed_encrypted => [], -); - -diag "check in read-only mode that queue's props influence create/update ticket pages" if $ENV{TEST_VERBOSE}; -{ - foreach my $variant ( @variants ) { - set_queue_crypt_options( %$variant ); - $m->goto_create_ticket( $queue ); - $m->form_name('TicketCreate'); - if ( $variant->{'Encrypt'} ) { - ok $m->value('Encrypt', 2), "encrypt tick box is checked"; - } else { - ok !$m->value('Encrypt', 2), "encrypt tick box is unchecked"; - } - if ( $variant->{'Sign'} ) { - ok $m->value('Sign', 2), "sign tick box is checked"; - } else { - ok !$m->value('Sign', 2), "sign tick box is unchecked"; - } - } - - # to avoid encryption/signing during create - set_queue_crypt_options(); - - my $ticket = RT::Ticket->new( $RT::SystemUser ); - my ($id) = $ticket->Create( - Subject => 'test', - Queue => $queue->id, - Requestor => 'rt-test@example.com', - ); - ok $id, 'ticket created'; - - foreach my $variant ( @variants ) { - set_queue_crypt_options( %$variant ); - $m->goto_ticket( $id ); - $m->follow_link_ok({text => 'Reply'}, '-> reply'); - $m->form_number(3); - if ( $variant->{'Encrypt'} ) { - ok $m->value('Encrypt', 2), "encrypt tick box is checked"; - } else { - ok !$m->value('Encrypt', 2), "encrypt tick box is unchecked"; - } - if ( $variant->{'Sign'} ) { - ok $m->value('Sign', 2), "sign tick box is checked"; - } else { - ok !$m->value('Sign', 2), "sign tick box is unchecked"; - } - } -} - -# create a ticket for each combination -foreach my $queue_set ( @variants ) { - set_queue_crypt_options( %$queue_set ); - foreach my $ticket_set ( @variants ) { - create_a_ticket( %$ticket_set ); - } -} - -my $tid; -{ - my $ticket = RT::Ticket->new( $RT::SystemUser ); - ($tid) = $ticket->Create( - Subject => 'test', - Queue => $queue->id, - Requestor => 'rt-test@example.com', - ); - ok $tid, 'ticket created'; -} - -# again for each combination add a reply message -foreach my $queue_set ( @variants ) { - set_queue_crypt_options( %$queue_set ); - foreach my $ticket_set ( @variants ) { - update_ticket( $tid, %$ticket_set ); - } -} - - -# ------------------------------------------------------------------------------ -# now delete all keys from the keyring and put back secret/pub pair for rt-test@ -# and only public key for rt-recipient@ so we can verify signatures and decrypt -# like we are on another side recieve emails -# ------------------------------------------------------------------------------ - -unlink $_ foreach glob( RT->Config->Get('GnuPGOptions')->{'homedir'} ."/*" ); -RT::Test->import_gnupg_key('rt-recipient@example.com', 'public'); -RT::Test->import_gnupg_key('rt-test@example.com'); - -$queue = RT::Test->load_or_create_queue( - Name => 'Regression', - CorrespondAddress => 'rt-test@example.com', - CommentAddress => 'rt-test@example.com', -); -ok $queue && $queue->id, 'changed props of the queue'; - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'plain'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - ok !$msg->GetHeader('X-RT-Privacy'), "RT's outgoing mail has no crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Not encrypted', - "RT's outgoing mail looks not encrypted"; - ok !$msg->GetHeader('X-RT-Incoming-Signature'), - "RT's outgoing mail looks not signed"; - - like $msg->Content, qr/Some content/, "RT's mail includes copy of ticket text"; -} - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'signed'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - is $msg->GetHeader('X-RT-Privacy'), 'PGP', - "RT's outgoing mail has crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Not encrypted', - "RT's outgoing mail looks not encrypted"; - like $msg->GetHeader('X-RT-Incoming-Signature'), - qr/<rt-recipient\@example.com>/, - "RT's outgoing mail looks signed"; - - like $attachments[0]->Content, qr/Some content/, - "RT's mail includes copy of ticket text"; -} - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'encrypted'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - is $msg->GetHeader('X-RT-Privacy'), 'PGP', - "RT's outgoing mail has crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Success', - "RT's outgoing mail looks encrypted"; - ok !$msg->GetHeader('X-RT-Incoming-Signature'), - "RT's outgoing mail looks not signed"; - - like $attachments[0]->Content, qr/Some content/, - "RT's mail includes copy of ticket text"; -} - -foreach my $mail ( map cleanup_headers($_), @{ $mail{'signed_encrypted'} } ) { - my ($status, $id) = RT::Test->send_via_mailgate($mail); - is ($status >> 8, 0, "The mail gateway exited normally"); - ok ($id, "got id of a newly created ticket - $id"); - - my $tick = RT::Ticket->new( $RT::SystemUser ); - $tick->Load( $id ); - ok ($tick->id, "loaded ticket #$id"); - - my $txn = $tick->Transactions->First; - my ($msg, @attachments) = @{$txn->Attachments->ItemsArrayRef}; - - is $msg->GetHeader('X-RT-Privacy'), 'PGP', - "RT's outgoing mail has crypto"; - is $msg->GetHeader('X-RT-Incoming-Encryption'), 'Success', - "RT's outgoing mail looks encrypted"; - like $msg->GetHeader('X-RT-Incoming-Signature'), - qr/<rt-recipient\@example.com>/, - "RT's outgoing mail looks signed"; - - like $attachments[0]->Content, qr/Some content/, - "RT's mail includes copy of ticket text"; -} - -sub create_a_ticket { - my %args = (@_); - - RT::Test->clean_caught_mails; - - $m->goto_create_ticket( $queue ); - $m->form_name('TicketCreate'); - $m->field( Subject => 'test' ); - $m->field( Requestors => 'rt-test@example.com' ); - $m->field( Content => 'Some content' ); - - foreach ( qw(Sign Encrypt) ) { - if ( $args{ $_ } ) { - $m->tick( $_ => 1 ); - } else { - $m->untick( $_ => 1 ); - } - } - - $m->submit; - is $m->status, 200, "request successful"; - - unlike($m->content, qr/unable to sign outgoing email messages/); - - $m->get_ok('/'); # ensure that the mail has been processed - - my @mail = RT::Test->fetch_caught_mails; - check_text_emails( \%args, @mail ); -} - -sub update_ticket { - my $tid = shift; - my %args = (@_); - - RT::Test->clean_caught_mails; - - ok $m->goto_ticket( $tid ), "UI -> ticket #$tid"; - $m->follow_link_ok( { text => 'Reply' }, 'ticket -> reply' ); - $m->form_number(3); - $m->field( UpdateContent => 'Some content' ); - - foreach ( qw(Sign Encrypt) ) { - if ( $args{ $_ } ) { - $m->tick( $_ => 1 ); - } else { - $m->untick( $_ => 1 ); - } - } - - $m->click('SubmitTicket'); - is $m->status, 200, "request successful"; - $m->content_like(qr/Message recorded/, 'Message recorded') or diag $m->content; - - $m->get_ok('/'); # ensure that the mail has been processed - - my @mail = RT::Test->fetch_caught_mails; - check_text_emails( \%args, @mail ); -} - -sub check_text_emails { - my %args = %{ shift @_ }; - my @mail = @_; - - ok scalar @mail, "got some mail"; - for my $mail (@mail) { - if ( $args{'Encrypt'} ) { - unlike $mail, qr/Some content/, "outgoing email was encrypted"; - } else { - like $mail, qr/Some content/, "outgoing email was not encrypted"; - } - if ( $args{'Sign'} && $args{'Encrypt'} ) { - like $mail, qr/BEGIN PGP MESSAGE/, 'outgoing email was signed'; - } elsif ( $args{'Sign'} ) { - like $mail, qr/SIGNATURE/, 'outgoing email was signed'; - } else { - unlike $mail, qr/SIGNATURE/, 'outgoing email was not signed'; - } - } - if ( $args{'Sign'} && $args{'Encrypt'} ) { - push @{ $mail{'signed_encrypted'} }, @mail; - } elsif ( $args{'Sign'} ) { - push @{ $mail{'signed'} }, @mail; - } elsif ( $args{'Encrypt'} ) { - push @{ $mail{'encrypted'} }, @mail; - } else { - push @{ $mail{'plain'} }, @mail; - } -} - -sub cleanup_headers { - my $mail = shift; - # strip id from subject to create new ticket - $mail =~ s/^(Subject:)\s*\[.*?\s+#\d+\]\s*/$1 /m; - # strip several headers - foreach my $field ( qw(Message-ID X-RT-Original-Encoding RT-Originator RT-Ticket X-RT-Loop-Prevention) ) { - $mail =~ s/^$field:.*?\n(?! |\t)//gmsi; - } - return $mail; -} - -sub set_queue_crypt_options { - my %args = @_; - $m->get_ok("/Admin/Queues/Modify.html?id=". $queue->id); - $m->form_with_fields('Sign', 'Encrypt'); - foreach my $opt ('Sign', 'Encrypt') { - if ( $args{$opt} ) { - $m->tick($opt => 1); - } else { - $m->untick($opt => 1); - } - } - $m->submit; -} - |