[Rt-commit] [rtir] 01/02: Create RT::IR::Test::GnuPG

Kevin Falcone falcone at bestpractical.com
Fri Apr 18 22:54:20 EDT 2014


This is an automated email from the git hooks/post-receive script.

falcone pushed a commit to branch 3.2/test-fixes
in repository rtir.

commit 8fe86fef12aaa1a53f45a1470ea690689c998327
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri Apr 18 22:37:38 2014 -0400

    Create RT::IR::Test::GnuPG
    
    This gives us a shim similar to RT::Test::GnuPG to do all the config
    writing and ensure that GnuPG is turned on.  This cargo cults frmo
    RT::Test::GnuPG *except* that it calls add_rights rather than set_rights
    because set_rights blows away all the RT::IR DutyTeam rights and RT
    freaks out when it can't load the Constituency CF during creation.
    
    While in here, clean up RT::IR::Test to just use base and to calculate
    what level is needed to export default_agent and rtir_user to (sometimes
    it'll be 1, sometimes 2).  This code is stolen from RT::Test.
---
 lib/RT/IR/Test.pm.in    |  21 ++++------
 lib/RT/IR/Test/GnuPG.pm | 104 ++++++++++++++++++++++++++++++++++++++++++++++++
 t/gnupg/on-create.t     |  25 +-----------
 t/gnupg/on-incident.t   |  21 +---------
 t/gnupg/on-update.t     |  24 +----------
 5 files changed, 116 insertions(+), 79 deletions(-)

diff --git a/lib/RT/IR/Test.pm.in b/lib/RT/IR/Test.pm.in
index e782ffc..b284b64 100644
--- a/lib/RT/IR/Test.pm.in
+++ b/lib/RT/IR/Test.pm.in
@@ -54,18 +54,7 @@ use lib qw(/opt/rt4/local/lib /opt/rt4/lib);
 
 package RT::IR::Test;
 
-our @ISA;
-BEGIN {
-    local $@ = undef;
-    eval { require RT::Test; 1 } or do {
-        require Test::More;
-        Test::More::BAIL_OUT(
-            "requires 3.8 to run tests. Error:\n$@\n"
-            ."You may need to set PERL5LIB=/path/to/rt/lib"
-        );
-    };
-    push @ISA, 'RT::Test';
-}
+use base 'RT::Test';
 
 use RT::IR::Test::Web;
 
@@ -86,7 +75,13 @@ sub import {
     }
 
     $class->SUPER::import( %args );
-    $class->export_to_level(1);
+
+    my $level = 1;
+    while ( my ($package) = caller($level-1) ) {
+        last unless $package =~ /Test/;
+        $level++;
+    }
+    RT::IR::Test->export_to_level($level);
 
     RT->Config->Set( 'rtirname' => 'regression_tests' );
 }
diff --git a/lib/RT/IR/Test/GnuPG.pm b/lib/RT/IR/Test/GnuPG.pm
new file mode 100644
index 0000000..21c1df6
--- /dev/null
+++ b/lib/RT/IR/Test/GnuPG.pm
@@ -0,0 +1,104 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
+#                                          <sales at bestpractical.com>
+#
+# (Except where explicitly superseded by other copyright notices)
+#
+#
+# LICENSE:
+#
+# This work is made available to you under the terms of Version 2 of
+# the GNU General Public License. A copy of that license should have
+# been provided with this software, but in any event can be snarfed
+# from www.gnu.org.
+#
+# This work is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 or visit their web page on the internet at
+# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+#
+#
+# CONTRIBUTION SUBMISSION POLICY:
+#
+# (The following paragraph is not intended to limit the rights granted
+# to you to modify and distribute this software under the terms of
+# the GNU General Public License and is only of importance to you if
+# you choose to contribute your changes and enhancements to the
+# community by submitting them to Best Practical Solutions, LLC.)
+#
+# By intentionally submitting any modifications, corrections or
+# derivatives to this work, or any other work intended for use with
+# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+# you are the copyright holder for those contributions and you grant
+# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+# royalty-free, perpetual, license to use, copy, create derivative
+# works based on those contributions, and sublicense and distribute
+# those contributions and any derivatives thereof.
+#
+# END BPS TAGGED BLOCK }}}
+
+package RT::IR::Test::GnuPG;
+use strict;
+use warnings;
+use Test::More;
+use base qw(RT::IR::Test);
+use File::Temp qw(tempdir);
+
+sub import {
+    my $class = shift;
+    my %args  = @_;
+    my $t     = $class->builder;
+
+    $t->plan( skip_all => 'GnuPG required.' )
+      unless eval { require GnuPG::Interface; 1 };
+    $t->plan( skip_all => 'gpg executable is required.' )
+      unless RT::Test->find_executable('gpg');
+
+    $class->SUPER::import(%args);
+
+    RT::Test::diag "GnuPG --homedir " . RT->Config->Get('GnuPGOptions')->{'homedir'};
+
+    $class->add_rights(
+        Principal => 'Everyone',
+        Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'],
+    );
+}
+
+sub bootstrap_more_config {
+    my $self = shift;
+    my $handle = shift;
+    my $args = shift;
+
+    $self->SUPER::bootstrap_more_config($handle, $args, @_);
+
+    my %gnupg_options = (
+        'no-permission-warning' => undef,
+        $args->{gnupg_options} ? %{ $args->{gnupg_options} } : (),
+    );
+    $gnupg_options{homedir} ||= scalar tempdir( CLEANUP => 1 );
+
+    use Data::Dumper;
+    local $Data::Dumper::Terse = 1; # "{...}" instead of "$VAR1 = {...};"
+    my $dumped_gnupg_options = Dumper(\%gnupg_options);
+
+    print $handle qq{
+Set(\%GnuPG, (
+    Enable                 => 1,
+    OutgoingMessagesFormat => 'RFC',
+));
+Set(\%GnuPGOptions => \%{ $dumped_gnupg_options });
+Set(\@MailPlugins => qw(Auth::MailFrom Auth::Crypt));
+};
+
+}
+
+1;
diff --git a/t/gnupg/on-create.t b/t/gnupg/on-create.t
index d2ca874..4fe44be 100644
--- a/t/gnupg/on-create.t
+++ b/t/gnupg/on-create.t
@@ -3,22 +3,7 @@
 use strict;
 use warnings;
 
