version 1.5, 2007/02/03 00:53:22 |
version 1.8, 2007/02/18 16:24:53 |
|
|
# Before `make install' is performed this script should be runnable with |
#!/usr/bin/perl |
# `make test'. After `make install' it should work as `perl test.pl' |
# $RedRiver: keyring.t,v 1.7 2007/02/18 16:19:12 andrew Exp $ |
|
use strict; |
|
use warnings; |
|
|
######################### We start with some black magic to print on failure. |
use Test::More qw/no_plan/; #tests => 22; |
|
|
# Change 1..1 below to 1..last_test_to_print . |
BEGIN { use_ok( 'Palm::PDB' ); } |
# (It may become useful if the test is moved to ./t subdirectory.) |
BEGIN { use_ok( 'Palm::Keyring' ); } |
|
|
my $test = 1; |
my $file = 'Keys-test.pdb'; |
BEGIN { $| = 1; print "1..20\n"; } |
|
END {print "not ok $test\n" unless $loaded;} |
|
use Palm::PDB; |
|
use Palm::Keyring; |
|
$loaded = 1; |
|
print "ok $test\n"; |
|
$test++; |
|
|
|
######################### End of black magic. |
|
|
|
# Insert your test code below (better if it prints "ok 13" |
|
# (correspondingly "not ok 13") depending on the success of chunk 13 |
|
# of the test code): |
|
|
|
my $file = 'Keys-GTKR-test.pdb'; |
|
my $password = '12345'; |
my $password = '12345'; |
my $new_password = '54321'; |
my $new_password = '54321'; |
my $acct = { |
my $acct = { |
|
|
}, |
}, |
}; |
}; |
|
|
my $pdb; |
my @o = ( |
my $record; |
{ |
|
version => 4, |
|
password => $password, |
|
}, |
|
{ |
|
version => 5, |
|
password => $password, |
|
v4compatible => 1, |
|
}, |
|
); |
|
|
eval { $pdb = new Palm::Keyring($password) }; |
foreach my $options (@o) { |
unless( $@ ) { |
my $pdb; |
print "ok $test\n"; |
my $record; |
} else { |
my $decrypted; |
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $record = $pdb->append_Record() }; |
ok( $pdb = new Palm::Keyring($options), 'New Palm::Keyring'); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Encrypt($record, $acct, $password) || die }; |
ok( $record = $pdb->append_Record(), 'Append Record' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Write($file) }; |
ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$pdb = new Palm::PDB; |
ok( $pdb->Write($file), 'Write file' ); |
$acct = {}; |
|
|
|
eval { $pdb->Load($file) }; |
$pdb = undef; |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Password($password) || die }; |
ok( $pdb = new Palm::PDB(), 'New Palm::PDB' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die }; |
ok( $pdb->Load($file), 'Load File' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
if ($acct->{'password'} eq $password) { |
ok( $pdb->Password($password), 'Verify Password' ); |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
my $old_date = $acct->{'lastchange'}; |
ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt record' ); |
|
|
eval { $pdb->Password($password, $new_password) || die }; |
is( $decrypted->{password}, $password, 'Got password' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$acct = {}; |
is_deeply( $decrypted, $acct, 'Account Matches' ); |
eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die }; |
|
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
if ($acct->{'password'} eq $password) { |
my $old_date = $decrypted->{'lastchange'}; |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
my $new_date = $acct->{'lastchange'}; |
ok( $pdb->Password($password, $new_password), 'Change PDB Password' ); |
|
|
if ( |
ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt with new password' ); |
$old_date->{'day'} == $new_date->{'day'} && |
|
$old_date->{'month'} == $new_date->{'month'} && |
|
$old_date->{'year'} == $new_date->{'year'} |
|
) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$acct->{'password'} = $new_password; |
my $new_date = $decrypted->{'lastchange'}; |
|
|
eval { $acct = $pdb->Encrypt($pdb->{'records'}->[1], $acct) || die }; |
is_deeply( $old_date, $new_date, 'Date didn\'t change' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$old_date = $new_date; |
$acct->{'password'} = $new_password; |
$new_date = $acct->{'lastchange'}; |
|
|
|
eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die }; |
ok( $pdb->Encrypt($pdb->{'records'}->[1], $acct), 'Change record' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
if ( |
ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt new record' ); |
$old_date->{'day'} != $new_date->{'day'} || |
|
$old_date->{'month'} != $new_date->{'month'} || |
|
$old_date->{'year'} != $new_date->{'year'} |
|
) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
if ($acct->{'password'} eq $new_password) { |
$new_date = $decrypted->{'lastchange'}; |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Password() || die }; |
my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date }; |
unless( $@ ) { |
my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date }; |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die }; |
isnt( $od, $nd, 'Date changed'); |
if ( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
unless ($acct->{'password'} eq $password) { |
is( $decrypted->{password}, $new_password, 'Got new password' ); |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
|
$decrypted = {}; |
|
ok( $pdb->Password(), 'Forget password' ); |
|
|
unlink($file); |
eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]) }; |
|
ok( $@, 'Don\'t decrypt' ); |
|
|
1; |
isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' ); |
|
|
|
unlink($file); |
|
} |
|
|
|
1; |