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

1.7     ! andrew      1: #!/usr/bin/perl
        !             2: # $RedRiver: keyring4.t,v 1.2 2007/02/18 05:39:32 andrew Exp $
        !             3: use strict;
        !             4: use warnings;
1.1       andrew      5:
1.7     ! andrew      6: use Test::More 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.7     ! andrew     11: my $file = 'Keys-test-v4.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.1       andrew     26: my $pdb;
1.3       andrew     27: my $record;
1.7     ! andrew     28: my $decrypted;
        !            29:
        !            30: ok( $pdb = new Palm::Keyring($password), 'New Palm::Keyring');
        !            31:
        !            32: ok( $record = $pdb->append_Record(), 'Append Record' );
        !            33:
        !            34: ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' );
        !            35:
        !            36: ok( $pdb->Write($file), 'Write file' );
        !            37:
        !            38: $pdb = undef;
        !            39:
        !            40: ok( $pdb = new Palm::PDB(), 'New Palm::PDB' );
        !            41:
        !            42: ok( $pdb->Load($file), 'Load File' );
        !            43:
        !            44: ok( $pdb->Password($password), 'Verify Password' );
        !            45:
        !            46: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt record' );
        !            47:
        !            48: is( $decrypted->{password}, $password, 'Got password' );
        !            49:
        !            50: is_deeply( $decrypted, $acct, 'Account Matches' );
1.1       andrew     51:
1.7     ! andrew     52: my $old_date = $decrypted->{'lastchange'};
        !            53:
        !            54: ok( $pdb->Password($password, $new_password), 'Change PDB Password' );
        !            55:
        !            56: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt with new password' );
        !            57:
        !            58: my $new_date = $decrypted->{'lastchange'};
        !            59:
        !            60: is_deeply( $old_date, $new_date, 'Date didn\'t change' );
1.4       andrew     61:
                     62: $acct->{'password'} = $new_password;
                     63:
1.7     ! andrew     64: ok(  $pdb->Encrypt($pdb->{'records'}->[1], $acct), 'Change record' );
        !            65:
        !            66: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt new record' );
        !            67:
        !            68: $new_date = $decrypted->{'lastchange'};
1.4       andrew     69:
1.7     ! andrew     70: my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date };
        !            71: my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date };
        !            72:
        !            73: isnt( $od, $nd, 'Date changed');
        !            74:
        !            75: is( $decrypted->{password}, $new_password, 'Got new password' );
        !            76:
        !            77: $decrypted = {};
        !            78: ok( $pdb->Password(), 'Forget password' );
        !            79:
        !            80: eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]) };
        !            81: ok( $@, 'Don\'t decrypt' );
        !            82:
        !            83: isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' );
1.4       andrew     84:
1.1       andrew     85: unlink($file);
                     86:
                     87: 1;

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