Annotation of palm/Palm-Keyring/t/keyring5.t, Revision 1.1
1.1 ! andrew 1: #!/usr/bin/perl
! 2: # $RedRiver: keyring.t,v 1.9 2007/02/19 00:22:42 andrew Exp $
! 3: use strict;
! 4: use warnings;
! 5:
! 6: use Test::More tests => 44;
! 7: use YAML;
! 8:
! 9: BEGIN {
! 10: use_ok( 'Palm::PDB' );
! 11: use_ok( 'Palm::Keyring' );
! 12: }
! 13:
! 14: my $file = 'Keys-test.pdb';
! 15: my $password = '12345';
! 16: my $new_password = '54321';
! 17:
! 18: my @o = (
! 19: {
! 20: version => 4,
! 21: password => $password,
! 22: },
! 23: {
! 24: version => 5,
! 25: password => $password,
! 26: cipher => 1,
! 27: v4compatible => 1,
! 28: },
! 29: );
! 30:
! 31: foreach my $options (@o) {
! 32: my $pdb;
! 33: my $record;
! 34: my $decrypted;
! 35:
! 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:
! 48: ok( $pdb = new Palm::Keyring($options), 'New Palm::Keyring v' . $options->{version} );
! 49:
! 50: ok( $record = $pdb->append_Record(), 'Append Record' );
! 51:
! 52: ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' );
! 53:
! 54: ok( $pdb->Write($file), 'Write file' );
! 55:
! 56: $pdb = undef;
! 57:
! 58:
! 59: my $rec_num = 1;
! 60: if ($options->{version} == 4) {
! 61: ok( $pdb = new Palm::PDB(), 'New Palm::PDB' );
! 62: } else {
! 63: ok( $pdb = new Palm::Keyring(-v4compatible => 1), 'New Palm::Keyring' );
! 64: $rec_num = 0;
! 65: }
! 66:
! 67: ok( $pdb->Load($file), 'Load File' );
! 68:
! 69: ok( $pdb->Password($password), 'Verify Password' );
! 70:
! 71: ok( $decrypted = $pdb->Decrypt($pdb->{records}->[$rec_num]), 'Decrypt record' );
! 72:
! 73: is( $decrypted->{password}, $password, 'Got password' );
! 74:
! 75: is_deeply( $decrypted, $acct, 'Account Matches' );
! 76:
! 77: my $old_date = $decrypted->{'lastchange'};
! 78:
! 79: ok( $pdb->Password($password, $new_password), 'Change PDB Password' );
! 80:
! 81: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]), 'Decrypt with new password' );
! 82:
! 83: my $new_date = $decrypted->{'lastchange'};
! 84:
! 85: is_deeply( $old_date, $new_date, 'Date didn\'t change' );
! 86:
! 87: $acct->{'password'} = $new_password;
! 88:
! 89: ok( $pdb->Encrypt($pdb->{'records'}->[$rec_num], $acct), 'Change record' );
! 90:
! 91: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]), 'Decrypt new record' );
! 92:
! 93: $new_date = $decrypted->{'lastchange'};
! 94:
! 95: my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date };
! 96: my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date };
! 97:
! 98: isnt( $od, $nd, 'Date changed');
! 99:
! 100: is( $decrypted->{password}, $new_password, 'Got new password' );
! 101:
! 102: $decrypted = {};
! 103: ok( $pdb->Password(), 'Forget password' );
! 104:
! 105: eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]) };
! 106: ok( $@, 'Don\'t decrypt' );
! 107:
! 108: isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' );
! 109:
! 110: ok( unlink($file), 'Remove test pdb v' . $options->{version} );
! 111: }
! 112:
! 113: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>