[Rt-commit] rt branch, 4.2/smime-v2, updated. rt-4.0.4-367-g02219dc

Ruslan Zakirov ruz at bestpractical.com
Thu Jan 12 14:51:46 EST 2012


The branch, 4.2/smime-v2 has been updated
       via  02219dc77a36c2b852ad3527ca0fc9a132cf7253 (commit)
       via  9fe3fb2272c5c40a3ab65092b147a718f44eed25 (commit)
       via  b78b4f4abd9ac016b8ed6a2465799ad8c873204f (commit)
      from  3d4e06c17077999ed62c561b80b06b90a6e8bea4 (commit)

Summary of changes:
 lib/RT/Test/SMIME.pm                         |  101 ++++++++++++++++++++++++++
 share/html/Admin/Elements/ShowKeyInfo        |    4 +-
 t/crypt/{gnupg => smime}/attachments-in-db.t |   24 +++----
 t/mail/smime/incoming.t                      |   58 ++-------------
 t/mail/smime/outgoing.t                      |   41 ++---------
 t/mail/smime/realmail.t                      |   48 +------------
 t/mail/smime/strict.t                        |   60 ++--------------
 t/web/smime/outgoing.t                       |   68 ++----------------
 8 files changed, 142 insertions(+), 262 deletions(-)
 create mode 100644 lib/RT/Test/SMIME.pm
 copy t/crypt/{gnupg => smime}/attachments-in-db.t (66%)

- Log -----------------------------------------------------------------
commit b78b4f4abd9ac016b8ed6a2465799ad8c873204f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Jan 12 23:48:17 2012 +0400

    extract common code into RT::Test::SMIME

diff --git a/lib/RT/Test/SMIME.pm b/lib/RT/Test/SMIME.pm
new file mode 100644
index 0000000..c12816b
--- /dev/null
+++ b/lib/RT/Test/SMIME.pm
@@ -0,0 +1,101 @@
+use strict;
+use warnings;
+
+package RT::Test::SMIME;
+
+use Test::More;
+use base qw(RT::Test);
+use File::Temp qw(tempdir);
+
+sub import {
+    my $class = shift;
+    my %args  = @_;
+    my $t     = $class->builder;
+
+    $t->plan( skip_all => 'openssl executable is required.' )
+        unless RT::Test->find_executable('openssl');
+
+    require RT::Crypt;
+    $class->SUPER::import(%args);
+
+    RT::Test::diag "GnuPG --homedir " . RT->Config->Get('GnuPGOptions')->{'homedir'};
+
+    $class->set_rights(
+        Principal => 'Everyone',
+        Right => ['CreateTicket', 'ShowTicket', 'SeeQueue', 'ReplyToTicket', 'ModifyTicket'],
+    );
+
+    $class->bootstrap_key_cf;
+
+    $class->export_to_level(1);
+}
+
+sub bootstrap_more_config {
+    my $self = shift;
+    my $handle = shift;
+    my $args = shift;
+
+    $self->SUPER::bootstrap_more_config($handle, $args, @_);
+
+    my $openssl = $self->find_executable('openssl');
+    my $keyring = $self->keyring_path;
+
+    print $handle qq{
+        Set(\%GnuPG, Enable => 0);
+        Set(\%SMIME =>
+            Enable => 1,
+            Passphrase => {
+                'root\@example.com' => '123456',
+                'sender\@example.com' => '123456',
+            },
+            OpenSSL => q{$openssl},
+            Keyring => q{$keyring},
+        );
+        Set(\@MailPlugins => qw(Auth::MailFrom Auth::Crypt));
+    };
+
+}
+
+sub bootstrap_key_cf {
+    my $self = shift;
+
+    my $cf = RT::CustomField->new( RT->SystemUser );
+    my ($ret, $msg) = $cf->Create(
+        Name       => 'SMIME Key',
+        LookupType => RT::User->new( RT->SystemUser )->CustomFieldLookupType,
+        Type       => 'TextSingle',
+    );
+    ok($ret, "Custom Field created");
+
+    my $OCF = RT::ObjectCustomField->new( $RT::SystemUser );
+    $OCF->Create(
+        CustomField => $cf->id,
+        ObjectId    => 0,
+    );
+}
+
+{ my $cache;
+sub keyring_path {
+    return $cache ||= shift->new_temp_dir(
+        crypt => smime => 'smime_keyring'
+    );
+} }
+
+sub key_path {
+    my $self = shift;
+    my $keys = RT::Test::get_abs_relocatable_dir(
+        (File::Spec->updir()) x 2,
+        qw(data smime keys),
+    );
+    return File::Spec->catfile( $keys => @_ ),
+}
+
+sub mail_set_path {
+    my $self = shift;
+    return RT::Test::get_abs_relocatable_dir(
+        (File::Spec->updir()) x 2,
+        qw(data smime mails),
+    );
+}
+
+1;
diff --git a/t/mail/smime/incoming.t b/t/mail/smime/incoming.t
index 50aa382..7039cfe 100644
--- a/t/mail/smime/incoming.t
+++ b/t/mail/smime/incoming.t
@@ -2,59 +2,13 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 21;
-
-my $openssl = RT::Test->find_executable('openssl');
-plan skip_all => 'openssl executable is required.'
-    unless $openssl;
+use RT::Test::SMIME tests => 21;
+my $test = 'RT::Test::SMIME';
 
 use IPC::Run3 'run3';
 use String::ShellQuote 'shell_quote';
 use RT::Tickets;
 
