[BACK]Return to keyring.t CVS log [TXT][DIR] Up to [local] / palm / Palm-Keyring / t

Diff for /palm/Palm-Keyring/t/keyring.t between version 1.6 and 1.7

version 1.6, 2007/02/17 23:36:05 version 1.7, 2007/02/18 16:19:12
Line 1 
Line 1 
 # 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..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 = {
Line 38 
Line 25 
   
 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++;  
   
 eval { $pdb->Password() || die };  is( $decrypted->{password}, $new_password, 'Got new password' );
 unless( $@ ) {  
         print "ok $test\n";  
 } else {  
         print "not ok $test\n";  
 }  
 $test++;  
   
 eval { $acct = $pdb->Decrypt($pdb->{'records'}->[1]) || die };  $decrypted = {};
 if ( $@ ) {  ok( $pdb->Password(), 'Forget password' );
         print "ok $test\n";  
 } else {  
         print "not ok $test\n";  
 }  
 $test++;  
   
 unless ($acct->{'password'} eq $password) {  eval{ $decrypted = $pdb->Decrypt($pdb->{'records'}->[1]) };
         print "ok $test\n";  ok( $@, 'Don\'t decrypt' );
 } else {  
         print "not ok $test\n";  
 }  
 $test++;  
   
   isnt( $decrypted->{password}, $new_password, 'Didn\'t get new password' );
   
 unlink($file);  unlink($file);
   
 1;  1;
   

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>