| 1 | #!/usr/bin/perl -w |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use constant KEYID => '34B22806'; |
| 6 | use constant EMAIL => 'EdwardNG (Key for testing EdwardNG) <edwardng@ieval.ro>'; |
| 7 | |
| 8 | use File::Copy qw/cp/; |
| 9 | use File::Temp qw/tempdir/; |
| 10 | use Test::More tests => 20; |
| 11 | BEGIN { use_ok('App::EdwardNG', qw/import_pubkeys process_message/) }; |
| 12 | |
| 13 | umask 0077; # GPG doesn't like group-/world-readable homedirs |
| 14 | $ENV{EDWARDNG_DEBUG} = $ENV{TEST_VERBOSE}; |
| 15 | $ENV{EDWARDNG_KEYDIR} = tempdir 'App-EdwardNG-test.XXXX', TMPDIR => 1, CLEANUP => 1; |
| 16 | cp "t/keydir/$_", $ENV{EDWARDNG_KEYDIR} for qw/pubring.gpg secring.gpg/; |
| 17 | |
| 18 | my $contains_pubkey = App::EdwardNG::mp->parse_open('t/data/contains-pubkey'); |
| 19 | my @keys = import_pubkeys ($contains_pubkey, App::EdwardNG::mg); |
| 20 | is $keys[0], 'DE12658069C2F09BF996CC855AAF79E969137654', 'import_pubkeys'; |
| 21 | |
| 22 | my ($tmpl, %params); |
| 23 | |
| 24 | sub process { |
| 25 | my ($name, $expected) = @_; |
| 26 | ($tmpl, %params) = process_message("t/data/$name"); |
| 27 | is $tmpl, $expected, "Result for $name is $expected" or diag "GnuPG said: $params{message}" |
| 28 | } |
| 29 | |
| 30 | process 'mime-signed', 'sign'; |
| 31 | is $params{keyid}, KEYID, 'mime-signed keyid'; |
| 32 | is $params{email}, EMAIL, 'mime-signed email'; |
| 33 | |
| 34 | process 'mime-encrypted', 'encrypt'; |
| 35 | like $params{plaintext}, qr/MIME encrypted/, 'mime-signed plaintext'; |
| 36 | |
| 37 | process 'mime-signed-encrypted', 'signencrypt'; |
| 38 | is $params{keyid}, KEYID, 'mime-signed-encrypted keyid'; |
| 39 | is $params{email}, EMAIL, 'mime-signed-encrypted email'; |
| 40 | like $params{plaintext}, qr/MIME signed & encrypted/, 'mime-signed-encrypted plaintext'; |
| 41 | |
| 42 | process 'inline-signed', 'sign'; |
| 43 | is $params{keyid}, KEYID, 'inline-signed keyid'; |
| 44 | is $params{email}, EMAIL, 'inline-signed email'; |
| 45 | |
| 46 | process 'inline-encrypted', 'encrypt'; |
| 47 | like $params{plaintext}, qr/Inline encrypted/, 'inline-signed plaintext'; |
| 48 | |
| 49 | process 'inline-signed-encrypted', 'signencrypt'; |
| 50 | is $params{keyid}, KEYID, 'inline-signed-encrypted keyid'; |
| 51 | is $params{email}, EMAIL, 'inline-signed-encrypted email'; |
| 52 | like $params{plaintext}, qr/Inline signed & encrypted/, 'inline-signed-encrypted plaintext'; |