]>
Dogcows Code - chaz/p5-File-KDBX/blob - t/yubikey.t
11 BEGIN { use_ok
'File::KDBX::Key::YubiKey' }
13 local $ENV{YKCHALRESP
} = testfile
(qw{bin ykchalresp});
14 local $ENV{YKINFO
} = 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,
24 'Do not throw during non-blocking response';
25 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';
26 is length($resp), 20, 'Response is the proper length';
27 is $pre, 1, 'The pre-challenge callback is called';
28 is $post, 1, 'The post-challenge callback is called';
32 my $key = File
::KDBX
::Key
::YubiKey-
>new;
33 local $ENV{YKCHALRESP_MOCK
} = 'error';
34 like exception
{ $key->challenge('foo') }, qr/Yubikey core error:/i,
35 'Throw if challenge-response program errored out';
39 my $key = File
::KDBX
::Key
::YubiKey-
>new;
40 local $ENV{YKCHALRESP_MOCK
} = 'usberror';
41 like exception
{ $key->challenge('foo') }, qr/USB error:/i,
42 'Throw if challenge-response program had a USB error';
46 my $key = File
::KDBX
::Key
::YubiKey-
>new(timeout
=> 0, device
=> 3, slot
=> 2);
47 local $ENV{YKCHALRESP_MOCK
} = 'block';
49 like exception
{ $key->challenge('foo') }, qr/operation would block/i,
50 'Throw if challenge would block but we do not want to wait';
53 like exception
{ $key->challenge('foo') }, qr/timed out/i,
54 'Timed out while waiting for response';
58 is exception
{ $resp = $key->challenge('foo') }, undef,
59 'Do not throw during blocking response';
60 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';
64 my $key = File
::KDBX
::Key
::YubiKey-
>new(device
=> 0, slot
=> 1);
65 is $key->name, 'YubiKey NEO FIDO v2.0.0 [123] (slot #1)',
66 'Get name for a new, unscanned key';
67 is $key->serial, 123, 'We have the serial number of the new key';
71 my ($key, @other) = File
::KDBX
::Key
::YubiKey-
>scan;
72 is $key->name, 'YubiKey 4/5 OTP v3.0.1 [456] (slot #2)',
73 'Find expected YubiKey';
74 is $key->serial, 456, 'We have the serial number of the scanned key';
75 is scalar @other, 0, 'Do not find any other YubiKeys';
79 local $ENV{YKCHALRESP
} = testfile
(qw{bin nonexistent});
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.039687 seconds and 4 git commands to generate.