=================================================================== RCS file: /cvs/palm/Palm-Keyring/t/keyring.t,v retrieving revision 1.22 retrieving revision 1.24 diff -u -r1.22 -r1.24 --- palm/Palm-Keyring/t/keyring.t 2008/09/19 03:51:44 1.22 +++ palm/Palm-Keyring/t/keyring.t 2008/09/19 06:53:08 1.24 @@ -1,9 +1,9 @@ #!/usr/bin/perl -T -# $RedRiver: keyring.t,v 1.21 2008/09/19 02:08:01 andrew Exp $ +# $RedRiver: keyring.t,v 1.23 2008/09/19 05:39:58 andrew Exp $ use strict; use warnings; -use Test::More tests => 195; +use Test::More tests => 202; use Data::Dumper; BEGIN { @@ -62,6 +62,8 @@ }, }; +my %unchanging_date = %{ $acct->{3}->{data} }; + my $bad_cipher = 999; my %crypt_1_details = ( 'default_iter' => 1000, @@ -110,7 +112,6 @@ ); - my $pdb; eval { $pdb = new Palm::Keyring( -file => 't/Keys-invalid_version.pdb' ) }; @@ -127,15 +128,54 @@ 'Couldn\'t load pdb with Unknown Cipher' ); +eval { $pdb = new Palm::Keyring( -file => 't/Keys-invalid_appinfo.pdb' ) }; +like( + $@, + qr/^Corrupt \s appinfo\? \s no \s {other}/xms, + 'Couldn\'t load pdb with invalid appinfo' +); + +ok( $pdb = new Palm::Keyring( -file => 't/Keys-no_data.pdb', -password => + $new_password ), + 'Loaded Palm::Keyring file with no data' ); ok( $pdb = new Palm::Keyring( -file => 't/Keys-no_data.pdb' ), 'Loaded Palm::Keyring file with no data' ); -ok( $pdb->Password($password), 'Entering Password' ); - my $record; ok( $record = $pdb->append_Record(), 'Append Record' ); -ok( $pdb->Encrypt( $record, $password, $acct ), - 'Encrypt account into record' ); +eval{ $pdb->Encrypt() }; +like( + $@, + qr/^Needed \s parameter \s \[record\] \s not \s passed!/xms, + 'Encrypt account into record without record' +); +eval{ $pdb->Encrypt( $record ) }; +like( + $@, + qr/^password \s not \s set!/xms, + 'Encrypt account into record without password' +); +eval{ $pdb->Encrypt( $record, $password ) }; +like( + $@, + qr/^Needed \s parameter \s \[plaintext\] \s not \s passed!/xms, + 'Encrypt account into record without account' +); +eval{ $pdb->Encrypt( $record, $new_password, $acct ) }; +like( + $@, + qr/^Incorrect \s Password!/xms, + 'Encrypt account into record with wrong password' +); + +my $ivec = pack("C*", 1..8); +ok( $pdb->Encrypt( $record, $password, $acct, $ivec), + 'Encrypt account into record (with custom ivec)' ); +ok( $pdb->Encrypt( $record, $password, $acct), + 'Encrypt account into record (with no changes)'); + +delete $record->{plaintext}; + ok( $pdb->PackRecord($record), 'Pack Proper Record'); ok( $record = $pdb->ParseRecord(%{ $record }), 'Parse Proper Packed'); @@ -166,6 +206,14 @@ ); $pdb->{version} = 999; +delete $record->{encrypted}; +eval{ $pdb->Encrypt( $record, undef, $acct ) }; +like( + $@, + qr/^Unsupported \s version \s 999/xms, + 'Couldn\'t Encrypt with unsupported version' +); + eval { $pdb->Write($file) }; like( $@, @@ -187,7 +235,10 @@ ); -$pdb = undef; +$pdb = undef; +$record = undef; +$record2 = undef; +%{ $acct->{3}->{data} } = %unchanging_date; unlink $file; @@ -248,6 +299,7 @@ ); ok( $pdb->Write($file), 'Write "empty" file' ); + #exit if $pdb->{version} == 5; ok( $record = $pdb->append_Record(), 'Append Record' );