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

Revision 234, 10.8 kB (checked in by kindlund, 2 years ago)

Version bump.

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 diag("Beginning of HoneyClient::Manager::FW testing.");
12 diag("Making sure all Modules are present");
13
14 # Make sure Log::Log4perl loads.
15 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."); }
16 require_ok('Log::Log4perl');
17 use Log::Log4perl;
18
19 # Make sure Filehandle loads.
20 BEGIN { use_ok('FileHandle') or diag("Can't load FileHandle package.  Check to make sure the package library is correctly listed within the path."); }
21 require_ok('FileHandle');
22 use FileHandle;
23
24 # Make sure IO::File loads.
25 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."); }
26 require_ok('IO::File');
27 use IO::File;
28
29 # Make sure IPTables::IPv4 loads.
30 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."); }
31 require_ok('IPTables::IPv4');
32 use IPTables::IPv4;
33
34 # Make sure Config::General loads.
35 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."); }
36 require_ok('Config::General');
37 use Config::General;
38
39 # Make sure use Data::Dumper loads.
40 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."); }
41 require_ok('Data::Dumper');
42 use Data::Dumper;
43
44 # Make sure use Net::DNS::Resolver loads.
45 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."); }
46 require_ok('Net::DNS::Resolver');
47 use Net::DNS::Resolver;
48
49 # Make sure use Time::HiRes loads.
50 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."); }
51 require_ok('Time::HiRes');
52 can_ok('Time::HiRes', 'gettimeofday');
53 use Time::HiRes qw(gettimeofday);
54
55 # Make sure use English loads.
56 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."); }
57 require_ok('English');
58 use English '-no_match_vars';
59
60 # Make sure use threads loads.
61 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."); }
62 require_ok('threads');
63 use threads;
64
65 # Make sure HoneyClient::Util::Config loads.
66 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."); }
67 require_ok('HoneyClient::Util::Config');
68 can_ok('HoneyClient::Util::Config', 'getVar');
69 use HoneyClient::Util::Config qw(getVar);
70
71 # Make sure the module loads properly, with the exportable
72 # functions shared.
73 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."); }
74 require_ok('HoneyClient::Manager::FW');
75 can_ok('HoneyClient::Manager::FW', 'init_fw');
76 can_ok('HoneyClient::Manager::FW', 'destroy_fw');
77 can_ok('HoneyClient::Manager::FW', '_getVMName');
78 use HoneyClient::Manager::FW qw(init_fw destroy_fw _getVMName);
79
80 # Make sure HoneyClient::Util::SOAP loads.
81 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."); }
82 require_ok('HoneyClient::Util::SOAP');
83 can_ok('HoneyClient::Util::SOAP', 'getServerHandle');
84 can_ok('HoneyClient::Util::SOAP', 'getClientHandle');
85 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle);
86
87 # Make sure use Proc::ProcessTable loads.
88 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."); }
89 require_ok('Proc::ProcessTable');
90 use Proc::ProcessTable;
91
92 diag("Making sure perl and shell scripts exist.\n");
93 ok( "-f /hc/startFWListener.pl", '/hc/startFWListener.pl is present' );
94 ok( "-f /hc/startLogListener.pl", '/hc/startLogListener.pl is present' );
95 ok( "-f /hc/startFWListener.sh", '/hc/startFWListener.sh is present' );
96 ok( "-f /hc/startLogListener.sh", '/hc/startLogListener.sh is present' );
97 ok( "-f  /etc/honeylog.conf", '/etc/honeylog.conf is present' );
98 ok("-f  /etc/honeyclient.conf", '/etc/honeyclient.conf exists');
99 #ok( -f , "/proc/sys/net/ipv4/ip_forward", '/proc/sys/net/ipv4/ip_forward does exist');
100 ok(" -f /etc/resolv.conf", '/etc/resolv.conf file does exist');
101 ok(" -f /etc/syslog.conf", '/etc/syslog.conf file does exist');
102 ok( "-f /usr/bin/uptime", '/usr/bin/uptime is present' );
103 ok(" -f /bin/uname", '/bin/uname exists');
104 ok(" -f /bin/mail", 'mail() exists');
105 ok(" -f /sbin/iptables", 'IPTables binary does exist');
106 diag("Enabling test hash reference here");
107 my $hashref = {
108
109     'foo' => {
110         'targets' => {
111             'rcf.mitre.org'   => { 'tcp' => [ 80 ], },
112         },
113
114         'resources' => {
115             'http://www.mitre.org' => 1,
116         },
117         'sources' => {
118
119             '00:0C:29:94:B9:15' => {
120                 '10.0.0.128' => {
121                     'tcp' => undef,
122                     'udp' => [ 23, 53, '80:1024', ],
123                 },
124             },
125         },
126     },
127 };
128
129 #my $hwall = getVar(name => "address");
130 #my $port = getVar(name => "port");
131
132 diag("Beginning our function testing now...");
133 $URL = HoneyClient::Manager::FW->init_fw();
134 is($URL, "http://192.168.0.129: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.");
135 sleep 3;
136 is(HoneyClient::Manager::FW->destroy_fw(), 1, "destroy_fw(), destruction of the firewall server") or diag("Unable to terminate FW");
137 sleep 1;
138 }
139
140
141
142 # =begin testing
143 {
144 eval{
145     diag("Testing fwInit()...");
146     $URL = HoneyClient::Manager::FW->init_fw();
147     # Wait at least a second, in order to initialize the daemon.
148     sleep(1);
149     # Connect to daemon as a client.
150     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
151     $som = $stub->fwInit($hashref);
152     $som = $stub->_validateInit();
153     is($som->result, 24, "fwInit current has set up 28 rules")   or diag("The fwInit() call failed.");
154     $som = $stub->_setAcceptPolicy();
155     $som = $stub->_flushChains();
156
157 };
158
159 # Kill the child daemon, if it still exists.
160 HoneyClient::Manager::FW->destroy_fw();
161 sleep(1);
162
163 # Report any failure found.
164 if ($@) {
165     fail($@);
166 }
167 }
168
169
170
171 # =begin testing
172 {
173 eval{
174     diag("Testing addChain()...");
175     $URL = HoneyClient::Manager::FW->init_fw();
176     # Wait at least a second, in order to initialize the daemon.
177     sleep 1;
178     # Connect to daemon as a client.
179     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
180     $som = $stub->addChain($hashref);
181     ok($som->result, "addChain() successfully passed.")   or diag("The addChain() call failed.");
182     $som = $stub->_setAcceptPolicy();
183     $som = $stub->_flushChains();
184 };
185
186 # Kill the child daemon, if it still exists.
187 HoneyClient::Manager::FW->destroy_fw();
188 sleep 1;
189
190 # Report any failure found.
191 if ($@) {
192     fail($@);
193     }
194 }
195
196
197
198 # =begin testing
199 {
200 eval{
201      diag("Testing deleteChain()...");
202     $URL = HoneyClient::Manager::FW->init_fw();
203     # Wait at least a second, in order to initialize the daemon.
204     sleep 1;
205     # Connect to daemon as a client.
206     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
207     $som = $stub->addChain($hashref);
208     sleep 1;
209     $som = $stub->deleteChain($hashref);
210     ok($som->result, "deleteChain() successfully passed.")   or diag("The deleteChain() call failed.");
211     $som = $stub->_setAcceptPolicy();
212     $som = $stub->_flushChains();
213
214 };
215
216 # Kill the child daemon, if it still exists.
217 HoneyClient::Manager::FW->destroy_fw();
218 sleep 1;
219
220 # Report any failure found.
221 if ($@) {
222     fail($@);
223     }
224 }
225
226
227
228 # =begin testing
229 {
230 eval{
231      diag("Testing addRule()...");
232     $URL = HoneyClient::Manager::FW->init_fw();
233     # Wait at least a second, in order to initialize the daemon.
234     sleep 1;
235     # Connect to daemon as a client.
236     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
237     my $som  = $stub->fwInit($hashref);
238     $som = $stub->addChain($hashref);
239     $som = $stub->addRule($hashref);
240     ok($som->result, "addRule() successfully passed and added a new rule.")   or diag("The addRule() call failed.");
241     $som = $stub->_setAcceptPolicy();
242     $som = $stub->_flushChains();
243 };
244
245 # Kill the child daemon, if it still exists.
246 HoneyClient::Manager::FW->destroy_fw();
247 sleep 1;
248
249 # Report any failure found.
250 if ($@) {
251     fail($@);
252     }
253 }
254
255
256
257 # =begin testing
258 {
259 eval{
260     diag("Testing fwStatus()...");
261     $URL = HoneyClient::Manager::FW->init_fw();
262     # Wait at least a second, in order to initialize the daemon.
263     sleep 1;
264     # Connect to daemon as a client.
265     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
266     $som = $stub->getStatus();
267     # testing to make sure the chains are empty
268     ok(!$som->result, "getStatus() successfully passed.")   or diag("The getStatus() call failed.");
269 #    $som = $stub->_setAcceptPolicy();
270 #    $som = $stub->_flushChains();
271 };
272
273 # Kill the child daemon, if it still exists.
274 HoneyClient::Manager::FW->destroy_fw();
275 sleep 1;
276
277 # Report any failure found.
278 if ($@) {
279     fail($@);
280     }
281 }
282
283
284
285 # =begin testing
286 {
287 eval{
288
289     diag("Testing _chainExists()...");
290     $URL = HoneyClient::Manager::FW->init_fw();
291     # Wait at least a second, in order to initialize the daemon.
292     sleep 1;
293     # Connect to daemon as a client.
294     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
295     my $som  = $stub->fwInit($hashref);
296     $som = $stub->addChain($hashref);
297     is($som->result, 1, "_chainExists($hashref) successfully passed.")  or diag("The _chainExists() call failed.");
298     $som = $stub->_setAcceptPolicy();
299     $som = $stub->_flushChains();
300 };
301
302 # Kill the child daemon, if it still exists.
303 HoneyClient::Manager::FW->destroy_fw();
304 sleep 1;
305
306 # Report any failure found.
307 if ($@) {
308     fail($@);
309     }
310 }
311
312
313
314 # =begin testing
315 {
316 eval{
317
318     $URL = HoneyClient::Manager::FW->init_fw();
319     # Wait at least a second, in order to initialize the daemon.
320     sleep 1;
321     # Connect to daemon as a client.
322     $stub = getClientHandle(namespace => "HoneyClient::Manager::FW");
323     $som = $stub->starttestProcess();
324     $som = $stub->fwShutdown();
325     $som = $stub->findProcess();
326    ok($som->result, "fwShutdown() successfully passed.")   or diag("The FWShutdown() call failed.");
327 };
328
329 # Kill the child daemon, if it still exists.
330 HoneyClient::Manager::FW->destroy_fw();
331 sleep 1;
332
333 # Report any failure found.
334 if ($@) {
335     fail($@);
336     }
337 }
338
339
340
341
342 1;
Note: See TracBrowser for help on using the browser.