X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=t%2Fhmac-block.t;h=87f280913f0b863c1eef8a6ed1fb9441d01b2ea8;hb=c98fc7d0294e641cf8844306808333bdec4fea2f;hp=bff3d5edc4a225b53f2026bb8e63d53a48f6d635;hpb=f63182fc62b25269b1c38588dca2b3535ed1a1a2;p=chaz%2Fp5-File-KDBX diff --git a/t/hmac-block.t b/t/hmac-block.t index bff3d5e..87f2809 100644 --- a/t/hmac-block.t +++ b/t/hmac-block.t @@ -6,12 +6,11 @@ use strict; use lib 't/lib'; use TestCommon qw(:no_warnings_test); +use File::KDBX::IO::HmacBlock; use File::KDBX::Util qw(can_fork); use IO::Handle; use Test::More; -BEGIN { use_ok 'PerlIO::via::File::KDBX::HmacBlock' } - my $KEY = "\x01" x 64; { @@ -19,57 +18,57 @@ my $KEY = "\x01" x 64; pipe(my $read, my $write) or die "pipe failed: $!\n"; - PerlIO::via::File::KDBX::HmacBlock->push($write, block_size => 3, key => $KEY); + $write = File::KDBX::IO::HmacBlock->new($write, block_size => 3, key => $KEY); print $write $expected_plaintext; - binmode($write, ':pop'); # finish stream close($write) or die "close failed: $!"; - PerlIO::via::File::KDBX::HmacBlock->push($read, key => $KEY); + $read = File::KDBX::IO::HmacBlock->new($read, key => $KEY); my $plaintext = do { local $/; <$read> }; close($read); is $plaintext, $expected_plaintext, 'HMAC-block just a little bit'; -} -subtest 'Error handling' => sub { - pipe(my $read, my $write) or die "pipe failed: $!\n"; - - PerlIO::via::File::KDBX::HmacBlock->push($read, key => $KEY); - - print $write 'blah blah blah'; - close($write) or die "close failed: $!"; - - is $read->error, 0, 'Read handle starts out fine'; - my $data = do { local $/; <$read> }; - is $read->error, 1, 'Read handle can enter and error state'; - - like $PerlIO::via::File::KDBX::HmacBlock::ERROR, qr/failed to read HMAC/i, - 'Error object is available'; -}; + is $File::KDBX::IO::HmacBlock::ERROR, undef, 'No error when successful'; +} SKIP: { - skip 'Tests require fork' if !can_fork; + skip 'fork required to test long data streams' if !can_fork; my $expected_plaintext = "\x64" x (1024*1024*12 - 57); + local $SIG{CHLD} = 'IGNORE'; pipe(my $read, my $write) or die "pipe failed: $!\n"; defined(my $pid = fork) or die "fork failed: $!\n"; if ($pid == 0) { - PerlIO::via::File::KDBX::HmacBlock->push($write, key => $KEY); + $write = File::KDBX::IO::HmacBlock->new($write, key => $KEY); print $write $expected_plaintext; - binmode($write, ':pop'); # finish stream close($write) or die "close failed: $!"; - exit; + # exit; + require POSIX; + POSIX::_exit(0); } - PerlIO::via::File::KDBX::HmacBlock->push($read, key => $KEY); + $read = File::KDBX::IO::HmacBlock->new($read, key => $KEY); my $plaintext = do { local $/; <$read> }; close($read); is $plaintext, $expected_plaintext, 'HMAC-block a lot'; - - waitpid($pid, 0) or die "wait failed: $!\n"; } +subtest 'Error handling' => sub { + pipe(my $read, my $write) or die "pipe failed: $!\n"; + + $read = File::KDBX::IO::HmacBlock->new($read, key => $KEY); + + print $write 'blah blah blah'; + close($write) or die "close failed: $!"; + + is $read->error, '', 'Read handle starts out fine'; + my $data = do { local $/; <$read> }; + is $read->error, 1, 'Read handle can enter an error state'; + + like $File::KDBX::IO::HmacBlock::ERROR, qr/failed to read HMAC/i, 'Error object is available'; +}; + done_testing;