]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/yubikey.t
10 use File
::KDBX
::Key
::YubiKey
;
13 @ENV{qw(YKCHALRESP YKCHALRESP_FLAGS)} = ($Config{perlpath
}, testfile
(qw{bin ykchalresp}));
14 @ENV{qw(YKINFO YKINFO_FLAGS)} = ($Config{perlpath
}, testfile
(qw{bin ykinfo}));
18 my $key = File
::KDBX
::Key
::YubiKey-
>new(
19 pre_challenge
=> sub { ++$pre },
20 post_challenge
=> sub { ++$post },
23 is exception
{ $resp = $key->challenge('foo') }, undef, 'Do not throw during non-blocking response';
24 is $resp, "\xf0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 'Get a non-blocking challenge response';
25 is length($resp), 20, 'Response is the proper length';
26 is $pre, 1, 'The pre-challenge callback is called';
27 is $post, 1, 'The post-challenge callback is called';
31 my $key = File
::KDBX
::Key
::YubiKey-
>new;
32 local $ENV{YKCHALRESP_MOCK
} = 'error';
33 like exception
{ $key->challenge('foo') }, qr/Yubikey core error:/i,
34 'Throw if challenge-response program errored out';
38 my $key = File
::KDBX
::Key
::YubiKey-
>new;
39 local $ENV{YKCHALRESP_MOCK
} = 'usberror';
40 like exception
{ $key->challenge('foo') }, qr/USB error:/i,
41 'Throw if challenge-response program had a USB error';
45 my $key = File
::KDBX
::Key
::YubiKey-
>new(timeout
=> 0, device
=> 3, slot
=> 2);
46 local $ENV{YKCHALRESP_MOCK
} = 'block';
48 like exception
{ $key->challenge('foo') }, qr/operation would block/i,
49 'Throw if challenge would block but we do not want to wait';
52 like exception
{ $key->challenge('foo') }, qr/timed out/i,
53 'Timed out while waiting for response';
57 is exception
{ $resp = $key->challenge('foo') }, undef,
58 'Do not throw during blocking response';
59 is $resp, "\xf0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 'Get a blocking challenge response';
63 my $key = File
::KDBX
::Key
::YubiKey-
>new(device
=> 0, slot
=> 1);
64 is $key->name, 'YubiKey NEO FIDO v2.0.0 [123] (slot #1)',
65 'Get name for a new, unscanned key';
66 is $key->serial, 123, 'We have the serial number of the new key';
70 my ($key, @other) = File
::KDBX
::Key
::YubiKey-
>scan;
71 is $key->name, 'YubiKey 4/5 OTP v3.0.1 [456] (slot #2)',
72 'Find expected YubiKey';
73 is $key->serial, 456, 'We have the serial number of the scanned key';
74 is scalar @other, 0, 'Do not find any other YubiKeys';
78 local $ENV{YKCHALRESP
} = testfile
(qw{bin nonexistent});
79 local $ENV{YKCHALRESP_FLAGS
} = undef;
80 my $key = File
::KDBX
::Key
::YubiKey-
>new;
81 like exception
{ $key->challenge('foo') }, qr/failed to run|failed to receive challenge response/i,
82 'Throw if the program failed to run';
This page took 0.042665 seconds and 5 git commands to generate.