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