Commit fa539bd6 authored by sikeda's avatar sikeda
Browse files

[-dev] Skip some tests when openssl is not installed.

git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@11284 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 5d737686
......@@ -11,10 +11,20 @@ use MIME::Parser;
use Test::More;
#use Sympa::Tools::File;
use tools; # Sympa::Tools::SMIME;
use tools; # Sympa::Tools::SMIME;
use Conf;
$Conf::Conf{'openssl'} = 'openssl';
delete $Conf::Conf{'openssl'};
foreach my $path (
split(/:/, $ENV{PATH} || ''),
qw(/usr/local/bin /usr/local/ssl/bin /opt/local/bin /usr/sfw/bin /usr/bin)
) {
my $openssl = $path . '/openssl';
if (-x $openssl) {
$Conf::Conf{'openssl'} = $openssl;
last;
}
}
$Conf::Conf{'tmpdir'} = '/tmp';
plan tests => 19;
......@@ -29,33 +39,24 @@ $Conf::Conf{'home'} = $home_dir;
my $cert_dir = $home_dir . '/sympa';
mkdir $cert_dir;
ok(
!tools::smime_find_keys('*', 'sign'),
'empty directory'
);
ok(!tools::smime_find_keys('*', 'sign'), 'empty directory');
my $generic_cert_file = $cert_dir . '/cert.pem';
my $generic_key_file = $cert_dir . '/private_key';
my $generic_cert_file = $cert_dir . '/cert.pem';
my $generic_key_file = $cert_dir . '/private_key';
my $encryption_cert_file = $cert_dir . '/cert.pem.enc';
my $encryption_key_file = $cert_dir . '/private_key.enc';
my $signature_cert_file = $cert_dir . '/cert.pem.sign';
my $signature_key_file = $cert_dir . '/private_key.sign';
my $encryption_key_file = $cert_dir . '/private_key.enc';
my $signature_cert_file = $cert_dir . '/cert.pem.sign';
my $signature_key_file = $cert_dir . '/private_key.sign';
touch($generic_cert_file);
ok(
!tools::smime_find_keys('*', 'sign'),
'directory with certificate only'
);
ok(!tools::smime_find_keys('*', 'sign'), 'directory with certificate only');
unlink($generic_cert_file);
touch($generic_key_file);
ok(
!tools::smime_find_keys('*', 'sign'),
'directory with key only'
);
ok(!tools::smime_find_keys('*', 'sign'), 'directory with key only');
unlink($generic_key_file);
......@@ -63,20 +64,20 @@ touch($generic_cert_file);
touch($generic_key_file);
is_deeply(
[ tools::smime_find_keys('*', 'sign') ],
[ $generic_cert_file, $generic_key_file ],
[tools::smime_find_keys('*', 'sign')],
[$generic_cert_file, $generic_key_file],
'directory with generic key/certificate only, signature operation'
);
is_deeply(
[ tools::smime_find_keys('*', 'encrypt') ],
[ $generic_cert_file, $generic_key_file ],
[tools::smime_find_keys('*', 'encrypt')],
[$generic_cert_file, $generic_key_file],
'directory with generic key/certificate only, encryption operation'
);
is_deeply(
[ tools::smime_find_keys('*', 'decrypt') ],
[ [ $generic_cert_file ], [ $generic_key_file ] ],
[tools::smime_find_keys('*', 'decrypt')],
[[$generic_cert_file], [$generic_key_file]],
'directory with generic key/certificate only, decryption operation'
);
......@@ -86,121 +87,119 @@ touch($encryption_cert_file);
touch($encryption_key_file);
is_deeply(
[ tools::smime_find_keys('*', 'sign') ],
[ $signature_cert_file, $signature_key_file ],
[tools::smime_find_keys('*', 'sign')],
[$signature_cert_file, $signature_key_file],
'directory with dedicated key/certificates, signature operation'
);
is_deeply(
[ tools::smime_find_keys('*', 'encrypt') ],
[ $encryption_cert_file, $encryption_key_file ],
[tools::smime_find_keys('*', 'encrypt')],
[$encryption_cert_file, $encryption_key_file],
'directory with dedicated key/certificates, encryption operation'
);
is_deeply(
[ tools::smime_find_keys('*', 'decrypt') ],
[
[ $generic_cert_file, $encryption_cert_file, $signature_cert_file ],
[ $generic_key_file, $encryption_key_file, $signature_key_file ],
[tools::smime_find_keys('*', 'decrypt')],
[ [$generic_cert_file, $encryption_cert_file, $signature_cert_file],
[$generic_key_file, $encryption_key_file, $signature_key_file],
],
'directory with dedicated key/certificates, decryption operation'
);
ok(
!tools::smime_parse_cert(),
'neither text nor file given',
);
ok(!tools::smime_parse_cert(), 'neither text nor file given',);
ok(
!tools::smime_parse_cert(file => '/no/where'),
'non-existing file',
);
ok(!tools::smime_parse_cert(file => '/no/where'), 'non-existing file',);
ok(
!tools::smime_parse_cert(text => ''),
'empty string',
);
ok(!tools::smime_parse_cert(text => ''), 'empty string',);
my $cert_file = 't/pki/crt/rousse.pem';
my $cert_file = 't/pki/crt/rousse.pem';
#my $cert_string = Sympa::Tools::File::slurp_file($cert_file);
my $cert_string = do { local (@ARGV, $/) = $cert_file; <> };
my $cert_data = {
my $cert_data = {
purpose => {
sign => 1,
enc => 1
},
subject => '/O=sympa developpers/OU=unit testing/CN=Guillaume Rousse/emailAddress=Guillaume.Rousse@sympa.org',
email => {
'guillaume.rousse@sympa.org' => 1
}
subject =>
'/O=sympa developpers/OU=unit testing/CN=Guillaume Rousse/emailAddress=Guillaume.Rousse@sympa.org',
email => {'guillaume.rousse@sympa.org' => 1}
};
is_deeply(
tools::smime_parse_cert(
file => $cert_file,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$cert_data,
'user certificate file parsing'
);
is_deeply(
tools::smime_parse_cert(
text => $cert_string,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$cert_data,
'user certificate string parsing'
);
SKIP: {
skip 'openssl is not supported', 2 unless $Conf::Conf{'openssl'};
is_deeply(
tools::smime_parse_cert(
file => $cert_file,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$cert_data,
'user certificate file parsing'
);
is_deeply(
tools::smime_parse_cert(
text => $cert_string,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$cert_data,
'user certificate string parsing'
);
}
my $ca_cert_file = 't/pki/crt/ca.pem';
my $ca_cert_data = {
subject => '/O=sympa developpers/OU=unit testing/CN=Test CA/emailAddress=test@sympa.org',
email => {
'test@sympa.org' => 1
},
my $ca_cert_file = 't/pki/crt/ca.pem';
my $ca_cert_data = {
subject =>
'/O=sympa developpers/OU=unit testing/CN=Test CA/emailAddress=test@sympa.org',
email => {'test@sympa.org' => 1},
purpose => {
sign => '',
enc => ''
},
};
is_deeply(
tools::smime_parse_cert(
file => $ca_cert_file,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$ca_cert_data,
'CA certificate file parsing'
);
SKIP: {
skip 'openssl is not supported', 1 unless $Conf::Conf{'openssl'};
is_deeply(
tools::smime_parse_cert(
file => $ca_cert_file,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$ca_cert_data,
'CA certificate file parsing'
);
}
my $parser = MIME::Parser->new();
my $entity = $parser->parse_open('t/samples/signed.eml');
my $parser = MIME::Parser->new();
my $entity = $parser->parse_open('t/samples/signed.eml');
my $out_file = $cert_dir . '/out';
ok(
!tools::smime_extract_certs($entity->parts(0), $out_file, 'openssl'),
"certificate extraction from text part doesn't work"
);
ok(
tools::smime_extract_certs($entity->parts(1), $out_file, 'openssl'),
"certificate extraction from signature part does work"
);
ok(-f $out_file, 'certificate extraction file exists');
is_deeply(
tools::smime_parse_cert(
file => $out_file,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$cert_data,
'certificate extraction file has expected content'
);
SKIP: {
skip 'openssl not supported', 4 unless $Conf::Conf{'openssl'};
ok( !tools::smime_extract_certs($entity->parts(0), $out_file, 'openssl'),
"certificate extraction from text part doesn't work"
);
ok( tools::smime_extract_certs($entity->parts(1), $out_file, 'openssl'),
"certificate extraction from signature part does work"
);
ok(-f $out_file, 'certificate extraction file exists');
is_deeply(
tools::smime_parse_cert(
file => $out_file,
#tmpdir => $ENV{TMP},
#openssl => 'openssl'
),
$cert_data,
'certificate extraction file has expected content'
);
}
sub touch {
my ($file) = @_;
open (my $fh, '>', $file) or die "Can't create file: $ERRNO";
open(my $fh, '>', $file) or die "Can't create file: $ERRNO";
close $fh;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment