Changeset 1443

Show
Ignore:
Timestamp:
04/03/08 15:22:02 (5 months ago)
Author:
kindlund
Message:

Finalized light-weight Agent design. Additional Housekeeping.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • honeyclient/branches/exp/kindlund-simpler_agent/lib/HoneyClient/Agent.pm

    r1436 r1443  
    102102  my $som; 
    103103 
     104  # Get the properties of the Agent OS and driven application. 
     105  $som = $stub->getProperties(driver_name => "HoneyClient::Agent::Driver::Browser::IE"); 
     106  print Dumper($som->result()) . "\n"; 
     107 
    104108  # Drive HoneyClient::Agent::Driver::Browser::IE to a website. 
    105109  $som = $stub->drive(driver_name => "HoneyClient::Agent::Driver::Browser::IE", 
     
    269273use DateTime::HiRes; 
    270274 
     275# Make sure Data::Dumper loads. 
     276BEGIN { use_ok('Data::Dumper') or diag("Can't load Data::Dumper package.  Check to make sure the package library is correctly listed within the path."); } 
     277require_ok('Data::Dumper'); 
     278use Data::Dumper; 
     279 
    271280BEGIN { 
    272281 
     
    312321use HoneyClient::Util::Config qw(getVar); 
    313322 
    314 # XXX: Remove this, eventually. 
     323# Include Dumper Library 
    315324use Data::Dumper; 
    316325 
     
    518527        $LOG->debug("Destroying Agent daemon at PID: " . $DAEMON_PID); 
    519528         
    520         # TODO: Need unit tests. 
    521529        require Win32::Process; 
    522530        Win32::Process::KillProcess($DAEMON_PID, 0); 
     
    555563=head1 EXTERNAL SOAP FUNCTIONS 
    556564 
    557 =head2 drive(driver_name => $driverName, 
    558              parameters => $params, 
    559              timeout => $timeout) 
     565=head2 drive(driver_name => $driverName, parameters => $params, timeout => $timeout) 
    560566 
    561567=over 4 
     
    14541460} 
    14551461 
    1456 # XXX: Comment this. 
     1462=pod 
     1463 
     1464=head2 getProperties(driver_name => $driverName) 
     1465 
     1466=over 4 
     1467 
     1468Retrieves properties about the Agent's OS and target driver application, 
     1469if specified. 
     1470 
     1471I<Inputs>:  
     1472 B<$driverName> an optional argument, indicating the Driver proprties to 
     1473return. 
     1474 
     1475I<Output>: 
     1476 A hashtable containing the following information: 
     1477 
     1478 { 
     1479     # Short name of the OS. 
     1480     'shortname' => 'Microsoft Windows', 
     1481     # Version of the OS. 
     1482     'version' => '5.1.2600.2.2.0.256.1', 
     1483     # Formal name of the OS. 
     1484     'name' => 'Windows XP Service Pack 2', 
     1485     # The targeted application(s) being driven, if driver_name was specified. 
     1486     'os_applications' => [ 
     1487         { 
     1488             # The short name of the app. 
     1489             'shortname' => 'Internet Explorer', 
     1490             # The manufacturer of the app. 
     1491             'manufacturer' => 'Microsoft Corporation', 
     1492             # The app version. 
     1493             'version' => '7.0.6000.16608' 
     1494         } 
     1495     ] 
     1496 }; 
     1497 
     1498=back 
     1499 
     1500=begin testing 
     1501 
     1502# Check to make sure we're in a suitable environment. 
     1503use Config; 
     1504SKIP: { 
     1505    skip 'HoneyClient::Agent only works in Cygwin environment.', 5 if ($Config{osname} !~ /^cygwin$/); 
     1506 
     1507    # Shared test variables. 
     1508    my ($stub, $som, $URL); 
     1509 
     1510    # Catch all errors, in order to make sure child processes are 
     1511    # properly killed. 
     1512    eval { 
     1513 
     1514        $URL = HoneyClient::Agent->init(); 
     1515 
     1516        # Connect to daemon as a client. 
     1517        $stub = getClientHandle(namespace => "HoneyClient::Agent", 
     1518                                address   => "localhost"); 
     1519 
     1520        # Drive the Agent using IE. 
     1521        $som = $stub->getProperties(driver_name => "HoneyClient::Agent::Driver::Browser::IE"); 
     1522 
     1523        # Verify output. 
     1524        my $output = $som->result(); 
     1525 
     1526        # Check to see if the operation completed properly.  
     1527        ok($output, "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The getProperties() call failed."); 
     1528        ok(exists($output->{'shortname'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     1529        ok(exists($output->{'version'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     1530        ok(exists($output->{'name'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     1531        ok(exists($output->{'os_applications'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     1532 
     1533    }; 
     1534 
     1535    # Kill the child daemon, if it still exists. 
     1536    HoneyClient::Agent->destroy(); 
     1537 
     1538    # Report any failure found. 
     1539    if ($@) { 
     1540        fail($@); 
     1541    } 
     1542
     1543 
     1544=end testing 
     1545 
     1546=cut 
     1547 
     1548sub getProperties { 
     1549     
     1550    # Extract arguments. 
     1551    my ($class, %args) = @_; 
     1552 
     1553    # Log resolved arguments. 
     1554    $LOG->debug(sub { 
     1555        # Make Dumper format more terse. 
     1556        $Data::Dumper::Terse = 1; 
     1557        $Data::Dumper::Indent = 0; 
     1558        Dumper(\%args); 
     1559    }); 
     1560 
     1561    # Sanity check.  Make sure we get a valid argument. 
     1562    my $argsExist = scalar(%args); 
     1563    if (!$argsExist || 
     1564        !exists($args{'driver_name'}) || 
     1565        !defined($args{'driver_name'})) { 
     1566 
     1567        $args{'driver_name'} = undef; 
     1568    } 
     1569 
     1570    # Get OS Properties 
     1571    require Win32; 
     1572    my @os_name = Win32::GetOSName(); 
     1573    my @os_vers = Win32::GetOSVersion(); 
     1574 
     1575    # Translate known OS names. 
     1576    my $name = $os_name[0]; 
     1577    $name =~ s/^WinXP.*/Windows XP/; 
     1578    $name .= " " . $os_name[1]; 
     1579 
     1580    # Get rid of any 'Service Pack' identifiers. 
     1581    shift(@os_vers); 
     1582    my $version = join('.', @os_vers);  
     1583 
     1584    # Construct initial output. 
     1585    my $ret = { 
     1586        shortname => 'Microsoft Windows', 
     1587        name => $name, 
     1588        version => $version, 
     1589        os_applications => [], 
     1590    }; 
     1591 
     1592    if (defined($args{'driver_name'})) { 
     1593        # Get Driver Application Properties 
     1594        require Win32::Exe; 
     1595        my $process_exec = getVar(name      => 'process_exec', 
     1596                                  namespace => $args{'driver_name'}); 
     1597        my $exe = Win32::Exe->new($process_exec); 
     1598        my $exe_name = $exe->version_info->get('FileDescription'); 
     1599        my $exe_comp = $exe->version_info->get('CompanyName'); 
     1600        my $exe_vers = $exe->version_info->get('ProductVersion'); 
     1601 
     1602        # Translate commas into periods. 
     1603        $exe_vers =~ s/,/./g; 
     1604 
     1605        my $app_properties = { 
     1606            manufacturer => $exe_comp, 
     1607            shortname    => $exe_name, 
     1608            version      => $exe_vers, 
     1609        }; 
     1610 
     1611        push(@{$ret->{os_applications}}, $app_properties); 
     1612    } 
     1613 
     1614    return $ret; 
     1615
    14571616 
    14581617####################################################################### 
  • honeyclient/branches/exp/kindlund-simpler_agent/t/honeyclient_agent.t

    r1436 r1443  
    106106require_ok('DateTime::HiRes'); 
    107107use DateTime::HiRes; 
     108 
     109# Make sure Data::Dumper loads. 
     110BEGIN { use_ok('Data::Dumper') or diag("Can't load Data::Dumper package.  Check to make sure the package library is correctly listed within the path."); } 
     111require_ok('Data::Dumper'); 
     112use Data::Dumper; 
    108113 
    109114BEGIN { 
     
    862867 
    863868 
     869# =begin testing 
     870{ 
     871# Check to make sure we're in a suitable environment. 
     872use Config; 
     873SKIP: { 
     874    skip 'HoneyClient::Agent only works in Cygwin environment.', 5 if ($Config{osname} !~ /^cygwin$/); 
     875 
     876    # Shared test variables. 
     877    my ($stub, $som, $URL); 
     878 
     879    # Catch all errors, in order to make sure child processes are 
     880    # properly killed. 
     881    eval { 
     882 
     883        $URL = HoneyClient::Agent->init(); 
     884 
     885        # Connect to daemon as a client. 
     886        $stub = getClientHandle(namespace => "HoneyClient::Agent", 
     887                                address   => "localhost"); 
     888 
     889        # Drive the Agent using IE. 
     890        $som = $stub->getProperties(driver_name => "HoneyClient::Agent::Driver::Browser::IE"); 
     891 
     892        # Verify output. 
     893        my $output = $som->result(); 
     894 
     895        # Check to see if the operation completed properly.  
     896        ok($output, "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The getProperties() call failed."); 
     897        ok(exists($output->{'shortname'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     898        ok(exists($output->{'version'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     899        ok(exists($output->{'name'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     900        ok(exists($output->{'os_applications'}), "getProperties(driver_name => 'HoneyClient::Agent::Driver::Browser::IE')") or diag("The drive() call failed."); 
     901 
     902    }; 
     903 
     904    # Kill the child daemon, if it still exists. 
     905    HoneyClient::Agent->destroy(); 
     906 
     907    # Report any failure found. 
     908    if ($@) { 
     909        fail($@); 
     910    } 
     911} 
     912} 
     913 
     914 
     915 
    864916 
    8659171;