| | 116 | # Make sure Log::Log4perl loads |
|---|
| | 117 | BEGIN { use_ok('Log::Log4perl', qw(:nowarn)) |
|---|
| | 118 | or diag("Can't load Log::Log4perl package. Check to make sure the package library is correctly listed within the path."); |
|---|
| | 119 | |
|---|
| | 120 | # Suppress all logging messages, since we need clean output for unit testing. |
|---|
| | 121 | Log::Log4perl->init({ |
|---|
| | 122 | "log4perl.rootLogger" => "DEBUG, Buffer", |
|---|
| | 123 | "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", |
|---|
| | 124 | "log4perl.appender.Buffer.min_level" => "fatal", |
|---|
| | 125 | "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", |
|---|
| | 126 | "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", |
|---|
| | 127 | }); |
|---|
| | 128 | } |
|---|
| | 129 | require_ok('Log::Log4perl'); |
|---|
| | 130 | use Log::Log4perl qw(:easy); |
|---|
| | 131 | |
|---|
| | 132 | # Make sure HoneyClient::Util::Config loads. |
|---|
| | 133 | BEGIN { use_ok('HoneyClient::Util::Config', qw(getVar)) |
|---|
| | 134 | or diag("Can't load HoneyClient::Util::Config package. Check to make sure the package library is correctly listed within the path."); |
|---|
| | 135 | |
|---|
| | 136 | # Suppress all logging messages, since we need clean output for unit testing. |
|---|
| | 137 | Log::Log4perl->init({ |
|---|
| | 138 | "log4perl.rootLogger" => "DEBUG, Buffer", |
|---|
| | 139 | "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", |
|---|
| | 140 | "log4perl.appender.Buffer.min_level" => "fatal", |
|---|
| | 141 | "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", |
|---|
| | 142 | "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", |
|---|
| | 143 | }); |
|---|
| | 144 | |
|---|
| | 145 | } |
|---|
| | 146 | require_ok('HoneyClient::Util::Config'); |
|---|
| | 147 | can_ok('HoneyClient::Util::Config', 'getVar'); |
|---|
| | 148 | use HoneyClient::Util::Config qw(getVar); |
|---|
| | 149 | |
|---|
| | 150 | # Make sure the module loads properly, with the exportable |
|---|
| | 151 | # functions shared. |
|---|
| | 152 | BEGIN { use_ok('HoneyClient::Agent::Driver::Browser::IE') or diag("Can't load HoneyClient::Agent::Driver::Browser::IE package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| | 153 | require_ok('HoneyClient::Agent::Driver::Browser::IE'); |
|---|
| | 154 | can_ok('HoneyClient::Agent::Driver::Browser::IE', 'new'); |
|---|
| | 155 | can_ok('HoneyClient::Agent::Driver::Browser::IE', 'drive'); |
|---|
| | 156 | can_ok('HoneyClient::Agent::Driver::Browser::IE', 'isFinished'); |
|---|
| | 157 | can_ok('HoneyClient::Agent::Driver::Browser::IE', 'next'); |
|---|
| | 158 | can_ok('HoneyClient::Agent::Driver::Browser::IE', 'status'); |
|---|
| | 159 | can_ok('HoneyClient::Agent::Driver::Browser::IE', 'getNextLink'); |
|---|
| | 160 | use HoneyClient::Agent::Driver::Browser::IE; |
|---|
| | 161 | |
|---|
| | 162 | # Suppress all logging messages, since we need clean output for unit testing. |
|---|
| | 163 | Log::Log4perl->init({ |
|---|
| | 164 | "log4perl.rootLogger" => "DEBUG, Buffer", |
|---|
| | 165 | "log4perl.appender.Buffer" => "Log::Log4perl::Appender::TestBuffer", |
|---|
| | 166 | "log4perl.appender.Buffer.min_level" => "fatal", |
|---|
| | 167 | "log4perl.appender.Buffer.layout" => "Log::Log4perl::Layout::PatternLayout", |
|---|
| | 168 | "log4perl.appender.Buffer.layout.ConversionPattern" => "%d{yyyy-MM-dd HH:mm:ss} %5p [%M] (%F:%L) - %m%n", |
|---|
| | 169 | }); |
|---|
| | 170 | |
|---|
| | 171 | # Make sure Win32::Job loads. |
|---|
| | 172 | BEGIN { use_ok('Win32::Job') or diag("Can't load Win32::Job package. Check to make sure the package library is correctly listed within the path."); } |
|---|
| | 173 | require_ok('Win32::Job'); |
|---|
| | 174 | use Win32::Job; |
|---|
| | 175 | |
|---|
| 163 | | # TODO: clean this up. |
|---|
| 164 | | #my %PARAMS = ( |
|---|
| 165 | | #); |
|---|
| 166 | | |
|---|
| 167 | | ####################################################################### |
|---|
| 168 | | # Private Methods Implemented # |
|---|
| 169 | | ####################################################################### |
|---|
| 170 | | |
|---|
| 171 | | #sub new { |
|---|
| 172 | | # |
|---|
| 173 | | # # - This function takes in an optional hashtable, |
|---|
| 174 | | # # that contains various key => 'value' configuration |
|---|
| 175 | | # # parameters. |
|---|
| 176 | | # # |
|---|
| 177 | | # # - For each parameter given, it overwrites any corresponding |
|---|
| 178 | | # # parameters specified within the default hashtable, %PARAMS, |
|---|
| 179 | | # # with custom entries that were given as parameters. |
|---|
| 180 | | # # |
|---|
| 181 | | # # - Finally, it returns a blessed instance of the |
|---|
| 182 | | # # merged hashtable, as an 'object'. |
|---|
| 183 | | # |
|---|
| 184 | | # # Get the class name. |
|---|
| 185 | | # my $self = shift; |
|---|
| 186 | | # |
|---|
| 187 | | # # Get the rest of the arguments, as a hashtable. |
|---|
| 188 | | # # Hash-based arguments are used, since HoneyClient::Util::SOAP is unable to handle |
|---|
| 189 | | # # hash references directly. Thus, flat hashtables are used throughout the code |
|---|
| 190 | | # # for consistency. |
|---|
| 191 | | # my %args = @_; |
|---|
| 192 | | # |
|---|
| 193 | | # # Check to see if the class name is inherited or defined. |
|---|
| 194 | | # my $class = ref($self) || $self; |
|---|
| 195 | | # |
|---|
| 196 | | # # Initialize default parameters. |
|---|
| 197 | | # my %params = %{dclone(\%PARAMS)}; |
|---|
| 198 | | # $self = $class->SUPER::new(); |
|---|
| 199 | | # @{$self}{keys %params} = values %params; |
|---|
| 200 | | # |
|---|
| 201 | | # # Now, overwrite any default parameters that were redefined |
|---|
| 202 | | # # in the supplied arguments. |
|---|
| 203 | | # @{$self}{keys %args} = values %args; |
|---|
| 204 | | # |
|---|
| 205 | | # # Now, assign our object the appropriate namespace. |
|---|
| 206 | | # bless $self, $class; |
|---|
| 207 | | # |
|---|
| 208 | | # # Finally, return the blessed object. |
|---|
| 209 | | # return $self; |
|---|
| 210 | | #} |
|---|
| | 194 | ####################################################################### |
|---|
| | 195 | # Public Methods Implemented # |
|---|
| | 196 | ####################################################################### |
|---|
| | 197 | |
|---|
| | 198 | =pod |
|---|
| | 199 | |
|---|
| | 200 | =head1 METHODS OVERRIDDEN |
|---|
| | 201 | |
|---|
| | 202 | The following functions have been overridden by the IE driver. All other |
|---|
| | 203 | methods were implemented by the generic Browser driver. For further |
|---|
| | 204 | information about the Browser driver, see the L<HoneyClient::Agent::Driver::Browser> |
|---|
| | 205 | documentation. |
|---|
| | 206 | |
|---|
| | 207 | =head2 $object->drive(url => $url) |
|---|
| | 208 | |
|---|
| | 209 | =over 4 |
|---|
| | 210 | |
|---|
| | 211 | Drives an instance of Microsoft Internet Explorer for one iteration, |
|---|
| | 212 | navigating either to the specified URL or to the next URL computed within |
|---|
| | 213 | the Browser driver's internal hashtables. |
|---|
| | 214 | |
|---|
| | 215 | For a description of which hashtable is consulted upon each iteration of |
|---|
| | 216 | drive(), see the B<next_link_to_visit> description of the |
|---|
| | 217 | L<HoneyClient::Agent::Driver::Browser> documentation, in the |
|---|
| | 218 | "DEFAULT PARAMETER LIST" section. |
|---|
| | 219 | |
|---|
| | 220 | Once a drive() iternation has completed, the corresponding browser process |
|---|
| | 221 | is terminated. Thus, each call to drive() invokes a new instance of the |
|---|
| | 222 | browser. |
|---|
| | 223 | |
|---|
| | 224 | I<Inputs>: |
|---|
| | 225 | B<$url> is an optional argument, specifying the next immediate URL the browser |
|---|
| | 226 | must drive to. |
|---|
| | 227 | |
|---|
| | 228 | I<Output>: The updated IE driver B<$object>, containing state information from driving the |
|---|
| | 229 | browser for one iteration. |
|---|
| | 230 | |
|---|
| | 231 | B<Warning>: This method will B<croak>, if the IE driver object is B<unable> |
|---|
| | 232 | to navigate to a new link, because its list of links to vist is empty and no new |
|---|
| | 233 | URL was supplied. |
|---|
| | 234 | |
|---|
| | 235 | =back |
|---|
| | 236 | |
|---|
| | 237 | =begin testing |
|---|
| | 238 | |
|---|
| | 239 | # TODO: Implement this. |
|---|
| | 240 | 1; |
|---|
| | 241 | |
|---|
| | 242 | =end testing |
|---|
| | 243 | |
|---|
| | 244 | =cut |
|---|
| | 345 | ####################################################################### |
|---|
| | 346 | # Additional Module Documentation # |
|---|
| | 347 | ####################################################################### |
|---|
| | 348 | |
|---|
| | 349 | __END__ |
|---|
| | 350 | |
|---|
| | 351 | =head1 BUGS & ASSUMPTIONS |
|---|
| | 352 | |
|---|
| | 353 | This package will only run on Win32 platforms. Furthermore, it has |
|---|
| | 354 | only been tested to work reliably within a Cygwin environment. |
|---|
| | 355 | |
|---|
| | 356 | In a nutshell, this object is nothing more than a blessed anonymous |
|---|
| | 357 | reference to a hashtable, where (key => value) pairs are defined in |
|---|
| | 358 | the L<DEFAULT PARAMETER LIST>, as well as fed via the new() function |
|---|
| | 359 | during object initialization. As such, this package does B<not> |
|---|
| | 360 | perform any rigorous B<data validation> prior to accepting any new |
|---|
| | 361 | or overriding (key => value) pairs. |
|---|
| | 362 | |
|---|
| | 363 | However, additional links can be fed to any IE driver at any time, by |
|---|
| | 364 | simply adding new hashtable entries to the B<links_to_visit> hashtable |
|---|
| | 365 | within the B<$object>. |
|---|
| | 366 | |
|---|
| | 367 | For example, if you wanted to add the URL "http://www.mitre.org" |
|---|
| | 368 | to the IE driver B<$object>, simply use the following code: |
|---|
| | 369 | |
|---|
| | 370 | $object->{links_to_visit}->{'http://www.mitre.org'} = 1; |
|---|
| | 371 | |
|---|
| | 372 | In general, the IE driver does B<not> know how many links it will |
|---|
| | 373 | ultimately end up browsing to, until it conducts an exhaustive |
|---|
| | 374 | spider of all initial URLs supplied. As such, expect the output |
|---|
| | 375 | of $object->status() to change significantly, upon each |
|---|
| | 376 | $object->drive() iteration. |
|---|
| | 377 | |
|---|
| | 378 | For example, if at one given point, the status of B<percent_complete> |
|---|
| | 379 | is 30% and then this value drops to 15% upon another iteration, then |
|---|
| | 380 | this means that the total number of links to drive to has greatly |
|---|
| | 381 | increased. |
|---|
| | 382 | |
|---|
| | 383 | Lastly, we assume that the Microsoft Internet Explorer browser has |
|---|
| | 384 | been preconfigured to B<not cache any data>. This ensures the browser |
|---|
| | 385 | will render the most recent version of the content hosted at each URL. |
|---|
| | 386 | |
|---|
| | 387 | =head1 SEE ALSO |
|---|
| | 388 | |
|---|
| | 389 | L<http://www.honeyclient.org/trac> |
|---|
| | 390 | |
|---|
| | 391 | =head1 REPORTING BUGS |
|---|
| | 392 | |
|---|
| | 393 | L<http://www.honeyclient.org/trac/newticket> |
|---|
| | 394 | |
|---|
| | 395 | =head1 AUTHORS |
|---|
| | 396 | |
|---|
| | 397 | Kathy Wang, E<lt>knwang@mitre.orgE<gt> |
|---|
| | 398 | |
|---|
| | 399 | Thanh Truong, E<lt>ttruong@mitre.orgE<gt> |
|---|
| | 400 | |
|---|
| | 401 | Darien Kindlund, E<lt>kindlund@mitre.orgE<gt> |
|---|
| | 402 | |
|---|
| | 403 | Brad Stephenson, E<lt>stephenson@mitre.orgE<gt> |
|---|
| | 404 | |
|---|
| | 405 | =head1 COPYRIGHT & LICENSE |
|---|
| | 406 | |
|---|
| | 407 | Copyright (C) 2007 The MITRE Corporation. All rights reserved. |
|---|
| | 408 | |
|---|
| | 409 | This program is free software; you can redistribute it and/or |
|---|
| | 410 | modify it under the terms of the GNU General Public License |
|---|
| | 411 | as published by the Free Software Foundation, using version 2 |
|---|
| | 412 | of the License. |
|---|
| | 413 | |
|---|
| | 414 | This program is distributed in the hope that it will be useful, |
|---|
| | 415 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| | 416 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| | 417 | GNU General Public License for more details. |
|---|
| | 418 | |
|---|
| | 419 | You should have received a copy of the GNU General Public License |
|---|
| | 420 | along with this program; if not, write to the Free Software |
|---|
| | 421 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|---|
| | 422 | 02110-1301, USA. |
|---|
| | 423 | |
|---|
| | 424 | |
|---|
| | 425 | =cut |
|---|
| | 426 | |
|---|