root/honeyclient/tags/exp/PRE-kindlund-test/t/FW.t

Revision 13, 12.6 kB (checked in by kindlund, 2 years ago)

Initialized public repository with 0.9 release.

Line 
1 #!/usr/bin/perl -w
2
3 use Test::More 'no_plan';
4
5 package Catch;
6
7 sub TIEHANDLE {
8     my($class, $var) = @_;
9     return bless { var => $var }, $class;
10 }
11
12 sub PRINT  {
13     my($self) = shift;
14     ${'main::'.$self->{var}} .= join '', @_;
15 }
16
17 sub OPEN  {}    # XXX Hackery in case the user redirects
18 sub CLOSE {}    # XXX STDERR/STDOUT.  This is not the behavior we want.
19
20 sub READ {}
21 sub READLINE {}
22 sub GETC {}
23 sub BINMODE {}
24
25 my $Original_File = 'HoneyClient/Manager/FW.pm';
26
27 package main;
28
29 # pre-5.8.0's warns aren't caught by a tied STDERR.
30 $SIG{__WARN__} = sub { $main::_STDERR_ .= join '', @_; };
31 tie *STDOUT, 'Catch', '_STDOUT_' or die $!;
32 tie *STDERR, 'Catch', '_STDERR_' or die $!;
33
34 {
35     undef $main::_STDOUT_;
36     undef $main::_STDERR_;
37 #line 172 HoneyClient/Manager/FW.pm
38
39 diag("Beginning of HoneyClient::Manager::FW testing.");
40 diag("Making sure all Modules are present");
41
42 # Make sure Log::Log4perl loads.
43 BEGIN { use_ok('Log::Log4perl') or diag("Can't load Log::Log4perl package.  Check to make sure the package library is correctly listed within the path."); }
44 require_ok('Log::Log4perl');
45 use Log::Log4perl;
46
47 # Make sure Filehandle loads.
48 BEGIN { use_ok('FileHandle') or diag("Can't load FileHandle package.  Check to make sure the package library is correctly listed within the path."); }
49 require_ok('FileHandle');
50 use FileHandle;
51
52 # Make sure IO::File loads.
53 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."); }
54 require_ok('IO::File');
55 use IO::File;
56
57 # Make sure IPTables::IPv4 loads.
58 BEGIN { use_ok('IPTables::IPv4') or diag("Can't load IPTables::IPv4 package.  Check to make sure the package library is correctly listed within the path."); }
59 require_ok('IPTables::IPv4');
60 use IPTables::IPv4;
61
62 # Make sure Config::General loads.
63 BEGIN { use_ok('Config::General') or diag("Can't load Config::General package.  Check to make sure the package library is correctly listed within the path."); }
64 require_ok('Config::General');
65 use Config::General;
66
67 # Make sure use Data::Dumper loads.
68 BEGIN { use_ok('Data::Dumper') or diag("Can't load use Data::Dumper package.  Check to make sure the package library is correctly listed within the path."); }
69 require_ok('Data::Dumper');
70 use Data::Dumper;
71
72 # Make sure use Net::DNS::Resolver loads.
73 BEGIN { use_ok('Net::DNS::Resolver') or diag("Can't load use Net::DNS::Resolver package.  Check to make sure the package library is correctly listed within the path."); }
74 require_ok('Net::DNS::Resolver');
75 use Net::DNS::Resolver;
76
77 # Make sure use Time::HiRes loads.
78 BEGIN { use_ok('Time::HiRes', qw(gettimeofday)) or diag("Can't load use Time::HiRes package.  Check to make sure the package library is correctly listed within the path."); }
79 require_ok('Time::HiRes');
80 can_ok('Time::HiRes', 'gettimeofday');
81 use Time::HiRes qw(gettimeofday);
82
83 # Make sure use English loads.
84 BEGIN { use_ok('English') or diag("Can't load use English package.  Check to make sure the package library is correctly listed within the path."); }
85 require_ok('English');
86 use English;
87
88 # Make sure use threads loads.
89 BEGIN { use_ok('threads') or diag("Can't load use threads package.  Check to make sure the package library is correctly listed within the path."); }
90 require_ok('threads');
91 use threads;
92
93 # Make sure HoneyClient::Util::Config loads.
94 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."); }
95 require_ok('HoneyClient::Util::Config');
96 can_ok('HoneyClient::Util::Config', 'getVar');
97 use HoneyClient::Util::Config qw(getVar);
98
99 # Make sure the module loads properly, with the exportable
100 # functions shared.
101 BEGIN { use_ok('HoneyClient::Manager::FW', qw(init_fw destroy_fw _getVMName)) or diag("Can't load HoneyClient::Manager:VM package.  Check to make sure the package library is correctly listed within the path."); }
102 require_ok('HoneyClient::Manager::FW');
103 can_ok('HoneyClient::Manager::FW', 'init_fw');
104 can_ok('HoneyClient::Manager::FW', 'destroy_fw');
105 can_ok('HoneyClient::Manager::FW', '_getVMName');
106 use HoneyClient::Manager::FW qw(init_fw destroy_fw _getVMName);
107
108 # Make sure HoneyClient::Util::SOAP loads.
109 BEGIN { use_ok('HoneyClient::Util::SOAP', qw(getServerHandle getClientHandle)) or diag("Can't load HoneyClient::Util::SOAP package.  Check to make sure the package library is correctly listed within the path."); }
110 require_ok('HoneyClient::Util::SOAP');
111 can_ok('HoneyClient::Util::SOAP', 'getServerHandle');
112 can_ok('HoneyClient::Util::SOAP', 'getClientHandle');
113 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle);
114
115 # Make sure use Proc::ProcessTable loads.
116 BEGIN { use_ok('Proc::ProcessTable') or diag("Can't load use Proc::ProcessTable package.  Check to make sure the package library is correctly listed within the path."); }
117 require_ok('Proc::ProcessTable');
118 use Proc::ProcessTable;
119
120 diag("Making sure perl and shell scripts exist.\n");
121 ok( "-f /hc/startFWListener.pl", '/hc/startFWListener.pl is present' );
122 ok( "-f /hc/startLogListener.pl", '/hc/startLogListener.pl is present' );
123 ok( "-f /hc/startFWListener.sh", '/hc/startFWListener.sh is present' );
124 ok( "-f /hc/startLogListener.sh", '/hc/startLogListener.sh is present' );
125 ok( "-f  /etc/honeylog.conf", '/etc/honeylog.conf is present' );
126 ok("-f  /etc/honeyclient.conf", '/etc/honeyclient.conf exists');
127 #ok( -f , "/proc/sys/net/ipv4/ip_forward", '/proc/sys/net/ipv4/ip_forward does exist');
128 ok(" -f /etc/resolv.conf", '/etc/resolv.conf file does exist');
129 ok(" -f /etc/syslog.conf", '/etc/syslog.conf file does exist');
130 ok( "-f /usr/bin/uptime", '/usr/bin/uptime is present' );
131 ok(" -f /bin/uname", '/bin/uname exists');
132 ok(" -f /bin/mail", 'mail() exists');
133 ok(" -f /sbin/iptables", 'IPTables binary does exist');
134 diag("Enabling test hash reference here");
135 my $hashref = {
136
137     'foo' => {   
138         'targets' => {   
139             'rcf.mitre.org'   => { 'tcp' => [ 80 ], },
140         },
141
142         'resources' => {
143             'http://www.mitre.org' => 1,
144         },
145         'sources' => {
146
147             '00:0C:29:94:B9:15' => {
148                 '10.0.0.128' => {   
149                     'tcp' => undef,
150                     'udp' => [ 23, 53, '80:1024', ],
151                 },
152             },
153         },
154     },
155 };
156
157 #my $hwall = getVar("address");
158 #my $port = getVar("port");
159
160 diag("Beginning our function testing now...");
161 $URL = HoneyClient::Manager::FW->init_fw();
162 is($URL, "http://192.168.0.128:8083/", "testing init_fw(), creation of the firewall server") or diag("Failed to start up the FW SOAP server.  Check to see if any other daemon is listening on TCP port $PORT.");
163 sleep 3;
164 is(HoneyClient::Manager::FW->destroy_fw(), 1, "destroy_fw(), destruction of the firewall server") or diag("Unable to terminate FW");
165 sleep 1;
166
167
168     undef $main::_STDOUT_;
169     undef $main::_STDERR_;
170 }
171
172 {
173     undef $main::_STDOUT_;
174     undef $main::_STDERR_;
175 #line 370 HoneyClient/Manager/FW.pm
176
177 eval{
178     diag("Testing fwInit()...");
179     $URL = HoneyClient::Manager::FW->init_fw();
180     # Wait at least a second, in order to initialize the daemon.
181     sleep 1;
182     # Connect to daemon as a client.
183     $stub = getClientHandle("HoneyClient::Manager::FW");
184     $som = $stub->fwInit($hashref);
185     $som = $stub->_validateInit();
186     is($som->result, 28, "fwInit current has set up 28 rules")   or diag("The fwInit() call failed.");
187     $som = $stub->_setAcceptPolicy();
188     $som = $stub->_flushChains();
189    
190 };
191
192 # Kill the child daemon, if it still exists.
193 HoneyClient::Manager::FW->destroy_fw();
194 sleep 1;
195
196 # Report any failure found.
197 if ($@) {
198     fail($@);
199     }
200    
201
202     undef $main::_STDOUT_;
203     undef $main::_STDERR_;
204 }
205
206 {
207     undef $main::_STDOUT_;
208     undef $main::_STDERR_;
209 #line 685 HoneyClient/Manager/FW.pm
210
211 eval{
212     diag("Testing addChain()...");
213     $URL = HoneyClient::Manager::FW->init_fw();
214     # Wait at least a second, in order to initialize the daemon.
215     sleep 1;
216     # Connect to daemon as a client.
217     $stub = getClientHandle("HoneyClient::Manager::FW");
218     $som = $stub->addChain($hashref);
219     ok($som->result, "addChain() successfully passed.")   or diag("The addChain() call failed.");
220     $som = $stub->_setAcceptPolicy();
221     $som = $stub->_flushChains();
222 };
223
224 # Kill the child daemon, if it still exists.
225 HoneyClient::Manager::FW->destroy_fw();
226 sleep 1;
227
228 # Report any failure found.
229 if ($@) {
230     fail($@);
231     }
232    
233
234     undef $main::_STDOUT_;
235     undef $main::_STDERR_;
236 }
237
238 {
239     undef $main::_STDOUT_;
240     undef $main::_STDERR_;
241 #line 779 HoneyClient/Manager/FW.pm
242
243 eval{
244      diag("Testing deleteChain()...");
245     $URL = HoneyClient::Manager::FW->init_fw();
246     # Wait at least a second, in order to initialize the daemon.
247     sleep 1;
248     # Connect to daemon as a client.
249     $stub = getClientHandle("HoneyClient::Manager::FW");
250     $som = $stub->addChain($hashref);
251     sleep 1;
252     $som = $stub->deleteChain($hashref);
253     ok($som->result, "deleteChain() successfully passed.")   or diag("The deleteChain() call failed.");
254     $som = $stub->_setAcceptPolicy();
255     $som = $stub->_flushChains();
256
257 };
258
259 # Kill the child daemon, if it still exists.
260 HoneyClient::Manager::FW->destroy_fw();
261 sleep 1;
262
263 # Report any failure found.
264 if ($@) {
265     fail($@);
266     }
267    
268
269     undef $main::_STDOUT_;
270     undef $main::_STDERR_;
271 }
272
273 {
274     undef $main::_STDOUT_;
275     undef $main::_STDERR_;
276 #line 972 HoneyClient/Manager/FW.pm
277
278 eval{
279      diag("Testing addRule()...");
280     $URL = HoneyClient::Manager::FW->init_fw();
281     # Wait at least a second, in order to initialize the daemon.
282     sleep 1;
283     # Connect to daemon as a client.
284     $stub = getClientHandle("HoneyClient::Manager::FW");
285     my $som  = $stub->fwInit($hashref);
286     $som = $stub->addChain($hashref);
287     $som = $stub->addRule($hashref);
288     ok($som->result, "addRule() successfully passed and added a new rule.")   or diag("The addRule() call failed.");
289     $som = $stub->_setAcceptPolicy();
290     $som = $stub->_flushChains();
291 };
292
293 # Kill the child daemon, if it still exists.
294 HoneyClient::Manager::FW->destroy_fw();
295 sleep 1;
296
297 # Report any failure found.
298 if ($@) {
299     fail($@);
300     }
301
302
303     undef $main::_STDOUT_;
304     undef $main::_STDERR_;
305 }
306
307 {
308     undef $main::_STDOUT_;
309     undef $main::_STDERR_;
310 #line 2131 HoneyClient/Manager/FW.pm
311
312 eval{
313     diag("Testing fwStatus()...");
314     $URL = HoneyClient::Manager::FW->init_fw();
315     # Wait at least a second, in order to initialize the daemon.
316     sleep 1;
317     # Connect to daemon as a client.
318     $stub = getClientHandle("HoneyClient::Manager::FW");
319     $som = $stub->getStatus();
320     # testing to make sure the chains are empty
321     ok(!$som->result, "getStatus() successfully passed.")   or diag("The getStatus() call failed.");
322 #    $som = $stub->_setAcceptPolicy();
323 #    $som = $stub->_flushChains();
324 };
325
326 # Kill the child daemon, if it still exists.
327 HoneyClient::Manager::FW->destroy_fw();
328 sleep 1;
329
330 # Report any failure found.
331 if ($@) {
332     fail($@);
333     }
334
335
336     undef $main::_STDOUT_;
337     undef $main::_STDERR_;
338 }
339
340 {
341     undef $main::_STDOUT_;
342     undef $main::_STDERR_;
343 #line 2348 HoneyClient/Manager/FW.pm
344
345 eval{
346
347     diag("Testing _chainExists()...");
348     $URL = HoneyClient::Manager::FW->init_fw();
349     # Wait at least a second, in order to initialize the daemon.
350     sleep 1;
351     # Connect to daemon as a client.
352     $stub = getClientHandle("HoneyClient::Manager::FW");
353     my $som  = $stub->fwInit($hashref);
354     $som = $stub->addChain($hashref);
355     is($som->result, 1, "_chainExists($hashref) successfully passed.")  or diag("The _chainExists() call failed.");
356     $som = $stub->_setAcceptPolicy();
357     $som = $stub->_flushChains();
358 };
359
360 # Kill the child daemon, if it still exists.
361 HoneyClient::Manager::FW->destroy_fw();
362 sleep 1;
363
364 # Report any failure found.
365 if ($@) {
366     fail($@);
367     }
368
369
370     undef $main::_STDOUT_;
371     undef $main::_STDERR_;
372 }
373
374 {
375     undef $main::_STDOUT_;
376     undef $main::_STDERR_;
377 #line 2484 HoneyClient/Manager/FW.pm
378
379 eval{
380    
381     $URL = HoneyClient::Manager::FW->init_fw();
382     # Wait at least a second, in order to initialize the daemon.
383     sleep 1;
384     # Connect to daemon as a client.
385     $stub = getClientHandle("HoneyClient::Manager::FW");
386     $som = $stub->starttestProcess();
387     $som = $stub->fwShutdown();
388     $som = $stub->findProcess();
389    ok($som->result, "fwShutdown() successfully passed.")   or diag("The FWShutdown() call failed.");
390 };
391
392 # Kill the child daemon, if it still exists.
393 HoneyClient::Manager::FW->destroy_fw();
394 sleep 1;
395
396 # Report any failure found.
397 if ($@) {
398     fail($@);
399     }
400
401
402     undef $main::_STDOUT_;
403     undef $main::_STDERR_;
404 }
405
Note: See TracBrowser for help on using the browser.