Crypt-PKCS11-Easy
view release on metacpan or search on metacpan
t/02-basic.t view on Meta::CPAN
use lib 't/lib';
use Test::Roo;
use Test::Fatal;
use Path::Tiny;
with 'CommonTest';
sub BUILD {
my $self = shift;
if (!$self->has_softhsm2) {
plan skip_all => 'SoftHSM2 is required to run these tests';
}
}
test info => sub {
my $self = shift;
ok my $info = $self->pkcs11->get_info;
isa_ok $info, 'HASH';
is_deeply [sort keys %$info],
[qw/cryptokiVersion libraryDescription libraryVersion manufacturerID/],
'Keys are as expected';
is $info->{manufacturerID}, 'SoftHSM', 'Correct manufacturerID';
};
test slots => sub {
my $self = shift;
ok my $slots = $self->pkcs11->get_slots;
isa_ok $slots, 'ARRAY';
is scalar @$slots, 2, 'softhsm always has at least one token';
$self->clear_pkcs11;
ok $slots = $self->pkcs11->get_slots;
isa_ok $slots, 'ARRAY';
is scalar @$slots, 2, 'There are now two tokens';
like(
exception { $self->pkcs11->get_slot(label => 'test_keys_1') },
qr/Missing id or token/,
'Failed to find slot using invalid args',
);
like(
exception { $self->pkcs11->get_slot(token => 'nosuchtoken') },
qr/Unable to find slot containing token labelled/,
'Failed to find slot using invalid args',
);
my $slot;
is(
exception { $slot = $self->pkcs11->get_slot(token => 'test_keys_1') },
undef,
'Found token by label',
);
my $slot2;
is(
( run in 1.474 second using v1.01-cache-2.11-cpan-54e63673c56 )