diff options
Diffstat (limited to 't')
-rw-r--r-- | t/000_setup.t | 54 | ||||
-rw-r--r-- | t/Fingerprint.t | 29 | ||||
-rw-r--r-- | t/Interface.t | 29 | ||||
-rw-r--r-- | t/MyTest.pm | 63 | ||||
-rw-r--r-- | t/MyTestSpecific.pm | 170 | ||||
-rw-r--r-- | t/UserId.t | 28 | ||||
-rw-r--r-- | t/clearsign.t | 38 | ||||
-rw-r--r-- | t/decrypt.t | 91 | ||||
-rw-r--r-- | t/detach_sign.t | 38 | ||||
-rw-r--r-- | t/encrypt.t | 76 | ||||
-rw-r--r-- | t/encrypt_symmetrically.t | 39 | ||||
-rw-r--r-- | t/export_keys.t | 37 | ||||
-rw-r--r-- | t/get_public_keys.t | 257 | ||||
-rw-r--r-- | t/get_secret_keys.t | 117 | ||||
-rw-r--r-- | t/import_keys.t | 39 | ||||
-rw-r--r-- | t/list_public_keys.t | 76 | ||||
-rw-r--r-- | t/list_secret_keys.t | 102 | ||||
-rw-r--r-- | t/list_sigs.t | 71 | ||||
-rw-r--r-- | t/passphrase_handling.t | 62 | ||||
-rw-r--r-- | t/sign.t | 38 | ||||
-rw-r--r-- | t/sign_and_encrypt.t | 39 | ||||
-rw-r--r-- | t/verify.t | 39 | ||||
-rw-r--r-- | t/version_updates.t | 30 | ||||
-rw-r--r-- | t/wrap_call.t | 59 | ||||
-rw-r--r-- | t/z_delete_keys.t | 51 | ||||
-rw-r--r-- | t/zzz_cleanup.t | 27 |
26 files changed, 1699 insertions, 0 deletions
diff --git a/t/000_setup.t b/t/000_setup.t new file mode 100644 index 0000000..8e3235a --- /dev/null +++ b/t/000_setup.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl -w + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; +use Cwd; +use File::Path qw (make_path); +use File::Copy; + +TEST +{ + my $homedir = $gnupg->options->homedir(); + make_path($homedir, { mode => 0700 }); + + copy('test/gpg.conf', $homedir . '/gpg.conf'); + + if ($gnupg->cmp_version($gnupg->version, '2.2') >= 0) { + my $agentconf = IO::File->new( "> " . $homedir . "/gpg-agent.conf" ); + # Classic gpg can't use loopback pinentry programs like fake-pinentry.pl. + $agentconf->write( + "allow-preset-passphrase\n". + "allow-loopback-pinentry\n". + "pinentry-program " . getcwd() . "/test/fake-pinentry.pl\n" + ); + $agentconf->close(); + + my $error = system("gpg-connect-agent", "--homedir", "$homedir", '/bye'); + if ($error) { + warn "gpg-connect-agent returned error : $error"; + } + + $error = system('gpg-connect-agent', "--homedir", "$homedir", 'reloadagent', '/bye'); + if ($error) { + warn "gpg-connect-agent returned error : $error"; + } + + $error = system("gpg-agent", '--homedir', "$homedir"); + if ($error) { + warn "gpg-agent returned error : $error"; + } + + } + reset_handles(); + + my $pid = $gnupg->import_keys(command_args => [ 'test/public_keys.pgp', 'test/secret_keys.pgp', 'test/new_secret.pgp' ], + options => [ 'batch'], + handles => $handles); + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/Fingerprint.t b/t/Fingerprint.t new file mode 100644 index 0000000..bdf60c9 --- /dev/null +++ b/t/Fingerprint.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl -w +# +# $Id: Fingerprint.t,v 1.1 2001/04/30 01:36:12 ftobin Exp $ +# + +use strict; + +use lib './t'; +use MyTest; + +use GnuPG::Fingerprint; + +my $v1 = '5A29DAE3649ACCA7BF59A67DBAED721F334C9V14'; +my $v2 = '4F863BBBA8166F0A340F600356FFD10A260C4FA3'; + +my $fingerprint = GnuPG::Fingerprint->new( as_hex_string => $v1 ); + +# deprecation test +TEST +{ + $fingerprint->hex_data() eq $v1; +}; + +# deprecation test +TEST +{ + $fingerprint->hex_data( $v2 ); + $fingerprint->as_hex_string() eq $v2; +}; diff --git a/t/Interface.t b/t/Interface.t new file mode 100644 index 0000000..ec5dfe5 --- /dev/null +++ b/t/Interface.t @@ -0,0 +1,29 @@ +#!/usr/bin/perl -w +# +# $Id: Interface.t,v 1.1 2001/04/30 02:04:25 ftobin Exp $ +# + +use strict; + +use lib './t'; +use MyTest; + +use GnuPG::Interface; + +my $v1 = './test/fake-gpg-v1'; +my $v2 = './test/fake-gpg-v2'; + +my $gnupg = GnuPG::Interface->new( call => $v1 ); + +# deprecation test +TEST +{ + $gnupg->gnupg_call() eq $v1; +}; + +# deprecation test +TEST +{ + $gnupg->gnupg_call( $v2 ); + $gnupg->call() eq $v2; +}; diff --git a/t/MyTest.pm b/t/MyTest.pm new file mode 100644 index 0000000..235d729 --- /dev/null +++ b/t/MyTest.pm @@ -0,0 +1,63 @@ +# MyTest.pm +# - module for use with test scripts +# +# Copyright (C) 2000 Frank J. Tobin <ftobin@cpan.org> +# +# This module is free software; you can redistribute it and/or modify it +# under the same terms as Perl itself. +# +# This program 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. +# +# $Id: MyTest.pm,v 1.3 2001/08/21 13:31:50 ftobin Exp $ +# + +package MyTest; + +use strict; +use English qw( -no_match_vars ); +use Exporter; +use IO::File; +use vars qw( @ISA @EXPORT ); + +@ISA = qw( Exporter ); +@EXPORT = qw( TEST ); + +$OUTPUT_AUTOFLUSH = 1; + +print "1..", COUNT_TESTS(), "\n"; + +my $counter = 0; + +sub TEST ( & ) +{ + my ( $code ) = @_; + + $counter++; + + &$code or print "not "; + print "ok $counter\n"; +} + + +sub COUNT_TESTS +{ + my ( $file ) = @_; + $file ||= $PROGRAM_NAME; + + my $tests = 0; + + my $in = IO::File->new( $file ); + + while ( $_ = $in->getline() ) + { + $tests++ + if /^\s*TEST\s*/; + } + + return $tests; +} + + +1; diff --git a/t/MyTestSpecific.pm b/t/MyTestSpecific.pm new file mode 100644 index 0000000..c335d62 --- /dev/null +++ b/t/MyTestSpecific.pm @@ -0,0 +1,170 @@ +# MyTestSpecific.pm +# - module for use with test scripts +# +# Copyright (C) 2000 Frank J. Tobin <ftobin@cpan.org> +# +# This module is free software; you can redistribute it and/or modify it +# under the same terms as Perl itself. +# +# This program 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. +# +# $Id: MyTestSpecific.pm,v 1.7 2001/08/21 13:31:50 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); +use Fatal qw/ open close /; +use IO::File; +use IO::Handle; +use IO::Seekable; +use File::Compare; +use Exporter; +use Class::Struct; +use File::Temp qw (tempdir); + +use GnuPG::Interface; +use GnuPG::Handles; + +use vars qw( @ISA @EXPORT + $stdin $stdout $stderr + $gpg_program $handles $gnupg + %texts + ); + +@ISA = qw( Exporter ); +@EXPORT = qw( stdin stdout stderr + gnupg_program handles reset_handles + texts file_match + ); + +my $homedir; +if (-f "test/gnupghome") { + my $record = IO::File->new( "< test/gnupghome" ); + $homedir = <$record>; + $record->close(); +} else { + $homedir = tempdir( DIR => '/tmp'); + my $record = IO::File->new( "> test/gnupghome" ); + $record->write($homedir); + $record->close(); +} + +$ENV{'GNUPGHOME'} = $homedir; + +$gnupg = GnuPG::Interface->new( passphrase => 'test' ); +$gnupg->options->hash_init( homedir => $homedir, + armor => 1, + meta_interactive => 0, + meta_signing_key_id => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C', + always_trust => 1, + ); + +struct( Text => { fn => "\$", fh => "\$", data => "\$" } ); + +$texts{plain} = Text->new(); +$texts{plain}->fn( 'test/plain.1.txt' ); + +$texts{alt_plain} = Text->new(); +$texts{alt_plain}->fn( 'test/plain.2.txt' ); + +$texts{encrypted} = Text->new(); +$texts{encrypted}->fn( 'test/encrypted.1.gpg' ); + +$texts{alt_encrypted} = Text->new(); +$texts{alt_encrypted}->fn( 'test/encrypted.2.gpg' ); + +$texts{signed} = Text->new(); +$texts{signed}->fn( 'test/signed.1.asc' ); + +$texts{key} = Text->new(); +$texts{key}->fn( 'test/key.1.asc' ); + +$texts{temp} = Text->new(); +$texts{temp}->fn( 'test/temp' ); + + +foreach my $name ( qw( plain alt_plain encrypted alt_encrypted signed key ) ) +{ + my $entry = $texts{$name}; + my $filename = $entry->fn(); + my $fh = IO::File->new( $filename ) + or die "cannot open $filename: $ERRNO"; + $entry->data( [ $fh->getlines() ] ); +} + +sub reset_handles +{ + foreach ( $stdin, $stdout, $stderr ) + { + $_ = IO::Handle->new(); + } + + $handles = GnuPG::Handles->new + ( stdin => $stdin, + stdout => $stdout, + stderr => $stderr + ); + + foreach my $name ( qw( plain alt_plain encrypted alt_encrypted signed key ) ) + { + my $entry = $texts{$name}; + my $filename = $entry->fn(); + my $fh = IO::File->new( $filename ) + or die "cannot open $filename: $ERRNO"; + $entry->fh( $fh ); + } + + { + my $entry = $texts{temp}; + my $filename = $entry->fn(); + my $fh = IO::File->new( $filename, 'w' ) + or die "cannot open $filename: $ERRNO"; + $entry->fh( $fh ); + } +} + + + +sub file_match +{ + my ( $orig, @compares ) = @_; + + my $found_match = 0; + + foreach my $file ( @compares ) + { + return 1 + if compare( $file, $orig ) == 0; + } + + return 0; +} + + + +# blank user_id_string and different validity for expired sig in GPG 2.2.x vs 1.x, 2.1 +sub get_expired_test_sig_params { + my $gnupg = shift; + my $version = $gnupg->version; + + my %sig_params = ( + date_string => '2000-03-16', + hex_id => '56FFD10A260C4FA3', + sig_class => 0x10, + algo_num => 17, + is_exportable => 1, + ); + if ($gnupg->cmp_version($gnupg->version, '2.2') > 0) { + $sig_params{user_id_string} = ''; + $sig_params{validity} = '?'; + } + else { + $sig_params{user_id_string} = 'Frank J. Tobin <ftobin@neverending.org>', + $sig_params{validity} = '!'; + } + return %sig_params +} + +1; diff --git a/t/UserId.t b/t/UserId.t new file mode 100644 index 0000000..1e8124c --- /dev/null +++ b/t/UserId.t @@ -0,0 +1,28 @@ +#!/usr/bin/perl -w +# +# $Id: UserId.t,v 1.1 2001/04/30 01:36:12 ftobin Exp $ +# + +use strict; + +use lib './t'; +use MyTest; +use GnuPG::UserId; + +my $v1 = 'Dekan'; +my $v2 = 'Frank Tobin'; + +my $user_id = GnuPG::UserId->new( as_string => $v1 ); + +# deprecation test +TEST +{ + $user_id->user_id_string() eq $v1; +}; + +# deprecation test +TEST +{ + $user_id->user_id_string( $v2 ); + $user_id->as_string() eq $v2; +}; diff --git a/t/clearsign.t b/t/clearsign.t new file mode 100644 index 0000000..8f27ebc --- /dev/null +++ b/t/clearsign.t @@ -0,0 +1,38 @@ +#!/usr/bin/perl -w +# +# $Id: clearsign.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->clearsign( handles => $handles ); + + print $stdin @{ $texts{plain}->data }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{plain}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + my $pid = $gnupg->clearsign( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/decrypt.t b/t/decrypt.t new file mode 100644 index 0000000..5bb35da --- /dev/null +++ b/t/decrypt.t @@ -0,0 +1,91 @@ +#!/usr/bin/perl -w +# +# $Id: decrypt.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); +use File::Compare; + +use lib './t'; +use MyTest; +use MyTestSpecific; + +my $compare; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->decrypt( handles => $handles ); + + print $stdin @{ $texts{encrypted}->data() }; + close $stdin; + + $compare = compare( $texts{plain}->fn(), $stdout ); + close $stdout; + waitpid $pid, 0; + + return $CHILD_ERROR == 0;; +}; + + +TEST +{ + return $compare == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{encrypted}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + + $handles->stdout( $texts{temp}->fh() ); + $handles->options( 'stdout' )->{direct} = 1; + + my $pid = $gnupg->decrypt( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + return compare( $texts{plain}->fn(), $texts{temp}->fn() ) == 0; +}; + + +# test without default_passphrase (that is, by using the agent, if ENV flag set) +TEST +{ + return 1 unless ($gnupg->cmp_version($gnupg->version, '2.2') >= 0); + + reset_handles(); + + $handles->stdin( $texts{alt_encrypted}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + + $handles->stdout( $texts{temp}->fh() ); + $handles->options( 'stdout' )->{direct} = 1; + + $handles->clear_passphrase(); + $gnupg->clear_passphrase(); + + my $pid = $gnupg->decrypt( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + return 1 unless ($gnupg->cmp_version($gnupg->version, '2.2') >= 0); + return compare( $texts{alt_plain}->fn(), $texts{temp}->fn() ) == 0; +}; diff --git a/t/detach_sign.t b/t/detach_sign.t new file mode 100644 index 0000000..f3bde63 --- /dev/null +++ b/t/detach_sign.t @@ -0,0 +1,38 @@ +#!/usr/bin/perl -w +# +# $Id: detach_sign.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->detach_sign( handles => $handles ); + + print $stdin @{ $texts{plain}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{plain}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + my $pid = $gnupg->detach_sign( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/encrypt.t b/t/encrypt.t new file mode 100644 index 0000000..e6bdc08 --- /dev/null +++ b/t/encrypt.t @@ -0,0 +1,76 @@ +#!/usr/bin/perl -w +# +# $Id: encrypt.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + my $pid = $gnupg->wrap_call( + handles => $handles, + commands => ['--update-trustdb'], + ); + waitpid $pid, 0; + return $CHILD_ERROR == 0; +}; + +TEST +{ + reset_handles(); + + $gnupg->options->clear_recipients(); + $gnupg->options->clear_meta_recipients_keys(); + $gnupg->options->push_recipients( '0x7466B7E98C4CCB64C2CE738BADB99D9C2E854A6B' ); + + my $pid = $gnupg->encrypt( handles => $handles ); + + print $stdin @{ $texts{plain}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + my @keys = $gnupg->get_public_keys( '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + $gnupg->options->clear_recipients(); + $gnupg->options->clear_meta_recipients_keys(); + $gnupg->options->push_meta_recipients_keys( @keys ); + + my $pid = $gnupg->encrypt( handles => $handles ); + + print $stdin @{ $texts{plain}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $gnupg->options->clear_recipients(); + $gnupg->options->clear_meta_recipients_keys(); + $gnupg->options->push_recipients( '0x7466B7E98C4CCB64C2CE738BADB99D9C2E854A6B' ); + + $handles->stdin( $texts{plain}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + my $pid = $gnupg->encrypt( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/encrypt_symmetrically.t b/t/encrypt_symmetrically.t new file mode 100644 index 0000000..61535ac --- /dev/null +++ b/t/encrypt_symmetrically.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w +# +# $Id: encrypt_symmetrically.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->encrypt_symmetrically( handles => $handles ); + + print $stdin @{ $texts{plain}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{plain}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + my $pid = $gnupg->encrypt_symmetrically( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/export_keys.t b/t/export_keys.t new file mode 100644 index 0000000..5add064 --- /dev/null +++ b/t/export_keys.t @@ -0,0 +1,37 @@ +#!/usr/bin/perl -w +# +# $Id: export_keys.t,v 1.6 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->export_keys( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdout( $texts{temp}->fh() ); + $handles->options( 'stdout' )->{direct} = 1; + + my $pid = $gnupg->export_keys( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + waitpid $pid, 0; + return $CHILD_ERROR == 0; +}; diff --git a/t/get_public_keys.t b/t/get_public_keys.t new file mode 100644 index 0000000..300c81c --- /dev/null +++ b/t/get_public_keys.t @@ -0,0 +1,257 @@ +#!/usr/bin/perl -w +# +# $Id: get_public_keys.t,v 1.9 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +use GnuPG::PrimaryKey; +use GnuPG::SubKey; + +my ( $given_key, $handmade_key ); + +TEST +{ + reset_handles(); + + my @returned_keys = $gnupg->get_public_keys_with_sigs( '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + + return 0 unless @returned_keys == 1; + + $given_key = shift @returned_keys; + + my $pubkey_data = [ + Math::BigInt->from_hex('0x'. + '88FCAAA5BCDCD52084D46143F44ED1715A339794641158DE03AA2092AFD3174E3DCA2CB7DF2DDC6FEDF7C3620F5A8BDAD06713E6153F8748DD76CB97305F30CBA8F8801DB47FAC11EED725F55672CB9BDAD629178A677CBB089B3E8AE0D9A9AD7741697A35F2868C62D25670994A92D810480173DC24263EEA0F103A43C0B64B'), + Math::BigInt->from_hex('0x'. + '8F2A3842C70FF17660CBB78C78FC93F534AB9A17'), + Math::BigInt->from_hex('0x'. + '83E348C2AA65F56DE84E8FDCE6DA7B0991B1C75EC8CA446FA85869A43350907BFF36BE512385E8E7E095578BB2138C04E318495873218286DE2B8C86F36EA670135434967AC798EBA28581F709F0C6B696EB512D3E561E381A06E4B5239BCC655015F9A926C74E4B859B26EAD604F208A556511A76A40EDCD9C38E6BD82CCCB4'), + Math::BigInt->from_hex('0x'. + '80DE04C85E30C9D62C13F90CFF927A84A5A59D0900B3533D4D6193FEF8C5DAEF9FF8A7D5F76B244FBC17644F50D524E0B19CD3A4B5FC2D78DAECA3FE58FA1C1A64E6C7B96C4EE618173543163A72EF954DFD593E84342699096E9CA76578AC1DE3D893BCCD0BF470CEF625FAF816A0F503EF75C18C6173E35C8675AF919E5704') + ]; + + $handmade_key = GnuPG::PrimaryKey->new + ( length => 1024, + algo_num => 17, + hex_id => '53AE596EF950DA9C', + creation_date => 949813093, + creation_date_string => '2000-02-06', + owner_trust => '-', + usage_flags => 'scaESCA', + pubkey_data => $pubkey_data, + ); + + $handmade_key->fingerprint + ( GnuPG::Fingerprint->new( as_hex_string => + '93AFC4B1B0288A104996B44253AE596EF950DA9C', + ) + ); + + + # Note, blank user_id_string and different validity for expired sig in GPG 2.2.x + my $uid0 = GnuPG::UserId->new( as_string => 'GnuPG test key (for testing purposes only)', + validity => '-'); + $uid0->push_signatures( + GnuPG::Signature->new( + date => 1177086597, + algo_num => 17, + is_exportable => 1, + user_id_string => 'GnuPG test key (for testing purposes only)', + date_string => '2007-04-20', + hex_id => '53AE596EF950DA9C', + sig_class => 0x13, + validity => '!'), + GnuPG::Signature->new( + get_expired_test_sig_params($gnupg), + date => 953180097, + ), + GnuPG::Signature->new( + date => 949813093, + algo_num => 17, + is_exportable => 1, + user_id_string => 'GnuPG test key (for testing purposes only)', + date_string => '2000-02-06', + hex_id => '53AE596EF950DA9C', + sig_class => 0x13, + validity => '!'), + GnuPG::Signature->new( + date => 1177086329, + algo_num => 17, + is_exportable => 1, + user_id_string => 'GnuPG test key (for testing purposes only)', + date_string => '2007-04-20', + hex_id => '53AE596EF950DA9C', + sig_class => 0x13, + validity => '!'), + ); + + # Note, blank user_id_string and different validity for expired sig in GPG 2.2.x + my $uid1 = GnuPG::UserId->new( as_string => 'Foo Bar (1)', + validity => '-'); + $uid1->push_signatures( + GnuPG::Signature->new( + date => 1177086330, + algo_num => 17, + is_exportable => 1, + user_id_string => 'GnuPG test key (for testing purposes only)', + date_string => '2007-04-20', + hex_id => '53AE596EF950DA9C', + sig_class => 0x13, + validity => '!'), + GnuPG::Signature->new( + get_expired_test_sig_params($gnupg), + date => 953180103, + ), + GnuPG::Signature->new( + date => 953179891, + algo_num => 17, + is_exportable => 1, + user_id_string => 'GnuPG test key (for testing purposes only)', + date_string => '2000-03-16', + hex_id => '53AE596EF950DA9C', + sig_class => 0x13, + validity => '!')); + + $handmade_key->push_user_ids($uid0, $uid1); + + my $subkey_signature = GnuPG::Signature->new + ( validity => '!', + algo_num => 17, + hex_id => '53AE596EF950DA9C', + date => 1177086380, + date_string => '2007-04-20', + user_id_string => 'GnuPG test key (for testing purposes only)', + sig_class => 0x18, + is_exportable => 1, + ); + + my $uid2_signature = GnuPG::Signature->new + ( validity => '!', + algo_num => 17, + hex_id => '53AE596EF950DA9C', + date => 953179891, + date_string => '2000-03-16', + ); + + my $ftobin_signature = GnuPG::Signature->new + ( validity => '!', + algo_num => 17, + hex_id => '56FFD10A260C4FA3', + date => 953180097, + date_string => '2000-03-16', + ); + + my $designated_revoker_sig = GnuPG::Signature->new + ( validity => '!', + algo_num => 17, + hex_id => '53AE596EF950DA9C', + date => 978325209, + date_string => '2001-01-01', + sig_class => 0x1f, + is_exportable => 1 + ); + + my $revoker = GnuPG::Revoker->new + ( algo_num => 17, + class => 0x80, + fingerprint => GnuPG::Fingerprint->new( as_hex_string => + '4F863BBBA8166F0A340F600356FFD10A260C4FA3'), + ); + $revoker->push_signatures($designated_revoker_sig); + + my $subkey_pub_data = [ + Math::BigInt->from_hex('0x'. + '8831982DADC4C5D05CBB01D9EAF612131DDC9C24CEA7246557679423FB0BA42F74D10D8E7F5564F6A4FB8837F8DC4A46571C19B122E6DF4B443D15197A6A22688863D0685FADB6E402316DAA9B560D1F915475364580A67E6DF0A727778A5CF3'), + Math::BigInt->from_hex('0x'. + '6'), + Math::BigInt->from_hex('0x'. + '2F3850FF130C6AC9AA0962720E86539626FAA9B67B33A74DFC0DE843FF3E90E43E2F379EE0182D914FA539CCCF5C83A20DB3A7C45E365B8A2A092E799A3DFF4AD8274EB977BAAF5B1AFB2ACB8D6F92454F01682F555565E73E56793C46EF7C3E') + ]; + + my $subkey = GnuPG::SubKey->new + ( validity => '-', + length => 768, + algo_num => 16, + hex_id => 'ADB99D9C2E854A6B', + creation_date => 949813119, + creation_date_string => '2000-02-06', + usage_flags => 'e', + pubkey_data => $subkey_pub_data, + ); + + + $subkey->fingerprint + ( GnuPG::Fingerprint->new( as_hex_string => + '7466B7E98C4CCB64C2CE738BADB99D9C2E854A6B' + ) + ); + + $subkey->push_signatures( $subkey_signature ); + + $handmade_key->push_subkeys( $subkey ); + $handmade_key->push_revokers( $revoker ); + + $handmade_key->compare( $given_key ); +}; + +TEST +{ + my $subkey1 = $given_key->subkeys()->[0]; + my $subkey2 = $handmade_key->subkeys()->[0]; + + bless $subkey1, 'GnuPG::SubKey'; + + my $equal = $subkey1->compare( $subkey2 ); + + warn 'subkeys fail comparison; this is a known issue with GnuPG 1.0.1' + if not $equal; + + return $equal; +}; + + +TEST +{ + # Some versions of GnuPG 2.2.x give same user_id and validity for expired sig as 1.4 + # this forces them to be consistent and still test them with 2.2 codepath + no warnings qw(redefine once); + local *GnuPG::Signature::compare = sub { + my ($self, $other) = @_; + if ($gnupg->cmp_version($gnupg->version, '2.2') > 0) { + if ( defined $self->user_id_string and + $self->user_id_string eq 'Frank J. Tobin <ftobin@neverending.org>') { + $self->user_id_string(''); + $self->validity('?'); + } + } + + my @compared_fields = qw( + validity + algo_num + hex_id + date + date_string + sig_class + is_exportable + ); + + foreach my $field ( @compared_fields ) { + return 0 unless $self->$field eq $other->$field; + } + # check for expiration if present? + return 0 unless (defined $self->expiration_date) == (defined $other->expiration_date); + if (defined $self->expiration_date) { + return 0 unless (($self->expiration_date == $other->expiration_date) || + ($self->expiration_date_string eq $other->expiration_date_string)); + } + return 1; + }; + + $handmade_key->compare( $given_key, 1 ); +}; diff --git a/t/get_secret_keys.t b/t/get_secret_keys.t new file mode 100644 index 0000000..5b4f97e --- /dev/null +++ b/t/get_secret_keys.t @@ -0,0 +1,117 @@ +#!/usr/bin/perl -w +# +# $Id: get_secret_keys.t,v 1.9 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +use GnuPG::PrimaryKey; + +my ( $given_key, $handmade_key ); + +TEST +{ + reset_handles(); + + my @returned_keys = $gnupg->get_secret_keys( '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + + return 0 unless @returned_keys == 1; + + $given_key = shift @returned_keys; + my $pubkey_data = [ + Math::BigInt->from_hex('0x'. + '88FCAAA5BCDCD52084D46143F44ED1715A339794641158DE03AA2092AFD3174E3DCA2CB7DF2DDC6FEDF7C3620F5A8BDAD06713E6153F8748DD76CB97305F30CBA8F8801DB47FAC11EED725F55672CB9BDAD629178A677CBB089B3E8AE0D9A9AD7741697A35F2868C62D25670994A92D810480173DC24263EEA0F103A43C0B64B'), + Math::BigInt->from_hex('0x'. + '8F2A3842C70FF17660CBB78C78FC93F534AB9A17'), + Math::BigInt->from_hex('0x'. + '83E348C2AA65F56DE84E8FDCE6DA7B0991B1C75EC8CA446FA85869A43350907BFF36BE512385E8E7E095578BB2138C04E318495873218286DE2B8C86F36EA670135434967AC798EBA28581F709F0C6B696EB512D3E561E381A06E4B5239BCC655015F9A926C74E4B859B26EAD604F208A556511A76A40EDCD9C38E6BD82CCCB4'), + Math::BigInt->from_hex('0x'. + '80DE04C85E30C9D62C13F90CFF927A84A5A59D0900B3533D4D6193FEF8C5DAEF9FF8A7D5F76B244FBC17644F50D524E0B19CD3A4B5FC2D78DAECA3FE58FA1C1A64E6C7B96C4EE618173543163A72EF954DFD593E84342699096E9CA76578AC1DE3D893BCCD0BF470CEF625FAF816A0F503EF75C18C6173E35C8675AF919E5704') + ]; + + + my $args = { + length => 1024, + algo_num => 17, + hex_id => '53AE596EF950DA9C', + creation_date => 949813093, + creation_date_string => '2000-02-06', + owner_trust => '-', + usage_flags => 'scaESCA', + pubkey_data => $pubkey_data, + }; + if ($gnupg->cmp_version($gnupg->version, '2.1') < 0) { + # older versions don't report ownertrust or pubkey_data for secret keys: + delete $args->{pubkey_data}; + $args->{owner_trust} = ''; + } + $handmade_key = GnuPG::PrimaryKey->new($args); + + $handmade_key->fingerprint + ( GnuPG::Fingerprint->new( as_hex_string => + '93AFC4B1B0288A104996B44253AE596EF950DA9C', + ) + ); + + $handmade_key->push_user_ids( + GnuPG::UserId->new( as_string => 'GnuPG test key (for testing purposes only)', + validity => $args->{owner_trust}), + GnuPG::UserId->new( as_string => 'Foo Bar (1)', + validity => $args->{owner_trust})); + + my $revoker = GnuPG::Revoker->new + ( algo_num => 17, + class => 0x80, + fingerprint => GnuPG::Fingerprint->new( as_hex_string => + '4F863BBBA8166F0A340F600356FFD10A260C4FA3'), + ); + + my $subkey_pub_data = [ + Math::BigInt->from_hex('0x'. + '8831982DADC4C5D05CBB01D9EAF612131DDC9C24CEA7246557679423FB0BA42F74D10D8E7F5564F6A4FB8837F8DC4A46571C19B122E6DF4B443D15197A6A22688863D0685FADB6E402316DAA9B560D1F915475364580A67E6DF0A727778A5CF3'), + Math::BigInt->from_hex('0x'. + '6'), + Math::BigInt->from_hex('0x'. + '2F3850FF130C6AC9AA0962720E86539626FAA9B67B33A74DFC0DE843FF3E90E43E2F379EE0182D914FA539CCCF5C83A20DB3A7C45E365B8A2A092E799A3DFF4AD8274EB977BAAF5B1AFB2ACB8D6F92454F01682F555565E73E56793C46EF7C3E') + ]; + + my $sub_args = { + validity => '-', + length => 768, + algo_num => 16, + hex_id => 'ADB99D9C2E854A6B', + creation_date => 949813119, + creation_date_string => '2000-02-06', + usage_flags => 'e', + pubkey_data => $subkey_pub_data, + }; + + if ($gnupg->cmp_version($gnupg->version, '2.1') < 0) { + # older versions do not report pubkey data for secret keys + delete $sub_args->{pubkey_data}; + } + my $subkey = GnuPG::SubKey->new($sub_args); + + $subkey->fingerprint + ( GnuPG::Fingerprint->new( as_hex_string => + '7466B7E98C4CCB64C2CE738BADB99D9C2E854A6B', + ) + ); + + $handmade_key->push_subkeys( $subkey ); + # older versions do not report designated revokers for secret keys + $handmade_key->push_revokers( $revoker ) if ($gnupg->cmp_version($gnupg->version, '2.1') >= 0); + + $handmade_key->compare( $given_key ); +}; + + +TEST +{ + $handmade_key->compare( $given_key, 1 ); +}; diff --git a/t/import_keys.t b/t/import_keys.t new file mode 100644 index 0000000..dc4a5a2 --- /dev/null +++ b/t/import_keys.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w +# +# $Id: import_keys.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->import_keys( handles => $handles ); + + print $stdin @{ $texts{key}->data() }; + close $stdin; + my @output = <$stdout>; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{key}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + + my $pid = $gnupg->import_keys( handles => $handles ); + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/list_public_keys.t b/t/list_public_keys.t new file mode 100644 index 0000000..622b092 --- /dev/null +++ b/t/list_public_keys.t @@ -0,0 +1,76 @@ +#!/usr/bin/perl -w +# +# $Id: list_public_keys.t,v 1.7 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); +use IO::File; + +use lib './t'; +use MyTest; +use MyTestSpecific; + +my $outfile; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->list_public_keys( handles => $handles ); + close $stdin; + + $outfile = 'test/public-keys/1.out'; + my $out = IO::File->new( "> $outfile" ) + or die "cannot open $outfile for writing: $ERRNO"; + $out->print( <$stdout> ); + close $stdout; + $out->close(); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + my $pid = $gnupg->list_public_keys( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' + ); + close $stdin; + + $outfile = 'test/public-keys/2.out'; + my $out = IO::File->new( "> $outfile" ) + or die "cannot open $outfile for writing: $ERRNO"; + $out->print( <$stdout> ); + close $stdout; + $out->close(); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + + +TEST +{ + reset_handles(); + + $handles->stdout( $texts{temp}->fh() ); + $handles->options( 'stdout' )->{direct} = 1; + + my $pid = $gnupg->list_public_keys( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C', + ); + + waitpid $pid, 0; + + $outfile = $texts{temp}->fn(); + + return $CHILD_ERROR == 0; +}; + diff --git a/t/list_secret_keys.t b/t/list_secret_keys.t new file mode 100644 index 0000000..13a7ae2 --- /dev/null +++ b/t/list_secret_keys.t @@ -0,0 +1,102 @@ +#!/usr/bin/perl -w +# +# $Id: list_secret_keys.t,v 1.7 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +my $outfile; + +TEST +{ + reset_handles(); + + $ENV{LC_MESSAGES} = 'C'; + my $pid = $gnupg->list_secret_keys( handles => $handles ); + close $stdin; + + $outfile = 'test/secret-keys/1.out'; + my $out = IO::File->new( "> $outfile" ) + or die "cannot open $outfile for writing: $ERRNO"; + my $seckey_file = $gnupg->cmp_version($gnupg->version, '2.1') >= 0 ? 'pubring.kbx' : 'secring.gpg'; + my $pubring_line = $gnupg->options->homedir() . '/' . $seckey_file . "\n"; + while (<$stdout>) { + if ($_ eq $pubring_line) { + $out->print('test/gnupghome/'.$seckey_file."\n"); + } elsif (/^--*$/) { + $out->print("--------------------------\n"); + } else { + $out->print( $_ ); + } + } + close $stdout; + $out->close(); + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + my $keylist; + if ($gnupg->cmp_version($gnupg->version, '2.1') < 0) { + $keylist = '0'; + } + else { + if ($gnupg->cmp_version($gnupg->version, '2.1.11') <= 0) { + $keylist = '1'; + } + else { + $keylist = '2'; + } + } + my @files_to_test = ( 'test/secret-keys/1.'.$keylist.'.test' ); + + return file_match( $outfile, @files_to_test ); +}; + + +TEST +{ + reset_handles(); + + my $pid = $gnupg->list_secret_keys( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + close $stdin; + + $outfile = 'test/secret-keys/2.out'; + my $out = IO::File->new( "> $outfile" ) + or die "cannot open $outfile for writing: $ERRNO"; + $out->print( <$stdout> ); + close $stdout; + $out->close(); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; + +}; + + +TEST +{ + reset_handles(); + + $handles->stdout( $texts{temp}->fh() ); + $handles->options( 'stdout' )->{direct} = 1; + + my $pid = $gnupg->list_secret_keys( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C' ); + + waitpid $pid, 0; + + $outfile = $texts{temp}->fn(); + + return $CHILD_ERROR == 0; +}; diff --git a/t/list_sigs.t b/t/list_sigs.t new file mode 100644 index 0000000..1301fb2 --- /dev/null +++ b/t/list_sigs.t @@ -0,0 +1,71 @@ +#!/usr/bin/perl -w +# +# $Id: list_sigs.t,v 1.7 2001/05/03 06:00:06 ftobin Exp $ + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +my $outfile; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->list_sigs( handles => $handles ); + close $stdin; + + $outfile = 'test/public-keys-sigs/1.out'; + my $out = IO::File->new( "> $outfile" ) + or die "cannot open $outfile for writing: $ERRNO"; + $out->print( <$stdout> ); + close $stdout; + $out->close(); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + my $pid = $gnupg->list_sigs( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C', + ); + close $stdin; + + $outfile = 'test/public-keys-sigs/2.out'; + my $out = IO::File->new( "> $outfile" ) + or die "cannot open $outfile for writing: $ERRNO"; + $out->print( <$stdout> ); + close $stdout; + $out->close(); + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdout( $texts{temp}->fh() ); + $handles->options( 'stdout' )->{direct} = 1; + + my $pid = $gnupg->list_sigs( handles => $handles, + command_args => '0x93AFC4B1B0288A104996B44253AE596EF950DA9C', + ); + + waitpid $pid, 0; + + $outfile = $texts{temp}->fn(); + + return $CHILD_ERROR == 0; +}; diff --git a/t/passphrase_handling.t b/t/passphrase_handling.t new file mode 100644 index 0000000..bfd0695 --- /dev/null +++ b/t/passphrase_handling.t @@ -0,0 +1,62 @@ +#!/usr/bin/perl -w +# +# $Id: passphrase_handling.t,v 1.6 2001/05/03 06:02:39 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); +use Symbol; +use IO::File; + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + return $gnupg->test_default_key_passphrase() +}; + + +$gnupg->clear_passphrase(); + +TEST +{ + reset_handles(); + + my $passphrase_handle = gensym; + $handles->passphrase( $passphrase_handle ); + + my $pid = $gnupg->sign( handles => $handles ); + + print $passphrase_handle 'test'; + print $stdin @{ $texts{plain}->data() }; + + close $passphrase_handle; + close $stdin; + + waitpid $pid, 0; + return $CHILD_ERROR == 0; +}; + + + +TEST +{ + reset_handles(); + $handles->clear_stderr(); + $handles->stderr( '>&STDERR' ); + + my $pass_fn = 'test/passphrase'; + my $passfile = IO::File->new( $pass_fn ) + or die "cannot open $pass_fn: $ERRNO"; + $handles->passphrase( $passfile ); + $handles->options( 'passphrase' )->{direct} = 1; + + my $pid = $gnupg->sign( handles => $handles ); + close $stdin; + + waitpid $pid, 0; + return $CHILD_ERROR == 0; +}; diff --git a/t/sign.t b/t/sign.t new file mode 100644 index 0000000..c854378 --- /dev/null +++ b/t/sign.t @@ -0,0 +1,38 @@ +#!/usr/bin/perl -w +# +# $Id: sign.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->sign( handles => $handles ); + + print $stdin @{ $texts{plain}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{plain}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + my $pid = $gnupg->sign( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/sign_and_encrypt.t b/t/sign_and_encrypt.t new file mode 100644 index 0000000..df0fc75 --- /dev/null +++ b/t/sign_and_encrypt.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w +# +# $Id: sign_and_encrypt.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + $gnupg->options->push_recipients( '0x7466B7E98C4CCB64C2CE738BADB99D9C2E854A6B' ); + my $pid = $gnupg->sign_and_encrypt( handles => $handles ); + + print $stdin @{ $texts{plain}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{plain}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + my $pid = $gnupg->sign_and_encrypt( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/verify.t b/t/verify.t new file mode 100644 index 0000000..bd5d0be --- /dev/null +++ b/t/verify.t @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w +# +# $Id: verify.t,v 1.4 2001/05/03 06:00:06 ftobin Exp $ +# + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->verify( handles => $handles ); + + print $stdin @{ $texts{signed}->data() }; + close $stdin; + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + + +TEST +{ + reset_handles(); + + $handles->stdin( $texts{signed}->fh() ); + $handles->options( 'stdin' )->{direct} = 1; + + my $pid = $gnupg->verify( handles => $handles ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/version_updates.t b/t/version_updates.t new file mode 100644 index 0000000..758ee7b --- /dev/null +++ b/t/version_updates.t @@ -0,0 +1,30 @@ +#!/usr/bin/perl -w + +use strict; + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + my $gpg = GnuPG::Interface->new(call => './test/fake-gpg-v1'); + return ($gpg->version() eq '1.4.23'); +}; + + +TEST +{ + my $gpg = GnuPG::Interface->new(call => './test/fake-gpg-v2'); + return ($gpg->version() eq '2.2.12'); +}; + +TEST +{ + my $gpg = GnuPG::Interface->new(call => './test/fake-gpg-v1'); + my $v1 = $gpg->version(); + $gpg->call('./test/fake-gpg-v2'); + my $v2 = $gpg->version(); + + return ($v1 eq '1.4.23' && $v2 eq '2.2.12'); +} diff --git a/t/wrap_call.t b/t/wrap_call.t new file mode 100644 index 0000000..8677d54 --- /dev/null +++ b/t/wrap_call.t @@ -0,0 +1,59 @@ +#!/usr/bin/perl -w +# +# $Id: wrap_call.t,v 1.1 2001/05/03 07:32:34 ftobin Exp $ +# + +use strict; + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->wrap_call + ( commands => [ qw( --list-packets ) ], + command_args => [ qw( test/key.1.asc ) ], + handles => $handles, + ); + + close $stdin; + + my @out = <$stdout>; + waitpid $pid, 0; + + return @out > 0; #just check if we have output. +}; + +TEST +{ + return $CHILD_ERROR == 0; +}; + + +# same as above, but now with deprecated stuff +TEST +{ + reset_handles(); + + my $pid = $gnupg->wrap_call + ( gnupg_commands => [ qw( --list-packets ) ], + gnupg_command_args => [ qw( test/key.1.asc ) ], + handles => $handles, + ); + + close $stdin; + + my @out = <$stdout>; + waitpid $pid, 0; + + return @out > 0; #just check if we have output. +}; + + +TEST +{ + return $CHILD_ERROR == 0; +}; diff --git a/t/z_delete_keys.t b/t/z_delete_keys.t new file mode 100644 index 0000000..b5d1215 --- /dev/null +++ b/t/z_delete_keys.t @@ -0,0 +1,51 @@ +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->wrap_call( + gnupg_commands => [qw( --delete-secret-keys )], + gnupg_command_args => [qw( 0x93AFC4B1B0288A104996B44253AE596EF950DA9C )], + handles => $handles, + ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->wrap_call( + gnupg_commands => [qw( --delete-keys )], + gnupg_command_args => [qw( 0x93AFC4B1B0288A104996B44253AE596EF950DA9C )], + handles => $handles, + ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; + +TEST +{ + reset_handles(); + + my $pid = $gnupg->wrap_call( + gnupg_commands => [qw( --delete-secret-and-public-keys )], + gnupg_command_args => [qw( 278F850AA702911F1318F0A61B913CE9B6747DDC )], + handles => $handles, + ); + + waitpid $pid, 0; + + return $CHILD_ERROR == 0; +}; diff --git a/t/zzz_cleanup.t b/t/zzz_cleanup.t new file mode 100644 index 0000000..9c4d806 --- /dev/null +++ b/t/zzz_cleanup.t @@ -0,0 +1,27 @@ +#!/usr/bin/perl -w + +use strict; +use English qw( -no_match_vars ); + +use lib './t'; +use MyTest; +use MyTestSpecific; +use File::Path qw (remove_tree); + +# this is actually no test, just cleanup. +TEST +{ + my $homedir = $gnupg->options->homedir(); + my $err = []; + # kill off any long-lived gpg-agent, ignoring errors. + # gpgconf versions < 2.1.11 do not support '--homedir', but still + # respect the GNUPGHOME environment variable + if ($gnupg->cmp_version($gnupg->version, '2.1') >= 0) { + $ENV{'GNUPGHOME'} = $homedir; + system('gpgconf', '--homedir', $homedir, '--quiet', '--kill', 'gpg-agent'); + delete $ENV{'GNUPGHOME'}; + } + remove_tree($homedir, {error => \$err}); + unlink('test/gnupghome'); + return ! @$err; +}; |