Show
Ignore:
Timestamp:
05/06/07 20:43:06 (2 years ago)
Author:
kindlund
Message:

merged filesystem exp branch back into trunk

Files:

Legend:

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

    r131 r328  
    99# =begin testing 
    1010{ 
    11 # Make sure HoneyClient::Agent::Integrity loads. 
    12 BEGIN { use_ok('HoneyClient::Agent::Integrity', qw(initAll checkAll initRegistry checkRegistry initFileSystem checkFileSystem)) or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path."); } 
    13 require_ok('HoneyClient::Agent::Integrity'); 
    14 #can_ok('HoneyClient::Agent::Integrity', 'new'); 
    15 can_ok('HoneyClient::Agent::Integrity', 'initAll'); 
    16 can_ok('HoneyClient::Agent::Integrity', 'checkAll'); 
    17 can_ok('HoneyClient::Agent::Integrity', 'initFileSystem'); 
    18 can_ok('HoneyClient::Agent::Integrity', 'checkFileSystem'); 
    19 use HoneyClient::Agent::Integrity qw(initAll checkAll initFileSystem checkFileSystem); 
     11# Make sure Log::Log4perl loads 
     12BEGIN { use_ok('Log::Log4perl', qw(:nowarn)) 
     13        or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path."); 
     14        
     15        # Suppress all logging messages, since we need clean output for unit testing. 
     16        Log::Log4perl->init({ 
     17            "log4perl.rootLogger"                               => "DEBUG, Buffer", 
     18            "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer", 
     19            "log4perl.appender.Buffer.min_level"                => "fatal", 
     20            "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout", 
     21            "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 
     22        }); 
     23
     24require_ok('Log::Log4perl'); 
     25use Log::Log4perl qw(:easy); 
    2026 
    21 # Make sure HoneyClient::Util::Config loads. 
    22 BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path."); } 
     27# Make sure the module loads properly, with the exportable 
     28# functions shared. 
     29BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar setVar))  
     30        or diag("Can't load HoneyClient::Util::Config package.  Check to make sure the package library is correctly listed within the path."); } 
    2331require_ok('HoneyClient::Util::Config'); 
    2432can_ok('HoneyClient::Util::Config', 'getVar'); 
    25 use HoneyClient::Util::Config qw(getVar); 
     33can_ok('HoneyClient::Util::Config', 'setVar'); 
     34use HoneyClient::Util::Config qw(getVar setVar); 
    2635 
    27 # Make sure File::Find loads. 
    28 BEGIN { use_ok('File::Find', qw(find)) or diag("Can't load File::Find package.  Check to make sure the package library is correctly listed within the path."); } 
    29 require_ok('File::Find'); 
    30 can_ok('File::Find', 'find'); 
    31 use File::Find; 
     36# Suppress all logging messages, since we need clean output for unit testing. 
     37Log::Log4perl->init({ 
     38    "log4perl.rootLogger"                               => "DEBUG, Buffer", 
     39    "log4perl.appender.Buffer"                          => "Log::Log4perl::Appender::TestBuffer", 
     40    "log4perl.appender.Buffer.min_level"                => "fatal", 
     41    "log4perl.appender.Buffer.layout"                   => "Log::Log4perl::Layout::PatternLayout", 
     42    "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", 
     43}); 
    3244 
    33 # Make sure Digest::MD5 loads. 
    34 #BEGIN { use_ok('Digest::MD5', qw(new)) or diag("Can't load Digest::MD5 package.  Check to make sure the package library is correctly listed within the path."); } 
    35 #require_ok('Digest::MD5'); 
    36 #use Digest::MD5; 
     45# Make sure Data::Dumper loads 
     46BEGIN { use_ok('Data::Dumper') 
     47        or diag("Can't load Data::Dumper package. Check to make sure the package library is correctly listed within the path."); } 
     48require_ok('Data::Dumper'); 
     49use Data::Dumper; 
    3750 
    38 # Make sure MIME::Base64 loads. 
    39 BEGIN { use_ok('MIME::Base64', qw(encode_base64 decode_base64)) or diag("Can't load MIME::Base64 package.  Check to make sure the package library is correctly listed within the path."); } 
    40 require_ok('MIME::Base64'); 
    41 can_ok('MIME::Base64', 'encode_base64'); 
    42 can_ok('MIME::Base64', 'decode_base64'); 
    43 use MIME::Base64 qw(encode_base64 decode_base64); 
    44  
    45 # Make sure Storable loads. 
    46 BEGIN { use_ok('Storable', qw(dclone nfreeze thaw)) or diag("Can't load Storable package.  Check to make sure the package library is correctly listed within the path."); } 
     51# Make sure Storable loads 
     52BEGIN { use_ok('Storable', qw(nfreeze thaw dclone)) 
     53        or diag("Can't load Storable package. Check to make sure the package library is correctly listed within the path."); } 
    4754require_ok('Storable'); 
    48 can_ok('Storable', 'dclone'); 
    4955can_ok('Storable', 'nfreeze'); 
    5056can_ok('Storable', 'thaw'); 
    51 use Storable qw(dclone nfreeze thaw); 
     57can_ok('Storable', 'dclone'); 
     58use Storable qw(nfreeze thaw dclone); 
    5259 
    53 ###Testing Globals### 
    54 # Directory where the known-good test files are stored 
    55 $test_dir = getVar(name => "test_dir"); 
     60# Make sure HoneyClient::Agent::Integrity::Registry loads 
     61BEGIN { use_ok('HoneyClient::Agent::Integrity::Registry') 
     62        or diag("Can't load HoneyClient::Agent::Integrity::Registry package. Check to make sure the package library is correctly listed within the path."); } 
     63require_ok('HoneyClient::Agent::Integrity::Registry'); 
     64use HoneyClient::Agent::Integrity::Registry; 
    5665 
    57 # List of files and directories to check during filesystem checking 
    58 $file_checklist = getVar(name => "file_checklist"); 
     66# Make sure HoneyClient::Agent::Integrity::Filesystem loads 
     67BEGIN { use_ok('HoneyClient::Agent::Integrity::Filesystem') 
     68        or diag("Can't load HoneyClient::Agent::Integrity::Filesystem package. Check to make sure the package library is correctly listed within the path."); } 
     69require_ok('HoneyClient::Agent::Integrity::Filesystem'); 
     70use HoneyClient::Agent::Integrity::Filesystem; 
    5971 
    60 # List of files or directories to exclude if found in subdirs during 
    61 # filesystem check. 
    62 $file_exclude = getVar(name => "file_exclude"); 
    63  
    64 # File where found changes are written to 
    65 $change_file = getVar(name => "change_file"); 
     72# Make sure HoneyClient::Agent::Integrity loads. 
     73BEGIN { use_ok('HoneyClient::Agent::Integrity') or diag("Can't load HoneyClient::Agent::Integrity package.  Check to make sure the package library is correctly listed within the path."); } 
     74require_ok('HoneyClient::Agent::Integrity'); 
     75use HoneyClient::Agent::Integrity; 
    6676} 
    6777 
     
    7080# =begin testing 
    7181{ 
    72 #Testing initFileSystem(); 
     82diag("These tests will create temporary files in /tmp.  Be sure to cleanup this directory, if any of these tests fail."); 
    7383 
    74 my $ob = HoneyClient::Agent::Integrity->new(); 
     84# Create a generic Integrity object, with test state data. 
     85my $integrity = HoneyClient::Agent::Integrity->new(test => 1, bypass_baseline => 1); 
     86is($integrity->{test}, 1, "new(test => 1, bypass_baseline => 1)") or diag("The new() call failed."); 
     87isa_ok($integrity, 'HoneyClient::Agent::Integrity', "new(test => 1, bypass_baseline => 1)") or diag("The new() call failed."); 
    7588 
    76 system("mkdir /tmp/hc_test_dir"); 
    77 system("echo hi > /tmp/hc_test_dir/hi.txt"); 
    78 system("echo /tmp/hc_test_dir/hi.txt > $file_checklist"); 
    79 system("echo /tmp/hc_test_dir/hi.txt > $file_exclude"); 
    80 $ob->initFileSystem(); 
    81 open (FILE, "cleanfile.txt") or die "Can't check the cleanfile.txt\n"; 
    82 @result = <FILE>; 
    83 close FILE; 
    84 #Bad test because it will be empty in the case of an error anyway? 
    85 is(scalar(@result), 0, 'initFileSystem: Explicit Filesystem Omission'); 
     89diag("Performing baseline check of the system; this may take some time..."); 
    8690 
    87 system("rm $file_exclude"); 
    88 system("echo hi > /tmp/hc_test_dir/hi.txt"); 
    89 system("echo /tmp/hc_test_dir/hi.txt > $file_checklist"); 
    90 system("echo /tmp/hc_test_dir/ > $file_exclude"); 
    91 $ob->initFileSystem(); 
    92 open (FILE, "cleanfile.txt") or die "Can't check the cleanfile.txt\n"; 
    93 @result = <FILE>; 
    94 close FILE; 
    95 #Bad test because it will be empty in the case of an error anyway? 
    96 is(scalar(@result), 0, 'initFileSystem: Directory Filesystem Omission'); 
    97  
    98 system("rm $file_exclude"); 
    99 system("echo hi > /tmp/hc_test_dir/hi.txt"); 
    100 system("echo /tmp/hc_test_dir/hi.txt > $file_checklist"); 
    101 $ob->initFileSystem(); 
    102 open (DIFF, "diff $test_dir/fs1.txt cleanfile.txt |") or die "Can't check the cleanfile.txt\n"; 
    103 @result = <DIFF>; 
    104 close DIFF; 
    105 #Bad test because it will be empty in the case of an error anyway? 
    106 is(scalar(@result), 0, 'initFileSystem: Known-good file hash'); 
    107  
    108 system("rm -rf /tmp/hc_test_dir/"); 
    109 system("rm $file_checklist"); 
    110 
    111  
    112  
    113  
    114 # =begin testing 
    115 
    116 #Testing that checkFileSystem() 
    117  
    118 my $ob = HoneyClient::Agent::Integrity->new(); 
    119 my @result; 
    120  
    121 #add 
    122 system("rm $change_file"); 
    123 system("mkdir /tmp/hc_test_dir/"); 
    124 system("echo hi > /tmp/hc_test_dir/hi.txt"); 
    125 system("echo /tmp/hc_test_dir/ > $file_checklist"); 
    126 $ob->initFileSystem(); 
    127 system("echo hi > /tmp/hc_test_dir/hi2.txt"); 
    128 $ob->checkFileSystem(); 
    129 open(CHECK, "diff $test_dir/fs2.txt $change_file |") or die "There was a problem doing the fs2.txt diff";  
    130 #XXX Won't the die statement just be masked by the redirection of stdout/stderr? 
    131 @result = <CHECK>; 
    132 close(CHECK); 
    133 is(scalar(@result), 0, "checkFileSystem: Files added"); 
    134  
    135  
    136 #delete 
    137 system("rm $change_file"); 
    138 system("rm /tmp/hc_test_dir/hi.txt"); 
    139 $ob->checkFileSystem(); 
    140 open(CHECK, "diff $test_dir/fs3.txt $change_file |") or die "There was a problem doing the fs2.txt diff";  
    141 #XXX Won't the die statement just be masked by the redirection of stdout/stderr? 
    142 @result = <CHECK>; 
    143 close(CHECK); 
    144 is(scalar(@result), 0, "checkFileSystem: Files deleted"); 
    145  
    146 #change 
    147 system("rm $change_file"); 
    148 system("echo again >> /tmp/hc_test_dir/hi.txt"); 
    149 $ob->checkFileSystem(); 
    150 open(CHECK, "diff $test_dir/fs4.txt $change_file |") or die "There was a problem doing the fs2.txt diff";  
    151 #XXX Won't the die statement just be masked by the redirection of stdout/stderr? 
    152 @result = <CHECK>; 
    153 close(CHECK); 
    154 is(scalar(@result), 0, "checkFileSystem: Files changed"); 
    155  
    156 system("rm -rf /tmp/hc_test_dir/"); 
    157 system("rm $file_checklist"); 
     91# XXX: Uncomment this next check, eventually.  (It's commented out right now, in order to save some time). 
     92# Perform baseline. 
     93$integrity = HoneyClient::Agent::Integrity->new(); 
     94isa_ok($integrity, 'HoneyClient::Agent::Integrity', "new()") or diag("The new() call failed."); 
    15895} 
    15996