Mail-SpamCannibal

 view release on metacpan or  search on metacpan

t/gp_decrypt.t  view on Meta::CPAN

############## expected  #################################
|, $original, q|
################# end ####################################\nnot |
	if !$plaintext || $plaintext ne $original;
  &ok;
}

sub dotests {
  my $pgpexe = shift;
## test 2 -- check decrypt with hash

  my %hash = (
	Data	  => $crypted,
	ExeFile	  => $pgpexe,
	KeyPath	  => './keyrings',
	Password  => 'TEST',
#	UserID	  => 'E56C91B9',
	Version	  => '2.62',
  );

  $plaintext = decrypt(%hash);
  checkoutput;

## test 3 -- repeat above with hash reference
  undef $plaintext;	# (skeptic :-)
  $plaintext = decrypt(\%hash);
  checkoutput;

## test 4 -- repeat above with named userid
  undef $plaintext;	# (skeptic :-)
  $hash{UserID} = 'test';
  $plaintext = decrypt(\%hash);
  checkoutput;

## test 5 -- repeat above with keyid
  undef $plaintext;	# (skeptic :-)
  $hash{UserID} = 'E56C91B9';
  $plaintext = decrypt(\%hash);
  checkoutput;

## test 6 -- check null return for broken decrypt
  $hash{Data} = $broken;
  my $rv = decrypt(\%hash);
  print q|instead of '', found text below
##########################################################
|, $rv, q|
##########################################################\nnot |
	if $rv;
&ok;

}

##########################################################
####### The test really begin here #######################


do './executableTestPath.conf';
my @pgpexe = &privacyexecutables;

my $pgpexe;
foreach my $try (qw(pgp gpg)) {
  $pgpexe = $try;
  foreach(@pgpexe) {
    if ($_ =~ m|/${try}[^/]*$|) {
      $pgpexe = $_;
      last;
    }
  }

  if ($pgpexe =~ m|/| && -e $pgpexe && -x $pgpexe) {
    if ($pgpexe =~ m|/gpg|) {
      local $/;
      open(VERSION,"$pgpexe --version|");
      $_ = <VERSION>;
      close VERSION;
      if ($_ =~ /IDEA/) {
        &dotests($pgpexe);
      } else {
	&skip(5);
	print STDERR qq
|	Tests for '$pgpexe' have been skipped. The
	IDEA plugin is required to run this test. See: the man
	page for Mail::SpamCannibal::GoodPrivacy about GnuPG.

|;
      }
    } else {
    &dotests($pgpexe);
    }
  } else {
    &skip(5);
    print STDERR qq
|	Tests for '$pgpexe' have been skipped. If you need to
	install '$pgpexe' on your system, do so, then edit file 
	'executableTestPath.conf' to include '/path/to/executable'

|;
  }
}



( run in 0.528 second using v1.01-cache-2.11-cpan-df04353d9ac )