Annotation of palm/Palm-Keyring/t/keyring.t, Revision 1.10
1.7 andrew 1: #!/usr/bin/perl
1.10 ! andrew 2: # $RedRiver: keyring.t,v 1.9 2007/02/19 00:22:42 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:
48: ok( $pdb = new Palm::Keyring($options), 'New Palm::Keyring v' . $options->{version} );
1.7 andrew 49:
1.8 andrew 50: ok( $record = $pdb->append_Record(), 'Append Record' );
1.7 andrew 51:
1.8 andrew 52: ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' );
1.7 andrew 53:
1.8 andrew 54: ok( $pdb->Write($file), 'Write file' );
1.7 andrew 55:
1.8 andrew 56: $pdb = undef;
1.7 andrew 57:
1.9 andrew 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: }
1.7 andrew 66:
1.8 andrew 67: ok( $pdb->Load($file), 'Load File' );
1.7 andrew 68:
1.8 andrew 69: ok( $pdb->Password($password), 'Verify Password' );
1.7 andrew 70:
1.9 andrew 71: ok( $decrypted = $pdb->Decrypt($pdb->{records}->[$rec_num]), 'Decrypt record' );
1.7 andrew 72:
1.8 andrew 73: is( $decrypted->{password}, $password, 'Got password' );
1.7 andrew 74:
1.8 andrew 75: is_deeply( $decrypted, $acct, 'Account Matches' );
1.1 andrew 76:
1.8 andrew 77: my $old_date = $decrypted->{'lastchange'};
1.7 andrew 78:
1.8 andrew 79: ok( $pdb->Password($password, $new_password), 'Change PDB Password' );
1.7 andrew 80:
1.9 andrew 81: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]), 'Decrypt with new password' );
1.7 andrew 82:
1.8 andrew 83: my $new_date = $decrypted->{'lastchange'};
1.7 andrew 84:
1.8 andrew 85: is_deeply( $old_date, $new_date, 'Date didn\'t change' );
1.4 andrew 86:
1.8 andrew 87: $acct->{'password'} = $new_password;
1.4 andrew 88:
1.9 andrew 89: ok( $pdb->Encrypt($pdb->{'records'}->[$rec_num], $acct), 'Change record' );
1.7 andrew 90:
1.9 andrew 91: ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]), 'Decrypt new record' );
1.7 andrew 92:
1.8 andrew 93: $new_date = $decrypted->{'lastchange'};
1.4 andrew 94:
1.8 andrew 95: my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date };
96: my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date };
1.7 andrew 97:
1.8 andrew 98: isnt( $od, $nd, 'Date changed');
1.7 andrew 99:
1.8 andrew 100: is( $decrypted->{password}, $new_password, 'Got new password' );
1.7 andrew 101:
1.8 andrew 102: $decrypted = {};
103: ok( $pdb->Password(), 'Forget password' );
1.7 andrew 104:
1.10 ! andrew 105: eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[$rec_num]) };
1.8 andrew 106: ok( $@, 'Don\'t decrypt' );
1.7 andrew 107:
1.8 andrew 108: isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' );
1.4 andrew 109:
1.9 andrew 110: ok( unlink($file), 'Remove test pdb v' . $options->{version} );
1.8 andrew 111: }
1.1 andrew 112:
113: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>