Show
Ignore:
Timestamp:
06/17/07 17:21:39 (1 year ago)
Author:
kindlund
Message:

Merged DB branch into trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/trunk/t/honeyclient_agent_integrity_filesystem.t

    r328 r521  
    8585require_ok('HoneyClient::Agent::Integrity::Filesystem'); 
    8686use HoneyClient::Agent::Integrity::Filesystem; 
     87 
     88# Make sure DateTime loads. 
     89BEGIN { use_ok('DateTime') or diag("Can't load DateTime package.  Check to make sure the package library is correctly listed within the path."); } 
     90require_ok('DateTime'); 
     91use DateTime; 
     92 
     93# Make sure Digest::MD5 loads. 
     94BEGIN { use_ok('Digest::MD5') or diag("Can't load Digest::MD5 package.  Check to make sure the package library is correctly listed within the path."); } 
     95require_ok('Digest::MD5'); 
     96use Digest::MD5; 
     97 
     98# Make sure Digest::SHA loads. 
     99BEGIN { use_ok('Digest::SHA') or diag("Can't load Digest::SHA package.  Check to make sure the package library is correctly listed within the path."); } 
     100require_ok('Digest::SHA'); 
     101use Digest::SHA; 
     102 
     103# Make sure File::Type loads. 
     104BEGIN { use_ok('File::Type') or diag("Can't load File::Type package.  Check to make sure the package library is correctly listed within the path."); } 
     105require_ok('File::Type'); 
     106use File::Type; 
     107 
     108# Make sure IO::File loads. 
     109BEGIN { use_ok('IO::File') or diag("Can't load IO::File package.  Check to make sure the package library is correctly listed within the path."); } 
     110require_ok('IO::File'); 
     111use IO::File; 
    87112} 
    88113 
     
    159184close ADD_FILE; 
    160185 
     186my $md5_ctx = Digest::MD5->new(); 
     187my $sha1_ctx = Digest::SHA->new("1"); 
     188my $type_ctx = File::Type->new(); 
     189 
     190my $add_fh = IO::File->new($add_file, "r"); 
     191$md5_ctx->addfile($add_fh); 
     192my $add_file_md5 = $md5_ctx->hexdigest(); 
     193seek($add_fh, 0, 0); 
     194$sha1_ctx->addfile($add_fh); 
     195my $add_file_sha1 = $sha1_ctx->hexdigest(); 
     196undef $add_fh; 
     197my $add_file_type = $type_ctx->mime_type($add_file); 
     198 
    161199@file_attr = stat($add_file); 
    162200my $add_file_size  = $file_attr[7]; 
     
    168206close CHANGE_FILE; 
    169207 
     208my $change_fh = IO::File->new($change_file, "r"); 
     209$md5_ctx->addfile($change_fh); 
     210my $change_file_md5 = $md5_ctx->hexdigest(); 
     211seek($change_fh, 0, 0); 
     212$sha1_ctx->addfile($change_fh); 
     213my $change_file_sha1 = $sha1_ctx->hexdigest(); 
     214undef $change_fh; 
     215my $change_file_type = $type_ctx->mime_type($change_file); 
     216 
    170217@file_attr = stat($change_file); 
    171218my $change_file_size2  = $file_attr[7]; 
     
    173220 
    174221### Perform check. 
    175 my $foundChanges = $filesystem->check(); 
     222my $foundChanges = $filesystem->check(no_prepare => 1); 
    176223 
    177224# Uncomment these lines, if you want to see more 
     
    184231my $expectedChanges = [ 
    185232  { 
    186     'status' => 'changed'
     233    'status' => $HoneyClient::Agent::Integrity::Filesystem::STATUS_MODIFIED
    187234    'new' => { 
    188235        'name'  => $change_file, 
     
    197244  }, 
    198245  { 
    199     'status' => 'added'
     246    'status' => $HoneyClient::Agent::Integrity::Filesystem::STATUS_ADDED
    200247    'new' => { 
    201248        'name'  => $add_file, 
     
    205252  }, 
    206253  { 
    207     'status' => 'deleted'
     254    'status' => $HoneyClient::Agent::Integrity::Filesystem::STATUS_DELETED
    208255    'old' => { 
    209256        'name'  => $delete_file, 
     
    214261]; 
    215262 
    216 is_deeply($foundChanges, $expectedChanges, "check(monitored_directories => [ $monitor_dir ], ignored_entries => [ $monitor_dir ])") or diag("The check() call failed."); 
     263is_deeply($foundChanges, $expectedChanges, "check(no_prepare => 1)") or diag("The check() call failed."); 
     264 
     265### Perform check. 
     266$foundChanges = $filesystem->check(); 
     267 
     268# Uncomment these lines, if you want to see more 
     269# detailed information about the changes found. 
     270#$Data::Dumper::Terse = 0; 
     271#$Data::Dumper::Indent = 1; 
     272#diag(Dumper($foundChanges)); 
     273 
     274### Verify changes. 
     275$expectedChanges = [ 
     276  { 
     277    'status' => $HoneyClient::Agent::Integrity::Filesystem::STATUS_MODIFIED, 
     278    'name'  => HoneyClient::Agent::Integrity::Filesystem::_convertFilename($change_file), 
     279    'mtime' => HoneyClient::Agent::Integrity::Filesystem::_convertTime($change_file_mtime2), 
     280    'content' => { 
     281        'size'  => $change_file_size2, 
     282        'type'  => $change_file_type, 
     283        'sha1'  => $change_file_sha1, 
     284        'md5'   => $change_file_md5, 
     285    }, 
     286  }, 
     287  { 
     288    'status' => $HoneyClient::Agent::Integrity::Filesystem::STATUS_ADDED, 
     289    'name'  => HoneyClient::Agent::Integrity::Filesystem::_convertFilename($add_file), 
     290    'mtime' => HoneyClient::Agent::Integrity::Filesystem::_convertTime($add_file_mtime), 
     291    'content' => { 
     292        'size'  => $add_file_size, 
     293        'type'  => $add_file_type, 
     294        'sha1'  => $add_file_sha1, 
     295        'md5'   => $add_file_md5, 
     296    }, 
     297  }, 
     298  { 
     299    'status' => $HoneyClient::Agent::Integrity::Filesystem::STATUS_DELETED, 
     300    'name'  => HoneyClient::Agent::Integrity::Filesystem::_convertFilename($delete_file), 
     301    'mtime' => HoneyClient::Agent::Integrity::Filesystem::_convertTime($delete_file_mtime), 
     302  }, 
     303]; 
     304 
     305is_deeply($foundChanges, $expectedChanges, "check()") or diag("The check() call failed."); 
    217306 
    218307### Clean up test data.