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

1.7       andrew      1: #!/usr/bin/perl
1.8     ! andrew      2: # $RedRiver: keyring.t,v 1.7 2007/02/18 16:19:12 andrew Exp $
1.7       andrew      3: use strict;
                      4: use warnings;
1.1       andrew      5:
1.8     ! andrew      6: use Test::More qw/no_plan/; #tests => 22;
1.1       andrew      7:
1.7       andrew      8: BEGIN { use_ok( 'Palm::PDB' ); }
                      9: BEGIN { use_ok( 'Palm::Keyring' ); }
1.1       andrew     10:
1.8     ! andrew     11: my $file = 'Keys-test.pdb';
1.1       andrew     12: my $password = '12345';
1.3       andrew     13: my $new_password = '54321';
                     14: my $acct = {
                     15:     name        => 'test3',
                     16:        account     => 'atestaccount',
                     17:        password    => $password,
                     18:        notes       => 'now that really roxorZ!',
1.4       andrew     19:     lastchange  => {
                     20:         day   =>  2,
                     21:         month =>  2,
                     22:         year  => 99,
                     23:     },
1.3       andrew     24: };
                     25:
1.8     ! andrew     26: my @o = (
        !            27:     {
        !            28:         version  => 4,
        !            29:         password => $password,
        !            30:     },
        !            31:     {
        !            32:         version      => 5,
        !            33:         password     => $password,
        !            34:         v4compatible => 1,
        !            35:     },
        !            36: );
        !            37:
        !            38: foreach my $options (@o) {
        !            39:     my $pdb;
        !            40:     my $record;
        !            41:     my $decrypted;
1.7       andrew     42:
1.8     ! andrew     43:     ok( $pdb = new Palm::Keyring($options), 'New Palm::Keyring');
1.7       andrew     44:
1.8     ! andrew     45:     ok( $record = $pdb->append_Record(), 'Append Record' );
1.7       andrew     46:
1.8     ! andrew     47:     ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' );
1.7       andrew     48:
1.8     ! andrew     49:     ok( $pdb->Write($file), 'Write file' );
1.7       andrew     50:
1.8     ! andrew     51:     $pdb = undef;
1.7       andrew     52:
1.8     ! andrew     53:     ok( $pdb = new Palm::PDB(), 'New Palm::PDB' );
1.7       andrew     54:
1.8     ! andrew     55:     ok( $pdb->Load($file), 'Load File' );
1.7       andrew     56:
1.8     ! andrew     57:     ok( $pdb->Password($password), 'Verify Password' );
1.7       andrew     58:
1.8     ! andrew     59:     ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt record' );
1.7       andrew     60:
1.8     ! andrew     61:     is( $decrypted->{password}, $password, 'Got password' );
1.7       andrew     62:
1.8     ! andrew     63:     is_deeply( $decrypted, $acct, 'Account Matches' );
1.1       andrew     64:
1.8     ! andrew     65:     my $old_date = $decrypted->{'lastchange'};
1.7       andrew     66:
1.8     ! andrew     67:     ok( $pdb->Password($password, $new_password), 'Change PDB Password' );
1.7       andrew     68:
1.8     ! andrew     69:     ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt with new password' );
1.7       andrew     70:
1.8     ! andrew     71:     my $new_date = $decrypted->{'lastchange'};
1.7       andrew     72:
1.8     ! andrew     73:     is_deeply( $old_date, $new_date, 'Date didn\'t change' );
1.4       andrew     74:
1.8     ! andrew     75:     $acct->{'password'} = $new_password;
1.4       andrew     76:
1.8     ! andrew     77:     ok(  $pdb->Encrypt($pdb->{'records'}->[1], $acct), 'Change record' );
1.7       andrew     78:
1.8     ! andrew     79:     ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt new record' );
1.7       andrew     80:
1.8     ! andrew     81:     $new_date = $decrypted->{'lastchange'};
1.4       andrew     82:
1.8     ! andrew     83:     my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date };
        !            84:     my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date };
1.7       andrew     85:
1.8     ! andrew     86:     isnt( $od, $nd, 'Date changed');
1.7       andrew     87:
1.8     ! andrew     88:     is( $decrypted->{password}, $new_password, 'Got new password' );
1.7       andrew     89:
1.8     ! andrew     90:     $decrypted = {};
        !            91:     ok( $pdb->Password(), 'Forget password' );
1.7       andrew     92:
1.8     ! andrew     93:     eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]) };
        !            94:     ok( $@, 'Don\'t decrypt' );
1.7       andrew     95:
1.8     ! andrew     96:     isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' );
1.4       andrew     97:
1.8     ! andrew     98:     unlink($file);
        !            99: }
1.1       andrew    100:
                    101: 1;

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