=================================================================== RCS file: /cvs/palm/Palm-Keyring/t/keyring.t,v retrieving revision 1.20 retrieving revision 1.22 diff -u -r1.20 -r1.22 --- palm/Palm-Keyring/t/keyring.t 2008/09/18 07:06:11 1.20 +++ palm/Palm-Keyring/t/keyring.t 2008/09/19 03:51:44 1.22 @@ -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.21 2008/09/19 02:08:01 andrew Exp $ use strict; use warnings; -use Test::More tests => 198; +use Test::More tests => 195; use Data::Dumper; BEGIN { @@ -106,11 +106,13 @@ 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( $@, @@ -128,47 +130,63 @@ 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' ); +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($record), 'Pack Proper 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'); - -ok( $record = $pdb->ParseRecord(%{ $record }), 'Parse Proper Packed'); - $pdb->{version} = 999; +eval { $pdb->Write($file) }; +like( + $@, + qr/^Unsupported \s Version \s 999/xms, + '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' ); +$record2->{data} = q{nothing}; eval{ $pdb->ParseRecord(%{ $record2 }) }; like( $@, qr/^Unsupported \s Version \s 999/xms, 'Couldn\'t ParseRecord with Invalid Version' ); + $pdb = undef; unlink $file; @@ -313,16 +331,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} );