add the search test file and more misc search logic

This commit is contained in:
Zane C. B-H 2019-02-20 01:52:33 -06:00
rodzic fb6a133edd
commit 647cd0923b
3 zmienionych plików z 79 dodań i 57 usunięć

Wyświetl plik

@ -193,6 +193,8 @@ sub search{
my $local_port=$res->[2]->{active_conns}->[$res_int]->{local_port};
my $local_host=$res->[2]->{active_conns}->[$res_int]->{local_host};
my $foreign_host=$res->[2]->{active_conns}->[$res_int]->{foreign_host};
my $sendq=$res->[2]->{active_conns}->[$res_int]->{sendq};
my $recvq=$res->[2]->{active_conns}->[$res_int]->{recvq};
# checks for making sure a check is meet... defaults to 1
my $port_meet=1;
@ -261,6 +263,9 @@ sub search{
'foriegn_host'=>$foreign_host,
'local_port'=>$local_port,
'local_host'=>$local_host,
'sendq'=>$sendq,
'recvq'=>$recvq,
'proto'=>$protocol,
}
);
}

Wyświetl plik

@ -0,0 +1,74 @@
use strict;
use Test::More;
BEGIN {
use_ok('Parse::Netstat::Search');
}
my $res=[ '0', '1',
{
'active_conns'=>[
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'10.0.0.2',
'foriegn_port'=>'22222',
'local_port'=>'22',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'ESTABLISHED',
'proto' => 'tcp4',
},
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'10.0.0.2',
'foriegn_port'=>'22',
'local_port'=>'2222',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'TIME_WAIT',
'proto' => 'tcp4',
},
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'192.168.0.1',
'foriegn_port'=>'22',
'local_port'=>'2222',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'ESTABLISHED',
'proto' => 'tcp4',
},
{
'foriegn_host'=>'10.0.0.1',
'local_host'=>'10.0.0.2',
'foriegn_port'=>'22',
'local_port'=>'2222',
'sendq'=>'0',
'recvq'=>'0',
'state' => 'ESTABLISHED',
'proto' => 'tcp4',
},
{
'foreign_host' => '*',
'recvq' => '0',
'local_port' => '389',
'local_host' => '127.0.0.1',
'foreign_port' => '*',
'state' => 'LISTEN',
'proto' => 'tcp4',
'sendq' => '0'
},
{
'foreign_host' => '*',
'recvq' => '0',
'local_port' => '22',
'local_host' => '*',
'foreign_port' => '*',
'state' => 'LISTEN',
'proto' => 'tcp4',
'sendq' => '0'
},
],
}
];

Wyświetl plik

@ -1,57 +0,0 @@
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 3;
sub not_in_file_ok {
my ($filename, %regex) = @_;
open( my $fh, '<', $filename )
or die "couldn't open $filename for reading: $!";
my %violated;
while (my $line = <$fh>) {
while (my ($desc, $regex) = each %regex) {
if ($line =~ $regex) {
push @{$violated{$desc}||=[]}, $.;
}
}
}
if (%violated) {
fail("$filename contains boilerplate text");
diag "$_ appears on lines @{$violated{$_}}" for keys %violated;
} else {
pass("$filename contains no boilerplate text");
}
}
sub module_boilerplate_ok {
my ($module) = @_;
not_in_file_ok($module =>
'the great new $MODULENAME' => qr/ - The great new /,
'boilerplate description' => qr/Quick summary of what the module/,
'stub function definition' => qr/function[12]/,
);
}
TODO: {
local $TODO = "Need to replace the boilerplate text";
not_in_file_ok(README =>
"The README is used..." => qr/The README is used/,
"'version information here'" => qr/to provide version information/,
);
not_in_file_ok(Changes =>
"placeholder date/time" => qr(Date/time)
);
module_boilerplate_ok('lib/Parse/Netstat/Search.pm');
}