| 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 |
|---|
| | 12 | BEGIN { 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 | } |
|---|
| | 24 | require_ok('Log::Log4perl'); |
|---|
| | 25 | use Log::Log4perl qw(:easy); |
|---|
| 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. |
|---|
| | 37 | Log::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 | }); |
|---|
| 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 |
|---|
| | 52 | BEGIN { 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."); } |
|---|
| 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(); |
|---|
| | 94 | isa_ok($integrity, 'HoneyClient::Agent::Integrity', "new()") or diag("The new() call failed."); |
|---|