From cbc81366fdd3b9f7cc19b8ce81c5b83994e91963 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 3 Apr 2011 19:31:32 +0200 Subject: t/20-app-raps2-password.t: Tests for ->salt() --- t/20-app-raps2-password.t | 54 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/t/20-app-raps2-password.t b/t/20-app-raps2-password.t index 67bf29a..56a6f4d 100644 --- a/t/20-app-raps2-password.t +++ b/t/20-app-raps2-password.t @@ -3,7 +3,7 @@ use strict; use warnings; use 5.010; -use Test::More tests => 13; +use Test::More tests => 19; use Test::Exception; my $pw; @@ -28,6 +28,17 @@ throws_ok( 'new() missing passphrase' ); +throws_ok( + sub { + App::Raps2::Password->new( + salt => $salt, + passphrase => q{} + ); + }, + qr{no passphrase given}, + 'new() missing passphrase' +); + throws_ok( sub { App::Raps2::Password->new(passphrase => $pass); @@ -87,4 +98,43 @@ throws_ok( 'verify: does not verify invalid hash' ); -ok($pw->verify($pw->crypt('truth')), 'crypt->verify okay') +ok($pw->verify($pw->crypt('truth')), 'crypt->verify okay'); + +throws_ok( + sub { + $pw->salt(); + }, + qr{incorrect salt length}, + 'salt: No argument', +); + +throws_ok( + sub { + $pw->salt(''); + }, + qr{incorrect salt length}, + 'salt: Empty argument', +); + +throws_ok( + sub { + $pw->salt('abcdefghijklmno'); + }, + qr{incorrect salt length}, + 'salt: One too short', +); + +throws_ok( + sub { + $pw->salt($salt . 'z'); + }, + qr{incorrect salt length}, + 'salt: One too long', +); + +lives_ok( + sub { + $pw->salt($salt); + }, + 'salt: Correct length', +); -- cgit v1.2.3