-use RT::IR::Test tests => 61;
-
-use File::Temp qw(tempdir);
-
-RT->Config->Set( 'GnuPG',
-                 Enable => 1,
-                 OutgoingMessagesFormat => 'RFC' );
-
-RT->Config->Set( GnuPGOptions =>
-    homedir => scalar tempdir( CLEANUP => 0 ),
-    passphrase => 'rt-test',
-    'no-permission-warning' => undef,
-);
-diag "GnuPG --homedir ". RT->Config->Get('GnuPGOptions')->{'homedir'};
-
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' );
+use RT::IR::Test::GnuPG tests => 61, gnupg_options => { passphrase => 'rt-test' };
 
 my $queue = RT::Test->load_or_create_queue(
     Name              => 'Incident Reports',
@@ -29,15 +14,10 @@ ok $queue && $queue->id, 'loaded or created queue';
 
 my ($baseurl) = RT::Test->started_ok;
 my $agent = default_agent();
-rtir_user();
+RT::IR::Test::rtir_user();
 $agent->login( rtir_test_user => 'rtir_test_pass' );
 
 
-RT::Test->set_rights(
-    Principal => 'Everyone',
-    Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'],
-);
-
 {
     RT::Test->import_gnupg_key('rt-recipient at example.com');
     RT::Test->trust_gnupg_key('rt-recipient at example.com');
@@ -296,4 +276,3 @@ sub check_text_emails {
     }
 }
 
-
diff --git a/t/gnupg/on-incident.t b/t/gnupg/on-incident.t
index d70a0af..48f7f83 100644
--- a/t/gnupg/on-incident.t
+++ b/t/gnupg/on-incident.t
@@ -3,21 +3,7 @@
 use strict;
 use warnings;
 
-use RT::IR::Test tests => 40;
-use File::Temp qw(tempdir);
-
-RT->Config->Set( 'GnuPG',
-                 Enable => 1,
-                 OutgoingMessagesFormat => 'RFC' );
-
-RT->Config->Set( GnuPGOptions =>
-    homedir => scalar tempdir( CLEANUP => 0 ),
-    passphrase => 'rt-test',
-    'no-permission-warning' => undef,
-);
-diag "GnuPG --homedir ". RT->Config->Get('GnuPGOptions')->{'homedir'};
-
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' );
+use RT::IR::Test::GnuPG tests => 40, gnupg_options => { passphrase => 'rt-test' };
 
 my $queue = RT::Test->load_or_create_queue(
     Name              => 'Incident Reports',
@@ -31,11 +17,6 @@ my $agent = default_agent();
 rtir_user();
 $agent->login( rtir_test_user => 'rtir_test_pass' );
 
-RT::Test->set_rights(
-    Principal => 'Everyone',
-    Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'OwnTicket', 'ReplyToTicket', 'ModifyTicket'],
-);
-
 diag "check that things don't work if there is no key";
 {
 
diff --git a/t/gnupg/on-update.t b/t/gnupg/on-update.t
index 96681b9..e6a1b33 100644
--- a/t/gnupg/on-update.t
+++ b/t/gnupg/on-update.t
@@ -3,23 +3,7 @@
 use strict;
 use warnings;
 
-use RT::IR::Test tests => 68;
-use File::Temp qw(tempdir);
-
-RT->Config->Set( 'GnuPG',
-                 Enable => 1,
-                 OutgoingMessagesFormat => 'RFC' );
-
-RT->Config->Set( GnuPGOptions =>
-    homedir => scalar tempdir( CLEANUP => 0 ),
-    passphrase => 'rt-test',
-    'no-permission-warning' => undef,
-);
-diag "GnuPG --homedir ". RT->Config->Get('GnuPGOptions')->{'homedir'};
-
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::GnuPG' );
-
-RT->Config->Set( Plugins => 'RT::FM', 'RT::IR' );
+use RT::IR::Test::GnuPG tests => 68, gnupg_options => { passphrase => 'rt-test' };
 
 my $queue = RT::Test->load_or_create_queue(
     Name              => 'Incident Reports',
@@ -33,12 +17,6 @@ my $agent = default_agent();
 rtir_user();
 $agent->login( rtir_test_user => 'rtir_test_pass' );
 
-
-RT::Test->set_rights(
-    Principal => 'Everyone',
-    Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'],
-);
-
 {
     RT::Test->import_gnupg_key('rt-recipient at example.com');
     RT::Test->trust_gnupg_key('rt-recipient at example.com');

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list