| | 87 | |
|---|
| | 88 | # Make sure DateTime loads. |
|---|
| | 89 | BEGIN { use_ok('DateTime') or diag("Can't load DateTime package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| | 90 | require_ok('DateTime'); |
|---|
| | 91 | use DateTime; |
|---|
| | 92 | |
|---|
| | 93 | # Make sure Digest::MD5 loads. |
|---|
| | 94 | BEGIN { 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."); } |
|---|
| | 95 | require_ok('Digest::MD5'); |
|---|
| | 96 | use Digest::MD5; |
|---|
| | 97 | |
|---|
| | 98 | # Make sure Digest::SHA loads. |
|---|
| | 99 | BEGIN { 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."); } |
|---|
| | 100 | require_ok('Digest::SHA'); |
|---|
| | 101 | use Digest::SHA; |
|---|
| | 102 | |
|---|
| | 103 | # Make sure File::Type loads. |
|---|
| | 104 | BEGIN { 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."); } |
|---|
| | 105 | require_ok('File::Type'); |
|---|
| | 106 | use File::Type; |
|---|
| | 107 | |
|---|
| | 108 | # Make sure IO::File loads. |
|---|
| | 109 | BEGIN { 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."); } |
|---|
| | 110 | require_ok('IO::File'); |
|---|
| | 111 | use IO::File; |
|---|
| | 186 | my $md5_ctx = Digest::MD5->new(); |
|---|
| | 187 | my $sha1_ctx = Digest::SHA->new("1"); |
|---|
| | 188 | my $type_ctx = File::Type->new(); |
|---|
| | 189 | |
|---|
| | 190 | my $add_fh = IO::File->new($add_file, "r"); |
|---|
| | 191 | $md5_ctx->addfile($add_fh); |
|---|
| | 192 | my $add_file_md5 = $md5_ctx->hexdigest(); |
|---|
| | 193 | seek($add_fh, 0, 0); |
|---|
| | 194 | $sha1_ctx->addfile($add_fh); |
|---|
| | 195 | my $add_file_sha1 = $sha1_ctx->hexdigest(); |
|---|
| | 196 | undef $add_fh; |
|---|
| | 197 | my $add_file_type = $type_ctx->mime_type($add_file); |
|---|
| | 198 | |
|---|
| 216 | | is_deeply($foundChanges, $expectedChanges, "check(monitored_directories => [ $monitor_dir ], ignored_entries => [ $monitor_dir ])") or diag("The check() call failed."); |
|---|
| | 263 | is_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 | |
|---|
| | 305 | is_deeply($foundChanges, $expectedChanges, "check()") or diag("The check() call failed."); |
|---|