]> Dogcows Code - chaz/p5-File-KDBX/blob - t/files/bin/ykchalresp
Fix YubiKey unit test portability issues
[chaz/p5-File-KDBX] / t / files / bin / ykchalresp
1 #!/usr/bin/env perl
2
3 # This is a fake ykchalresp program that provides canned responses, for testing.
4
5 use warnings;
6 use strict;
7
8 use Getopt::Std;
9
10 my %opts;
11 getopts('12HNn:i:', \%opts);
12
13 my ($device, $hmac, $nonblocking, $in) = @opts{qw(n H N i)};
14
15 if (!$hmac) {
16 print STDERR "HMAC-SHA1 not requested\n";
17 exit 3;
18 }
19 elsif (!defined($in) || $in ne '-') {
20 $in //= '(none)';
21 print STDERR "Unexpected input file: $in\n";
22 exit 3;
23 }
24
25 my $challenge = <STDIN>;
26
27 my $mock = $ENV{YKCHALRESP_MOCK} || '';
28 if ($mock eq 'block') {
29 if ($nonblocking) {
30 print STDERR "Yubikey core error: operation would block\n";
31 exit 1;
32 }
33 sleep 2;
34 succeed();
35 }
36 elsif ($mock eq 'error') {
37 my $resp = $ENV{YKCHALRESP_ERROR} || 'not yet implemented';
38 print STDERR "Yubikey core error: $resp\n";
39 exit 1;
40 }
41 elsif ($mock eq 'usberror') {
42 print STDERR "USB error: something happened\n";
43 exit 1;
44 }
45 else { # OK
46 succeed();
47 }
48
49 sub succeed {
50 my $resp = $ENV{YKCHALRESP_RESPONSE} || 'f000000000000000000000000000000000000000';
51 print "$resp\n";
52 exit 0;
53 }
54
55 exit 2;
This page took 0.037436 seconds and 4 git commands to generate.