version 1.4, 2007/02/01 01:56:11 |
version 1.7, 2007/02/18 16:19:12 |
|
|
# 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: keyring4.t,v 1.2 2007/02/18 05:39:32 andrew Exp $ |
|
use strict; |
|
use warnings; |
|
|
######################### We start with some black magic to print on failure. |
use Test::More 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-v4.pdb'; |
BEGIN { $| = 1; print "1..17\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 $pdb; |
my $record; |
my $record; |
|
my $decrypted; |
|
|
eval { $pdb = new Palm::Keyring($password) }; |
ok( $pdb = new Palm::Keyring($password), 'New Palm::Keyring'); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $record = $pdb->append_Record() }; |
ok( $record = $pdb->append_Record(), 'Append Record' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Encrypt($record, $acct, $password) || die }; |
ok( $pdb->Encrypt($record, $acct, $password), 'Encrypt account into record' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Write($file) }; |
ok( $pdb->Write($file), 'Write file' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$pdb = new Palm::PDB; |
$pdb = undef; |
$acct = {}; |
|
|
|
eval { $pdb->Load($file) }; |
ok( $pdb = new Palm::PDB(), 'New Palm::PDB' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $pdb->Password($password) || die }; |
ok( $pdb->Load($file), 'Load File' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die }; |
ok( $pdb->Password($password), 'Verify Password' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
if ($acct->{'password'} eq $password) { |
ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt record' ); |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
my $old_date = $acct->{'lastchange'}; |
is( $decrypted->{password}, $password, 'Got password' ); |
|
|
eval { $pdb->Password($password, $new_password) || die }; |
is_deeply( $decrypted, $acct, 'Account Matches' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$acct = {}; |
my $old_date = $decrypted->{'lastchange'}; |
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) { |
ok( $pdb->Password($password, $new_password), 'Change PDB Password' ); |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
my $new_date = $acct->{'lastchange'}; |
ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt with new password' ); |
|
|
if ( |
my $new_date = $decrypted->{'lastchange'}; |
$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++; |
|
|
|
|
is_deeply( $old_date, $new_date, 'Date didn\'t change' ); |
|
|
$acct->{'password'} = $new_password; |
$acct->{'password'} = $new_password; |
|
|
eval { $acct = $pdb->Encrypt($pdb->{'records'}->[1], $acct) || die }; |
ok( $pdb->Encrypt($pdb->{'records'}->[1], $acct), 'Change record' ); |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
$old_date = $new_date; |
ok( $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]), 'Decrypt new record' ); |
$new_date = $acct->{'lastchange'}; |
|
|
|
eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die }; |
$new_date = $decrypted->{'lastchange'}; |
unless( $@ ) { |
|
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
if ( |
my $od = join '/', map { $old_date->{$_} } sort keys %{ $old_date }; |
$old_date->{'day'} != $new_date->{'day'} || |
my $nd = join '/', map { $new_date->{$_} } sort keys %{ $new_date }; |
$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) { |
isnt( $od, $nd, 'Date changed'); |
print "ok $test\n"; |
|
} else { |
|
print "not ok $test\n"; |
|
} |
|
$test++; |
|
|
|
|
is( $decrypted->{password}, $new_password, 'Got new password' ); |
|
|
|
$decrypted = {}; |
|
ok( $pdb->Password(), 'Forget password' ); |
|
|
|
eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]) }; |
|
ok( $@, 'Don\'t decrypt' ); |
|
|
|
isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' ); |
|
|
unlink($file); |
unlink($file); |
|
|
1; |
1; |
|
|