2006-03-27 02:57:24 +02:00
|
|
|
# ===========================================================================
|
|
|
|
# test.pl - version 0.02 - 25/09/2000
|
|
|
|
# $Id: test.pl,v 1.5 2005/03/05 14:08:30 guy Exp $
|
|
|
|
# Test suite for Mail::Ezmlm
|
|
|
|
#
|
2006-04-19 01:52:16 +02:00
|
|
|
# Copyright (C) 02006, Lars Kruse, All Rights Reserved.
|
|
|
|
# Please send bug reports and comments to devel@sumpfralle.de
|
2006-03-27 02:57:24 +02:00
|
|
|
#
|
|
|
|
# This program is subject to the restrictions set out in the copyright
|
2006-04-19 01:52:16 +02:00
|
|
|
# agreement that can be found in the Gpg.pm file in this distribution
|
2006-03-27 02:57:24 +02:00
|
|
|
#
|
|
|
|
# ==========================================================================
|
|
|
|
# Before `make install' is performed this script should be runnable with
|
|
|
|
# `make test'. After `make install' it should work as `perl test.pl'
|
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
use Test;
|
2006-04-19 02:45:18 +02:00
|
|
|
use strict;
|
|
|
|
|
|
|
|
BEGIN { plan tests => 13 }
|
2006-03-27 02:57:24 +02:00
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print "Trying to load the Mail::Ezmlm module: ";
|
|
|
|
eval { require Mail::Ezmlm; return 1;};
|
|
|
|
ok($@,'');
|
|
|
|
croak() if $@; # If Mail::Ezmlm didn't load... bail hard now
|
|
|
|
|
|
|
|
print "Trying to load the Mail::Ezmlm::Gpg module: ";
|
2006-04-19 02:45:18 +02:00
|
|
|
eval { require "Gpg.pm"; return 1;};
|
2006-04-19 01:52:16 +02:00
|
|
|
ok($@,'');
|
|
|
|
croak() if $@; # Mail::Ezmlm::Gpg is essential ...
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 02:45:18 +02:00
|
|
|
print "Checking version of gpg-ezmlm: ";
|
|
|
|
my $version_check = Mail::Ezmlm::Gpg->check_gpg_ezmlm_version();
|
|
|
|
ok($version_check);
|
|
|
|
croak() unless ($version_check); # the version of gpg-ezmlm is important
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
use Cwd;
|
2006-04-19 02:45:18 +02:00
|
|
|
my $list = new Mail::Ezmlm;
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
# create a temp directory if necessary
|
2006-04-19 02:45:18 +02:00
|
|
|
my $TMP = cwd() . '/gpg-ezmlmtmp';
|
2006-03-27 02:57:24 +02:00
|
|
|
mkdir $TMP, 0755 unless (-d $TMP);
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Checking list creation with Mail::Ezmlm: ';
|
2006-04-19 02:45:18 +02:00
|
|
|
my $test1 = $list->make(-name=>"ezmlm-test1-$$",
|
2006-03-27 02:57:24 +02:00
|
|
|
-qmail=>"$TMP/.qmail-ezmlm-test1-$$",
|
|
|
|
-dir=>"$TMP/ezmlm-test1-$$");
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
ok($test1 eq "$TMP/ezmlm-test1-$$");
|
2006-03-27 02:57:24 +02:00
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
# backup the created to list to check clean conversion later
|
|
|
|
system("cp", "-a", $list->{'LIST_NAME'}, $list->{'LIST_NAME'} . ".backup");
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing list conversion from plaintext to encryption: ';
|
2006-04-19 02:45:18 +02:00
|
|
|
my $gpg_list = new Mail::Ezmlm::Gpg($list->{'LIST_NAME'});
|
2006-04-19 01:52:16 +02:00
|
|
|
ok($gpg_list->convert_to_encrypted() && $gpg_list->is_gpg());
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing list conversion from encryption to plaintext: ';
|
|
|
|
ok($gpg_list->convert_to_plaintext() && !($gpg_list->is_gpg()));
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing if back and forth conversion was clean: ';
|
|
|
|
ok(system("diff -qr --exclude=.gnupg --exclude=tmp --exclude=text '" . $list->{'LIST_NAME'} . "' '" . $list->{'LIST_NAME'} . '.backup' . "' 2>/dev/null") == 0);
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing getconfig: ';
|
|
|
|
$gpg_list->convert_to_encrypted();
|
|
|
|
ok($gpg_list->getconfig());
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing update: ';
|
|
|
|
# toggle a setting and check, if it works
|
|
|
|
$gpg_list->update((requireSigs => 1));
|
|
|
|
my %list_config = $gpg_list->getconfig();
|
|
|
|
my $update_failed = ($list_config{requireSigs} == 1)? 0 : 1;
|
|
|
|
unless ($update_failed) {
|
|
|
|
$gpg_list->update((requireSigs => 0));
|
|
|
|
%list_config = $gpg_list->getconfig();
|
|
|
|
$update_failed = ($list_config{requireSigs} == 0)? 0 : 1;
|
2006-03-27 02:57:24 +02:00
|
|
|
}
|
2006-04-19 01:52:16 +02:00
|
|
|
ok(!$update_failed);
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing key generation: ';
|
2006-04-19 02:45:18 +02:00
|
|
|
ok($gpg_list->generate_private_key('Name', 'Comment', 'mail@addr.ess', 1024, 0));
|
2006-03-27 02:57:24 +02:00
|
|
|
|
|
|
|
|
2006-04-19 01:52:16 +02:00
|
|
|
print 'Testing key retrieval: ';
|
|
|
|
my @pub_keys = $gpg_list->get_public_keys();
|
|
|
|
my @sec_keys = $gpg_list->get_secret_keys();
|
|
|
|
ok((@pub_keys == 1) && (@sec_keys == 1));
|
|
|
|
|
|
|
|
|
|
|
|
print 'Testing key export: ';
|
|
|
|
my $keyid = $pub_keys[0]{id};
|
2006-04-19 02:45:18 +02:00
|
|
|
ok($keyid && $gpg_list->export_key($keyid));
|
2006-04-19 01:52:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
print 'Testing key deletion: ';
|
|
|
|
$gpg_list->delete_key($keyid);
|
|
|
|
@pub_keys = $gpg_list->get_public_keys();
|
|
|
|
@sec_keys = $gpg_list->get_secret_keys();
|
|
|
|
ok((@pub_keys == 0) && (@sec_keys == 0));
|
|
|
|
|