-my $keys = RT::Test::get_abs_relocatable_dir(
-    (File::Spec->updir()) x 2,
-    qw(data smime keys),
-);
-
-my $keyring = RT::Test->new_temp_dir(
-    crypt => smime => 'smime_keyring'
-);
-
-RT->Config->Set( Crypt =>
-    Enable   => 1,
-    Incoming => ['SMIME'],
-    Outgoing => 'SMIME',
-);
-RT->Config->Set( GnuPG => Enable => 0 );
-RT->Config->Set( SMIME =>
-    Enable => 1,
-    OutgoingMessagesFormat => 'RFC',
-    Passphrase => {
-        'sender at example.com' => '123456',
-    },
-    OpenSSL => $openssl,
-    Keyring => $keyring,
-);
-
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::Crypt' );
-
-{
-    my $cf = RT::CustomField->new( $RT::SystemUser );
-    my ($ret, $msg) = $cf->Create(
-        Name       => 'SMIME Key',
-        LookupType => RT::User->new( $RT::SystemUser )->CustomFieldLookupType,
-        Type       => 'TextSingle',
-    );
-    ok($ret, "Custom Field created");
-
-    my $OCF = RT::ObjectCustomField->new( $RT::SystemUser );
-    $OCF->Create(
-        CustomField => $cf->id,
-        ObjectId    => 0,
-    );
-}
-
 my ($url, $m) = RT::Test->started_ok;
 ok $m->login, "logged in";
 
@@ -109,7 +63,7 @@ RT::Test->close_mailgate_ok($mail);
             -from    => 'root at example.com',
             -to      => 'rt@' . $RT::rtname,
             -subject => "Encrypted message for queue",
-            File::Spec->catfile( $keys, 'sender at example.com.crt' ),
+            $test->key_path('sender at example.com.crt'),
         ),
         \"Subject: test\n\norzzzzzz",
         \$buf,
@@ -149,8 +103,8 @@ RT::Test->close_mailgate_ok($mail);
             shell_quote(
                 RT->Config->Get('SMIME')->{'OpenSSL'},
                 qw( smime -sign -nodetach -passin pass:123456),
-                -signer => File::Spec->catfile( $keys, 'root at example.com.crt' ),
-                -inkey  => File::Spec->catfile( $keys, 'root at example.com.key' ),
+                -signer => $test->key_path('root at example.com.crt'),
+                -inkey  => $test->key_path('root at example.com.key'),
             ),
             '|',
             shell_quote(
@@ -158,7 +112,7 @@ RT::Test->close_mailgate_ok($mail);
                 -from    => 'root at example.com',
                 -to      => 'rt@' . RT->Config->Get('rtname'),
                 -subject => "Encrypted and signed message for queue",
-                File::Spec->catfile( $keys, 'sender at example.com.crt' ),
+                $test->key_path('sender at example.com.crt'),
             )),
             \"Subject: test\n\norzzzzzz",
             \$buf,
diff --git a/t/mail/smime/outgoing.t b/t/mail/smime/outgoing.t
index d0a9407..418881c 100644
--- a/t/mail/smime/outgoing.t
+++ b/t/mail/smime/outgoing.t
@@ -2,43 +2,12 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 15;
-
-my $openssl = RT::Test->find_executable('openssl');
-plan skip_all => 'openssl executable is required.'
-    unless $openssl;
-
+use RT::Test::SMIME tests => 16;
+my $test = 'RT::Test::SMIME';
 
 use IPC::Run3 'run3';
 use RT::Interface::Email;
 
