=================================================================== RCS file: /cvs/palm/Palm-Keyring/t/keyring.t,v retrieving revision 1.20 retrieving revision 1.23 diff -u -r1.20 -r1.23 --- palm/Palm-Keyring/t/keyring.t 2008/09/18 07:06:11 1.20 +++ 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.19 2008/09/18 02:02:50 andrew Exp $ +# $RedRiver: keyring.t,v 1.22 2008/09/19 02:51:44 andrew Exp $ use strict; use warnings; -use Test::More tests => 198; +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, @@ -106,11 +108,12 @@ is( Palm::Keyring::labels(), undef, "Didn't get label empty label" ); is_deeply( Palm::Keyring::labels($bad_label), \%label_not_found_details, "Got default label for $bad_label" ); -is( Palm::Keyring::labels($bad_label_name), undef, "Didn't get label for - $bad_label_name" +is( Palm::Keyring::labels($bad_label_name), undef, "Didn't get label for $bad_label_name" ); + my $pdb; + eval { $pdb = new Palm::Keyring( -file => 't/Keys-invalid_version.pdb' ) }; like( $@, @@ -125,52 +128,117 @@ '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' ); my $record; ok( $record = $pdb->append_Record(), 'Append Record' ); -ok( $pdb->Encrypt( $record, $password, $acct ), - 'Encrypt account into record' ); -my $record2; -ok( $record2 = $pdb->append_Record(), 'Append 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' ); eval{ $pdb->PackRecord($record2) }; like( - $@, - qr/^No \s encrypted \s content \s to \s pack/xms, - 'Fail to pack record without encrypted content' -); + $@, + qr/^No \s encrypted \s data \s in \s record/xms, + 'Pack Empty Record' +); -$record2->{encrypted} = ''; +$record2->{encrypted} = q{}; eval{ $pdb->PackRecord($record2) }; like( - $@, + $@, qr/^No \s ivec/xms, - 'Fail to pack record without ivec' + 'Pack Empty Record with encrypted, but no ivec' +); + +$pdb->{version} = 4; +delete $record->{encrypted}; +delete $record->{data}; +eval{ $pdb->PackRecord($record) }; +like( $@, + qr/^No \s data \s in \s record \s to \s pack/xms, + 'Couldn\'t PackRecord without data' ); -$record2->{ivec} = 1; -ok( $pdb->PackRecord($record2), 'Pack Proper Record'); +$pdb->{version} = 999; +eval{ $pdb->Encrypt( $record, $password, $acct ) }; +like( + $@, + qr/^Unsupported \s version \s 999/xms, + 'Couldn\'t Encrypt with unsupported version' +); -ok( $record = $pdb->ParseRecord(%{ $record }), 'Parse Proper Packed'); +eval { $pdb->Write($file) }; +like( + $@, + qr/^Unsupported \s Version \s 999/xms, + 'Couldn\'t Write file with unsupported version' +); -$pdb->{version} = 999; eval{ $pdb->PackRecord($record) }; like( $@, qr/^Unsupported \s Version \s 999/xms, 'Couldn\'t PackRecord with Invalid Version' ); +$record2->{data} = q{nothing}; eval{ $pdb->ParseRecord(%{ $record2 }) }; like( $@, qr/^Unsupported \s Version \s 999/xms, 'Couldn\'t ParseRecord with Invalid Version' ); -$pdb = undef; +$pdb = undef; +$record = undef; +$record2 = undef; +%{ $acct->{3}->{data} } = %unchanging_date; + unlink $file; foreach my $options (@o) { @@ -230,6 +298,7 @@ ); ok( $pdb->Write($file), 'Write "empty" file' ); + #exit if $pdb->{version} == 5; ok( $record = $pdb->append_Record(), 'Append Record' ); @@ -313,16 +382,8 @@ is_deeply( $plaintext[0], $cleared_decrypted, 'Cleared records' ); $pdb->{records}->[0]->{data} = undef; - ok( $pdb->Write($file), 'Write file' ); - ok( $pdb->Load($file), 'Load File' ); - - $pdb->{version} = 999; - eval { $pdb->Write($file) }; - like( - $@, - qr/^Unsupported \s Version \s 999/xms, - 'Couldn\'t Write file with unsupported version' - ); + ok( $pdb->Write($file), 'Write file without data' ); + ok( $pdb->Load($file), 'Load File without data' ); ok( unlink($file), 'Remove test pdb v' . $options->{version} );