Annotation of palm/Palm-Keyring/t/keyring4.t, Revision 1.2
1.1 andrew 1: #!/usr/bin/perl
1.2 ! andrew 2: # $RedRiver: keyring4.t,v 1.1 2007/02/17 23:36:07 andrew Exp $
1.1 andrew 3: use strict;
4: use warnings;
5:
1.2 ! andrew 6: use Test::More tests => 22;
1.1 andrew 7:
8: BEGIN { use_ok( 'Palm::PDB' ); }
9: BEGIN { use_ok( 'Palm::Keyring' ); }
10:
11: my $file = 'Keys-test-v4.pdb';
12: my $password = '12345';
13: my $new_password = '54321';
14: my $acct = {
15: name => 'test3',
16: account => 'atestaccount',
17: password => $password,
18: notes => 'now that really roxorZ!',
19: lastchange => {
20: day => 2,
21: month => 2,
22: year => 99,
23: },
24: };
25:
26: my $pdb;
27: my $record;
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' );
51:
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' );
61:
62: $acct->{'password'} = $new_password;
63:
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'};
69:
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' );
84:
85: unlink($file);
86:
87: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>