X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=t%2Fyubikey.t;h=b325b25e262f9d0caf8582183713678d982290ce;hb=b30990a507ef30b6f5b6fcb799a2759632c77ff0;hp=1ec1ed41223e5d4020ab2fb5208a02304e56dddc;hpb=f63182fc62b25269b1c38588dca2b3535ed1a1a2;p=chaz%2Fp5-File-KDBX diff --git a/t/yubikey.t b/t/yubikey.t index 1ec1ed4..b325b25 100644 --- a/t/yubikey.t +++ b/t/yubikey.t @@ -6,12 +6,14 @@ use strict; use lib 't/lib'; use TestCommon; +use Config; +use File::KDBX::Key::YubiKey; use Test::More; -BEGIN { use_ok 'File::KDBX::Key::YubiKey' } +$^O eq 'MSWin32' and plan skip_all => 'Non-Windows required to test YubiKeys'; -local $ENV{YKCHALRESP} = testfile(qw{bin ykchalresp}); -local $ENV{YKINFO} = testfile(qw{bin ykinfo}); +@ENV{qw(YKCHALRESP YKCHALRESP_FLAGS)} = ($Config{perlpath}, testfile(qw{bin ykchalresp})); +@ENV{qw(YKINFO YKINFO_FLAGS)} = ($Config{perlpath}, testfile(qw{bin ykinfo})); { my ($pre, $post); @@ -20,8 +22,7 @@ local $ENV{YKINFO} = testfile(qw{bin ykinfo}); post_challenge => sub { ++$post }, ); my $resp; - is exception { $resp = $key->challenge('foo') }, undef, - 'Do not throw during non-blocking response'; + is exception { $resp = $key->challenge('foo') }, undef, 'Do not throw during non-blocking response'; 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'; is length($resp), 20, 'Response is the proper length'; is $pre, 1, 'The pre-challenge callback is called'; @@ -51,7 +52,7 @@ local $ENV{YKINFO} = testfile(qw{bin ykinfo}); $key->timeout(1); like exception { $key->challenge('foo') }, qr/timed out/i, - 'Timed out while waiting for response'; + 'Timeout while waiting for response'; $key->timeout(-1); my $resp; @@ -64,19 +65,20 @@ local $ENV{YKINFO} = testfile(qw{bin ykinfo}); my $key = File::KDBX::Key::YubiKey->new(device => 0, slot => 1); is $key->name, 'YubiKey NEO FIDO v2.0.0 [123] (slot #1)', 'Get name for a new, unscanned key'; - is $key->serial, 123, 'We have the serial number of the new key'; + is $key->serial, 123, 'Get the serial number of the new key'; } { my ($key, @other) = File::KDBX::Key::YubiKey->scan; is $key->name, 'YubiKey 4/5 OTP v3.0.1 [456] (slot #2)', 'Find expected YubiKey'; - is $key->serial, 456, 'We have the serial number of the scanned key'; + is $key->serial, 456, 'Get the serial number of the scanned key'; is scalar @other, 0, 'Do not find any other YubiKeys'; } { local $ENV{YKCHALRESP} = testfile(qw{bin nonexistent}); + local $ENV{YKCHALRESP_FLAGS} = undef; my $key = File::KDBX::Key::YubiKey->new; like exception { $key->challenge('foo') }, qr/failed to run|failed to receive challenge response/i, 'Throw if the program failed to run';