-my $keys = RT::Test::get_abs_relocatable_dir(
-    (File::Spec->updir()) x 2,
-    qw(data smime keys),
-);
-
-my $keyring = RT::Test->new_temp_dir(
-    crypt => smime => 'smime_keyring'
-);
-
-RT->Config->Set( Crypt =>
-    Enable   => 1,
-    Incoming => ['SMIME'],
-    Outgoing => 'SMIME',
-);
-RT->Config->Set( GnuPG => Enable => 0 );
-RT->Config->Set( SMIME =>
-    Enable => 1,
-    OutgoingMessagesFormat => 'RFC',
-    Passphrase => {
-        'sender at example.com' => '123456',
-    },
-    OpenSSL => $openssl,
-    Keyring => $keyring,
-);
-
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::Crypt' );
-
 my ($url, $m) = RT::Test->started_ok;
 ok $m->login, "logged in";
 
@@ -112,9 +81,9 @@ END
     local $@;
     ok(eval {
         run3([
-            $openssl, qw(smime -decrypt -passin pass:123456),
-            '-inkey', File::Spec->catfile($keys, 'root at example.com.key'),
-            '-recip', File::Spec->catfile($keys, 'root at example.com.crt')
+            qw(openssl smime -decrypt -passin pass:123456),
+            '-inkey', $test->key_path('root at example.com.key'),
+            '-recip', $test->key_path('root at example.com.crt')
         ], \$mails[0], \$buf, \$err )
         }, 'can decrypt'
     );
diff --git a/t/mail/smime/realmail.t b/t/mail/smime/realmail.t
index fb45c00..dc9722d 100644
--- a/t/mail/smime/realmail.t
+++ b/t/mail/smime/realmail.t
@@ -2,53 +2,11 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 92;
-
-my $openssl = RT::Test->find_executable('openssl');
-plan skip_all => 'openssl executable is required.'
-    unless $openssl;
-
+use RT::Test::SMIME tests => 93;
 use Digest::MD5 qw(md5_hex);
 
-my $mails = RT::Test::get_abs_relocatable_dir(
-    (File::Spec->updir()) x 2,
-    qw(data smime mails),
-);
-my $keyring = RT::Test->new_temp_dir(
-    crypt => smime => 'smime_keyring'
-);
-
-RT->Config->Set( Crypt =>
-    Enable   => 1,
-    Incoming => ['SMIME'],
-    Outgoing => 'SMIME',
-);
-RT->Config->Set( GnuPG => Enable => 0 );
-RT->Config->Set( SMIME =>
-    Enable => 1,
-    Passphrase => {
-        'root at example.com' => '123456',
-    },
-    OpenSSL => $openssl,
-    Keyring => $keyring,
-);
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::Crypt' );
-
-{
-    my $cf = RT::CustomField->new( $RT::SystemUser );
-    my ($ret, $msg) = $cf->Create(
-        Name       => 'SMIME Key',
-        LookupType => RT::User->new( $RT::SystemUser )->CustomFieldLookupType,
-        Type       => 'TextSingle',
-    );
-    ok($ret, "Custom Field created");
-
-    my $OCF = RT::ObjectCustomField->new( $RT::SystemUser );
-    $OCF->Create(
-        CustomField => $cf->id,
-        ObjectId    => 0,
-    );
-}
+my $test = 'RT::Test::SMIME';
+my $mails = $test->mail_set_path;
 
 RT::Test->import_smime_key('root at example.com');
 RT::Test->import_smime_key('sender at example.com');
diff --git a/t/mail/smime/strict.t b/t/mail/smime/strict.t
index c91b438..df71677 100644
--- a/t/mail/smime/strict.t
+++ b/t/mail/smime/strict.t
@@ -2,60 +2,14 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 22;
-
-my $openssl = RT::Test->find_executable('openssl');
-plan skip_all => 'openssl executable is required.'
-    unless $openssl;
+use RT::Test::SMIME tests => 22;
+my $test = 'RT::Test::SMIME';
 
 use IPC::Run3 'run3';
 use String::ShellQuote 'shell_quote';
 use RT::Tickets;
 
