root/honeyclient/tags/rel/0.9.2/t/honeyclient_agent_integrity.t

Revision 130, 5.7 kB (checked in by kindlund, 2 years ago)

sc: merging branch using tags svn+ssh://kindlund@www.honeyclient.org/home/svn/honeyclient/honeyclient/tags/bug/PRE-42 and svn+ssh://kindlund@www.honeyclient.org/home/svn/honeyclient/honeyclient/tags/bug/POST-42

Line 
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More 'no_plan';
5 $| = 1;
6
7
8
9 # =begin testing
10 {
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);
20
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."); }
23 require_ok('HoneyClient::Util::Config');
24 can_ok('HoneyClient::Util::Config', 'getVar');
25 use HoneyClient::Util::Config qw(getVar);
26
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;
32
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;
37
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."); }
47 require_ok('Storable');
48 can_ok('Storable', 'dclone');
49 can_ok('Storable', 'nfreeze');
50 can_ok('Storable', 'thaw');
51 use Storable qw(dclone nfreeze thaw);
52
53 ###Testing Globals###
54 # Directory where the known-good test files are stored
55 $test_dir = getVar(name => "test_dir");
56
57 # List of files and directories to check during filesystem checking
58 $file_checklist = getVar(name => "file_checklist");
59
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");
66 }
67
68
69
70 # =begin testing
71 {
72 #Testing initFileSystem();
73
74 my $ob = HoneyClient::Agent::Integrity->new();
75
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');
86
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");
158 }
159
160
161
162
163 1;
Note: See TracBrowser for help on using the browser.