root/honeyclient/branches/exp/kindlund-filesystem/t/Integrity.t

Revision 13, 5.4 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/Integrity.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 64 HoneyClient/Manager/FW/Integrity.pm
38
39 diag("Beginning of HoneyClient::Manager::FW::Integrity testing.");
40
41 # Make sure Log::Log4perl loads.
42 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."); }
43 require_ok('Log::Log4perl');
44 use Log::Log4perl;
45
46 # Make sure IO::File loads.
47 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."); }
48 require_ok('IO::File');
49 use IO::File;
50
51 # Make sure IPTables::IPv4 loads.
52 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."); }
53 require_ok('IPTables::IPv4');
54 use IPTables::IPv4;
55
56 # Make sure HoneyClient::Manager::FW loads.
57 BEGIN { use_ok('HoneyClient::Manager::FW') or diag("Can't load HoneyClient::Manager::FW package.  Check to make sure the package library is correctly listed within the path."); }
58 require_ok('HoneyClient::Manager::FW');
59 use HoneyClient::Manager::FW;
60
61 # Make sure HoneyClient::Util::Config loads.
62 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."); }
63 require_ok('HoneyClient::Util::Config');
64 can_ok('HoneyClient::Util::Config', 'getVar');
65 use HoneyClient::Util::Config qw(getVar);
66
67 # Make sure HoneyClient::Util::SOAP loads.
68 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."); }
69 require_ok('HoneyClient::Util::SOAP');
70 can_ok('HoneyClient::Util::SOAP', 'getServerHandle');
71 can_ok('HoneyClient::Util::SOAP', 'getClientHandle');
72 use HoneyClient::Util::SOAP qw(getServerHandle getClientHandle);
73
74
75 # test hashref used for Inline testing
76 my $hashref = {
77
78     'foo' => {   
79         'targets' => {   
80             'rcf.mitre.org'   => { 'tcp' => [ 80 ], },
81         },
82
83         'resources' => {
84             'http://www.mitre.org' => 1,
85         },
86         'sources' => {
87
88             '00:0C:29:94:B9:15' => {
89                 '10.0.0.128' => {   
90                     'tcp' => undef,
91                     'udp' => [ 23, 53, '80:1024', ],
92                 },
93             },
94         },
95     },
96 };
97
98 diag("Making sure needed files exist.\n");
99 ok( "-f  /var/log/iptables", '/var/log/iptables log file is present' );
100 ok(" -f  /sbin/iptables", 'IPTables binary does exist');
101 ok(" -d /tmp", '/tmp does exist');
102
103
104
105     undef $main::_STDOUT_;
106     undef $main::_STDERR_;
107 }
108
109 {
110     undef $main::_STDOUT_;
111     undef $main::_STDERR_;
112 #line 145 HoneyClient/Manager/FW/Integrity.pm
113
114 eval{
115      # yes, this test could of been written better
116      my $vmname = "chainfoo";
117     my $testfile = "/tmp/testfile.txt";
118     $URL = HoneyClient::Manager::FW->init_fw();
119     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.");
120     sleep 1;
121  # Wait at least a second, in order to initialize the daemon.
122     sleep 1;
123     # Connect to daemon as a client.
124     my $stub = getClientHandle("HoneyClient::Manager::FW");
125     diag("Calling fwInit()");
126     $som = $stub->fwInit($hashref);
127     diag("Calling addchain()");
128     $som = $stub->addChain($hashref);
129     diag("Calling addRule()");
130     $som = $stub->addRule($hashref);
131     diag("Creating test file and appending log entry...");
132     open(TEST, ">$testfile");
133     print TEST "Jun 24 20:43:52 HcHWALL kernel: VMID=foo IN=eth1 OUT= MAC=00:0c:29:fa:23:66:00:0c:29:94:b9:15:08:00 SRC=10.0.0.128 DST=128.29.239.232 LEN=44 TOS=0x00 PREC=0x00 TTL=32 ID=26351 PROTO=UDP SPT=1452 DPT=38293 LEN=24\n";
134     close TEST;
135     diag("Calling macCheck()...");
136     $som = $stub->macCheck($hashref, $vmname);
137     my @list = $som->paramsall;
138     my $value = scalar(@list);
139     ok( $value > 0,  'Defined data exists within either the @known or @unknown array' );
140     diag("Deleting our testfile now...");
141     unlink($testfile);
142     diag("Setting the Policy to ACCEPT");
143     $som = $stub->_setAcceptPolicy();
144     diag("Flushing all rules and chains");
145     $som = $stub->_flushChains();
146
147 };
148
149 # Kill the child daemon, if it still exists.
150 is(HoneyClient::Manager::FW->destroy_fw(), 1, "destroy_fw(), destruction of the firewall server") or diag("Unable to terminate FW");
151 HoneyClient::Manager::FW->destroy_fw();
152 sleep 1;
153
154 # Report any failure found.
155 if ($@) {
156     fail($@);
157     }
158    
159
160     undef $main::_STDOUT_;
161     undef $main::_STDERR_;
162 }
163
Note: See TracBrowser for help on using the browser.