-my $keys = RT::Test::get_abs_relocatable_dir(
-    (File::Spec->updir()) x 2,
-    qw(data smime keys),
-);
-
-my $keyring = RT::Test->new_temp_dir(
-    crypt => smime => 'smime_keyring'
-);
-
-RT->Config->Set( Crypt =>
-    Enable   => 1,
-    Strict   => 1,
-    Incoming => ['SMIME'],
-    Outgoing => 'SMIME',
-);
-RT->Config->Set( GnuPG => Enable => 0 );
-RT->Config->Set( SMIME =>
-    Enable => 1,
-    Strict => 1,
-    OutgoingMessagesFormat => 'RFC',
-    Passphrase => {
-        'sender at example.com' => '123456',
-    },
-    OpenSSL => $openssl,
-    Keyring => $keyring,
-);
-
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::Crypt' );
-
-{
-    my $cf = RT::CustomField->new( $RT::SystemUser );
-    my ($ret, $msg) = $cf->Create(
-        Name       => 'SMIME Key',
-        LookupType => RT::User->new( $RT::SystemUser )->CustomFieldLookupType,
-        Type       => 'TextSingle',
-    );
-    ok($ret, "Custom Field created");
-
-    my $OCF = RT::ObjectCustomField->new( $RT::SystemUser );
-    $OCF->Create(
-        CustomField => $cf->id,
-        ObjectId    => 0,
-    );
-}
+RT->Config->Get('Crypt')->{'Strict'} = 1;
 
 {
     my $template = RT::Template->new($RT::SystemUser);
@@ -122,7 +76,7 @@ RT::Test->close_mailgate_ok($mail);
             -from    => 'root at example.com',
             -to      => 'rt@' . $RT::rtname,
             -subject => "Encrypted message for queue",
-            File::Spec->catfile( $keys, 'sender at example.com.crt' ),
+            $test->key_path('sender at example.com.crt' ),
         ),
         \"Subject: test\n\norzzzzzz",
         \$buf,
@@ -162,8 +116,8 @@ RT::Test->close_mailgate_ok($mail);
             shell_quote(
                 RT->Config->Get('SMIME')->{'OpenSSL'},
                 qw( smime -sign -nodetach -passin pass:123456),
-                -signer => File::Spec->catfile( $keys, 'root at example.com.crt' ),
-                -inkey  => File::Spec->catfile( $keys, 'root at example.com.key' ),
+                -signer => $test->key_path('root at example.com.crt' ),
+                -inkey  => $test->key_path('root at example.com.key' ),
             ),
             '|',
             shell_quote(
@@ -171,7 +125,7 @@ RT::Test->close_mailgate_ok($mail);
                 -from    => 'root at example.com',
                 -to      => 'rt@' . RT->Config->Get('rtname'),
                 -subject => "Encrypted and signed message for queue",
-                File::Spec->catfile( $keys, 'sender at example.com.crt' ),
+                $test->key_path('sender at example.com.crt' ),
             )),
             \"Subject: test\n\norzzzzzz",
             \$buf,
diff --git a/t/web/smime/outgoing.t b/t/web/smime/outgoing.t
index 6a5ff3c..bfa24d5 100644
--- a/t/web/smime/outgoing.t
+++ b/t/web/smime/outgoing.t
@@ -2,78 +2,23 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 495;
-
-my $openssl = RT::Test->find_executable('openssl');
-plan skip_all => 'openssl executable is required.'
-    unless $openssl;
+use RT::Test::SMIME tests => 497;
+my $test = 'RT::Test::SMIME';
 
 use RT::Action::SendEmail;
 use File::Temp qw(tempdir);
 
 use_ok('RT::Crypt::SMIME');
 
-my $keys = RT::Test::get_abs_relocatable_dir(
-    (File::Spec->updir()) x 2,
-    qw(data smime keys),
-);
-
-my $keyring = RT::Test->new_temp_dir(
-    crypt => smime => 'smime_keyring'
-);
-
-RT->Config->Set( Crypt =>
-    Enable   => 1,
-    Incoming => ['SMIME'],
-    Outgoing => 'SMIME',
-);
-RT->Config->Set( GnuPG => Enable => 0 );
-RT->Config->Set( SMIME =>
-    Enable => 1,
-    OutgoingMessagesFormat => 'RFC',
-    Passphrase => {
-        'sender at example.com' => '123456',
-        'root at example.com' => '123456',
-    },
-    OpenSSL => $openssl,
-    Keyring => $keyring,
-);
-RT->Config->Set( 'MailPlugins' => 'Auth::MailFrom', 'Auth::Crypt' );
-
 RT::Test->import_smime_key('sender at example.com');
 
