From: Marius Gavrilescu Date: Sat, 14 Apr 2018 15:27:10 +0000 (+0300) Subject: Better test coverage X-Git-Tag: 0.002~3 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=b68c60ff4b898ad462793b4084199231e22f4024;p=authen-passphrase-scrypt.git Better test coverage --- diff --git a/Makefile.PL b/Makefile.PL index 2a1fa63..6d653e0 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -34,6 +34,9 @@ WriteMakefile( Object::Tiny 0 Data::Entropy::Algorithms 0/, }, + TEST_REQUIRES => { + qw/Test::Exception 0/, + }, INC => '-I. -Iscrypt-1.2.1', LIBS => ['-lcrypto'], MYEXTLIB => 'scrypt-1.2.1/libscrypt_sse2.a', diff --git a/t/Authen-Passphrase-Scrypt.t b/t/Authen-Passphrase-Scrypt.t index dce2a7a..aceef26 100644 --- a/t/Authen-Passphrase-Scrypt.t +++ b/t/Authen-Passphrase-Scrypt.t @@ -2,7 +2,9 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 16; +use Test::Exception; + BEGIN { use_ok('Authen::Passphrase::Scrypt') }; # Vectors in the scrypt paper @@ -33,11 +35,29 @@ $x = Authen::Passphrase::Scrypt->from_rfc2307($test_rfc2307); ok !$x->match('password1'), 'from_rfc2307 + match'; ok $x->match('password2'), 'from_rfc2307 + match'; -my $y = Authen::Passphrase::Scrypt->new({ +my $y = Authen::Passphrase::Scrypt->new( passphrase => 'password2', salt => $x->salt, logN => $x->logN, r => 8, -}); +); is $y->as_rfc2307, $test_rfc2307, 'as_rfc2307'; + +my $bad_rfc2307_1 = '{SCRYPT}notavalidscryptstringaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; +my $bad_rfc2307_2 = '{SCRYPT}c2NyeXB0AAwAAAAIAAAAAZ/+bp8gWcTZgEC7YQZeLLyxFeKRRdDkwbaGeFC0NkdUraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; + +throws_ok { Authen::Passphrase::Scrypt->new } + qr/passphrase not set/, 'new without passphrase'; +throws_ok { Authen::Passphrase::Scrypt->from_rfc2307('bad') } + qr/Invalid Scrypt RFC2307/, 'from_rfc2307 with bad string'; +throws_ok { Authen::Passphrase::Scrypt->from_rfc2307($bad_rfc2307_1) } + qr/Invalid Scrypt RFC2307: should start/, 'from_rfc2307 with another bad string'; +throws_ok { Authen::Passphrase::Scrypt->from_rfc2307($bad_rfc2307_2) } + qr/Invalid Scrypt RFC2307: bad checksum/, 'from_rfc2307 with yet another rfc2307'; +throws_ok { Authen::Passphrase::Scrypt->from_crypt('') } + qr/does not support crypt strings/, 'from_crypt'; +throws_ok { $y->as_crypt } + qr/does not support crypt strings/, 'as_crypt'; +throws_ok { Authen::Passphrase::Scrypt->new(passphrase => 'xkcd', r => (1 << 30), p => (1 << 30)) } + qr/Error in crypto_scrypt/, 'new with huge r and p';