[BACK]Return to keyring.t CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / t

Annotation of palm/Palm-Keyring/t/keyring.t, Revision 1.13

1.12      andrew      1: #!/usr/bin/perl -T
1.13    ! andrew      2: # $RedRiver: keyring.t,v 1.12 2007/02/23 22:05:17 andrew Exp $
1.7       andrew      3: use strict;
                      4: use warnings;
1.1       andrew      5:
1.9       andrew      6: use Test::More tests => 44;
1.1       andrew      7:
1.9       andrew      8: BEGIN {
                      9:     use_ok( 'Palm::PDB' );
                     10:     use_ok( 'Palm::Keyring' );
                     11: }
1.1       andrew     12:
1.8       andrew     13: my $file = 'Keys-test.pdb';
1.1       andrew     14: my $password = '12345';
1.3       andrew     15: my $new_password = '54321';
                     16:
1.8       andrew     17: my @o = (
                     18:     {
                     19:         version  => 4,
                     20:         password => $password,
                     21:     },
                     22:     {
                     23:         version      => 5,
                     24:         password     => $password,
1.9       andrew     25:         cipher       => 1,
1.8       andrew     26:         v4compatible => 1,
                     27:     },
                     28: );
                     29:
                     30: foreach my $options (@o) {
                     31:     my $pdb;
                     32:     my $record;
                     33:     my $decrypted;
1.7       andrew     34:
1.9       andrew     35:     my $acct = {
                     36:         name        => 'test3',
                     37:         account     => 'atestaccount',
                     38:         password    => $password,
                     39:         notes       => 'now that really roxorZ!',
                     40:         lastchange  => {
                     41:             day   =>  2,
                     42:             month =>  2,
                     43:             year  => 99,
                     44:         },
                     45:     };
                     46:
1.11      andrew     47:     SKIP: {
                     48:         if (defined $options->{cipher} && $options->{cipher} > 0) {
                     49:             my $crypt = Palm::Keyring::crypts($options->{cipher});
                     50:             skip 'Crypt::CBC not installed', 21 unless
                     51:                 eval "require Crypt::CBC";
                     52:             skip 'Crypt::' . $crypt->{name} . ' not installed', 21 unless
                     53:                 eval "require Crypt::$crypt->{name}";
                     54:         }
1.7       andrew     55:
1.11      andrew     56:         if ($options->{version} == 4) {
                     57:             skip 'Crypt::DES not installed', 21 unless
                     58:                 eval " require Crypt::DES ";
                     59:             skip 'Digest::MD5 not installed', 21 unless
                     60:                 eval " require Digest::MD5 ";
                     61:         } elsif ($options->{version} == 5) {
                     62:             skip 'Digest::HMAC_SHA1 not installed', 21 unless
                     63:                 eval " require Digest::HMAC_SHA1 ";
                     64:         }
1.7       andrew     65:
1.11      andrew     66:         ok( $pdb = new Palm::Keyring($options),
                     67:             'New Palm::Keyring v' . $options->{version} );
1.7       andrew     68:
1.11      andrew     69:         ok( $record = $pdb->append_Record(), 'Append Record' );
1.7       andrew     70:
1.11      andrew     71:         ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' );
1.7       andrew     72:
1.11      andrew     73:         ok( $pdb->Write($file), 'Write file' );
1.9       andrew     74:
1.11      andrew     75:         $pdb = undef;
                     76:
                     77:
                     78:         my $rec_num = 1;
                     79:         if ($options->{version} == 4) {
                     80:             ok( $pdb = new Palm::PDB(), 'New Palm::PDB' );
                     81:         } else {
                     82:             ok( $pdb = new Palm::Keyring(-v4compatible => 1), 'New Palm::Keyring' );
                     83:             $rec_num = 0;
                     84:         }
1.7       andrew     85:
1.11      andrew     86:         ok( $pdb->Load($file), 'Load File' );
1.7       andrew     87:
1.11      andrew     88:         ok( $pdb->Password($password), 'Verify Password' );
1.7       andrew     89:
1.11      andrew     90:         ok( $decrypted = $pdb->Decrypt($pdb->{records}->[$rec_num]), 'Decrypt record' );
1.7       andrew     91:
1.11      andrew     92:         is( $decrypted->{password}, $password, 'Got password' );
1.7       andrew     93:
1.11      andrew     94:         is_deeply( $decrypted, $acct, 'Account Matches' );
1.1       andrew     95:
1.11      andrew     96:         my $old_date = $decrypted->{'lastchange'};
1.7       andrew     97:
1.11      andrew     98:         ok( $pdb->Password($password, $new_password), 'Change PDB Password' );
1.7       andrew     99:
1.11      andrew    100:         ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]), 'Decrypt with new password' );
1.7       andrew    101:
1.11      andrew    102:         my $new_date = $decrypted->{'lastchange'};
1.7       andrew    103:
1.11      andrew    104:         is_deeply( $old_date, $new_date, 'Date didn\'t change' );
1.4       andrew    105:
1.11      andrew    106:         $acct->{'password'} = $new_password;
1.4       andrew    107:
1.11      andrew    108:         ok(  $pdb->Encrypt($pdb->{'records'}->[$rec_num], $acct), 'Change record' );
1.7       andrew    109:
1.11      andrew    110:         ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]), 'Decrypt new record' );
1.7       andrew    111:
1.11      andrew    112:         $new_date = $decrypted->{'lastchange'};
1.4       andrew    113:
1.11      andrew    114:         my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date };
                    115:         my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date };
1.7       andrew    116:
1.11      andrew    117:         isnt( $od, $nd, 'Date changed');
1.7       andrew    118:
1.11      andrew    119:         is( $decrypted->{password}, $new_password, 'Got new password' );
1.7       andrew    120:
1.11      andrew    121:         $decrypted = {};
                    122:         ok( $pdb->Password(), 'Forget password' );
1.7       andrew    123:
1.11      andrew    124:         eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]) };
                    125:         ok( $@, 'Don\'t decrypt' );
1.7       andrew    126:
1.11      andrew    127:         isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' );
1.4       andrew    128:
1.11      andrew    129:         ok( unlink($file), 'Remove test pdb v' . $options->{version} );
                    130:     }
1.8       andrew    131: }
1.1       andrew    132:
                    133: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>