[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.12

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

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