=================================================================== RCS file: /cvs/palm/Palm-Keyring/t/keyring.t,v retrieving revision 1.21 retrieving revision 1.23 diff -u -r1.21 -r1.23 --- palm/Palm-Keyring/t/keyring.t 2008/09/19 03:08:01 1.21 +++ palm/Palm-Keyring/t/keyring.t 2008/09/19 06:39:58 1.23 @@ -1,9 +1,9 @@ #!/usr/bin/perl -T -# $RedRiver: keyring.t,v 1.20 2008/09/18 06:06:11 andrew Exp $ +# $RedRiver: keyring.t,v 1.22 2008/09/19 02:51:44 andrew Exp $ use strict; use warnings; -use Test::More tests => 194; +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,35 +128,89 @@ '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'); my $record2; ok( $record2 = $pdb->append_Record(), 'Append Record' ); -ok( $pdb->PackRecord($record2), 'Pack Empty Record'); -ok( $record = $pdb->ParseRecord(%{ $record2 }), 'Parse Empty Packed'); +eval{ $pdb->PackRecord($record2) }; +like( + $@, + qr/^No \s encrypted \s data \s in \s record/xms, + 'Pack Empty Record' +); +$record2->{encrypted} = q{}; +eval{ $pdb->PackRecord($record2) }; +like( + $@, + qr/^No \s ivec/xms, + 'Pack Empty Record with encrypted, but no ivec' +); -$pdb->{version} = 999; +$pdb->{version} = 4; +delete $record->{encrypted}; +delete $record->{data}; eval{ $pdb->PackRecord($record) }; like( $@, - qr/^Unsupported \s Version \s 999/xms, - 'Couldn\'t PackRecord with Invalid Version' + qr/^No \s data \s in \s record \s to \s pack/xms, + 'Couldn\'t PackRecord without data' ); -eval{ $pdb->ParseRecord(%{ $record2 }) }; -like( $@, - qr/^Unsupported \s Version \s 999/xms, - 'Couldn\'t ParseRecord with Invalid Version' +$pdb->{version} = 999; +eval{ $pdb->Encrypt( $record, $password, $acct ) }; +like( + $@, + qr/^Unsupported \s version \s 999/xms, + 'Couldn\'t Encrypt with unsupported version' ); eval { $pdb->Write($file) }; @@ -165,9 +220,25 @@ 'Couldn\'t Write file with unsupported version' ); +eval{ $pdb->PackRecord($record) }; +like( $@, + qr/^Unsupported \s Version \s 999/xms, + 'Couldn\'t PackRecord with Invalid Version' +); -$pdb = undef; +$record2->{data} = q{nothing}; +eval{ $pdb->ParseRecord(%{ $record2 }) }; +like( $@, + qr/^Unsupported \s Version \s 999/xms, + 'Couldn\'t ParseRecord with Invalid Version' +); + +$pdb = undef; +$record = undef; +$record2 = undef; +%{ $acct->{3}->{data} } = %unchanging_date; + unlink $file; foreach my $options (@o) { @@ -227,6 +298,7 @@ ); ok( $pdb->Write($file), 'Write "empty" file' ); + #exit if $pdb->{version} == 5; ok( $record = $pdb->append_Record(), 'Append Record' );