1#!./perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 @INC = '../lib'; 6 require "./test.pl"; 7 eval 'use Errno'; 8 die $@ if $@ and !is_miniperl(); 9} 10 11my @bad_salts = 12 ( 13 [ '', 'zero-length' ], 14 [ 'a', 'length 1' ], 15 [ '!a', 'bad first character' ], 16 [ 'a!', 'bad second character' ], 17 [ '@a', 'fencepost before A' ], 18 [ '[a', 'fencepost after Z' ], 19 [ '`a', 'fencepost before a' ], 20 [ '{a', 'fencepost after z' ], 21 [ '-a', 'fencepost before .' ], 22 [ ':a', 'fencepost after 9' ], 23 ); 24 25my @good_salts = qw(aa zz AA ZZ .. 99); 26 27plan tests => 2 * @bad_salts + 1 + @good_salts; 28 29for my $bad_salt (@bad_salts) { 30 my ($salt, $what) = @$bad_salt; 31 $! = 0; 32 is(crypt("abc", $salt), undef, "bad salt ($what)"); 33 is(0+$!, &Errno::EINVAL, "check errno ($what)"); 34} 35 36is(crypt("abcdef", "ab"), "abDMWw5NL.afs", "sanity check result"); 37 38# just to check we're not rejecting any good salts 39for my $good_salt (@good_salts) { 40 isnt(crypt("abcdef", $good_salt), undef, "good salt $good_salt"); 41} 42