-{
-    my $cf = RT::CustomField->new( $RT::SystemUser );
-    my ($ret, $msg) = $cf->Create(
-        Name       => 'SMIME Key',
-        LookupType => RT::User->new( $RT::SystemUser )->CustomFieldLookupType,
-        Type       => 'TextSingle',
-    );
-    ok($ret, "Custom Field created");
-
-    my $OCF = RT::ObjectCustomField->new( $RT::SystemUser );
-    $OCF->Create(
-        CustomField => $cf->id,
-        ObjectId    => 0,
-    );
-}
-
 my $user_email = 'root at example.com';
 {
-    my $user = RT::User->new( $RT::SystemUser );
-    $user->LoadByEmail( $user_email );
-    unless ( $user->id ) {
-        $user->Create(
-            Name         => $user_email,
-            EmailAddress => $user_email,
-            Privileged   => 1,
-        );
-    }
-    my ($status, $msg) = $user->AddCustomFieldValue(
-        Field => 'SMIME Key',
-        Value => RT::Test->file_content([$keys, $user_email .'.crt']),
+    my $user = RT::Test->load_or_create_user(
+        Name => $user_email, EmailAddress => $user_email
     );
-    ok $status, "set key for the user" or diag "error: $msg";
+    ok $user && $user->id, 'loaded or created user';
+    RT::Test->import_smime_key($user_email, $user);
 }
 
 my $queue = RT::Test->load_or_create_queue(
@@ -187,6 +132,7 @@ foreach my $queue_set ( @variants ) {
 # like we are on another side recieving emails
 # ------------------------------------------------------------------------------
 
+my $keyring = $test->keyring_path;
 unlink $_ foreach glob( $keyring ."/*" );
 {
     my $sender = 'sender at example.com';

commit 9fe3fb2272c5c40a3ab65092b147a718f44eed25
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Jan 12 23:49:11 2012 +0400

    test encrypting attachments in DB with SMIME

diff --git a/t/crypt/smime/attachments-in-db.t b/t/crypt/smime/attachments-in-db.t
new file mode 100644
index 0000000..da18786
--- /dev/null
+++ b/t/crypt/smime/attachments-in-db.t
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use RT::Test::SMIME tests => 13;
+
+use IPC::Run3 'run3';
+use String::ShellQuote 'shell_quote';
+use RT::Tickets;
+
+RT->Config->Get('Crypt')->{'AllowEncryptDataInDB'} = 1;
+
+RT::Test->import_smime_key('sender at example.com');
+my $queue = RT::Test->load_or_create_queue(
+    Name              => 'General',
+    CorrespondAddress => 'sender at example.com',
+);
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    my $ticket = RT::Test->create_ticket(
+        Queue   => $queue->id,
+        Subject => 'test',
+        Content => 'test',
+    );
+
+    my $txn = $ticket->Transactions->First;
+    ok $txn && $txn->id, 'found first transaction';
+    is $txn->Type, 'Create', 'it is Create transaction';
+
+    my $attach = $txn->Attachments->First;
+    ok $attach && $attach->id, 'found attachment';
+    is $attach->Content, 'test', 'correct content';
+
+    my ($status, $msg) = $attach->Encrypt;
+    ok $status, 'encrypted attachment' or diag "error: $msg";
+
+    isnt $attach->Content, 'test', 'correct content';
+
+    ($status, $msg) = $attach->Decrypt;
+    ok $status, 'decrypted attachment' or diag "error: $msg";
+
+    is $attach->Content, 'test', 'correct content';
+}
+
+
+

commit 02219dc77a36c2b852ad3527ca0fc9a132cf7253
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Thu Jan 12 23:49:51 2012 +0400

    reference proper argument in loc string

diff --git a/share/html/Admin/Elements/ShowKeyInfo b/share/html/Admin/Elements/ShowKeyInfo
index 6912990..73edbe5 100644
--- a/share/html/Admin/Elements/ShowKeyInfo
+++ b/share/html/Admin/Elements/ShowKeyInfo
@@ -102,8 +102,8 @@ return unless @protocols;
 
 my $title;
 unless ( $Type eq 'private' ) {
-    $title = loc('Public key(s) for [_2]', $EmailAddress);
+    $title = loc('Public key(s) for [_1]', $EmailAddress);
 } else {
-    $title = loc('Private key(s) for [_2]', $EmailAddress);
+    $title = loc('Private key(s) for [_1]', $EmailAddress);
 }
 </%INIT>

-----------------------------------------------------------------------


More information about the Rt-commit mailing list