şunun yansıması https://github.com/VVelox/Net-Connection-Match.git
UID stuff is all good
Bu işleme şunda yer alıyor:
ebeveyn
86fa94fc79
işleme
be6a7cb8cf
|
@ -3,6 +3,7 @@ Revision history for Net-Connection-Match
|
|||
0 ?/?
|
||||
- Misc. POD fixes.
|
||||
- Add RegexPTR support.
|
||||
- Add UID support.
|
||||
|
||||
0.1.0 2019-07-31/02:00
|
||||
- Ports can now match '*'.
|
||||
|
|
|
@ -25,3 +25,4 @@ t/States.t
|
|||
t/manifest.t
|
||||
t/pod-coverage.t
|
||||
t/pod.t
|
||||
t/UID.t
|
||||
|
|
|
@ -147,22 +147,22 @@ sub match{
|
|||
return 1;
|
||||
}elsif( $uid =~ /^\<\=[0-9]+$/ ){
|
||||
$uid=~s/^\<\=//;
|
||||
if ( $uid <= $conn_uid ){
|
||||
if ( $conn_uid <= $uid ){
|
||||
return 1;
|
||||
}
|
||||
}elsif( $uid =~ /^\<[0-9]+$/ ){
|
||||
$uid=~s/^\<//;
|
||||
if ( $uid < $conn_uid ){
|
||||
if ( $conn_uid < $uid ){
|
||||
return 1;
|
||||
}
|
||||
}elsif( $uid =~ /^\>\=[0-9]+$/ ){
|
||||
$uid=~s/^\>\=//;
|
||||
if ( $uid >= $conn_uid ){
|
||||
if ( $conn_uid >= $uid ){
|
||||
return 1;
|
||||
}
|
||||
}elsif( $uid =~ /^\>[0-9]+$/ ){
|
||||
$uid=~s/^\>//;
|
||||
if ( $uid > $conn_uid ){
|
||||
if ( $conn_uid > $uid ){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
#!perl -T
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Net::Connection;
|
||||
|
||||
BEGIN {
|
||||
use_ok( 'Net::Connection::Match::UID' ) || print "Bail out!\n";
|
||||
}
|
||||
|
||||
my $connection_args={
|
||||
foreign_host=>'10.0.0.1',
|
||||
foreign_port=>'22',
|
||||
local_host=>'10.0.0.2',
|
||||
local_port=>'12322',
|
||||
proto=>'tcp4',
|
||||
state=>'LISTEN',
|
||||
uid=>0,
|
||||
username=>'root',
|
||||
};
|
||||
|
||||
my %args=(
|
||||
uids=>[
|
||||
'0',
|
||||
'>1000',
|
||||
],
|
||||
);
|
||||
my $checker;
|
||||
|
||||
# makes sure we error with empty args
|
||||
my $worked=0;
|
||||
eval{
|
||||
$checker=Net::Connection::Match::UID->new();
|
||||
$worked=1;
|
||||
};
|
||||
ok( $worked eq '0', 'empty init check') or diag('Calling new with empty args worked');
|
||||
|
||||
# makes sure we can init with good args
|
||||
$worked=0;
|
||||
eval{
|
||||
$checker=Net::Connection::Match::UID->new( \%args );
|
||||
$worked=1;
|
||||
};
|
||||
ok( $worked eq '1', 'init check') or diag('Calling Net::Connection::Match::UID->new resulted in... '.$@);
|
||||
|
||||
# make sure it will not accept null input
|
||||
my $returned=1;
|
||||
eval{
|
||||
$returned=$checker->match;
|
||||
};
|
||||
ok( $returned eq '0', 'undef match check') or diag('match accepted undefined input');
|
||||
|
||||
# make sure it will not accept a improper ref type
|
||||
$returned=1;
|
||||
eval{
|
||||
$returned=$checker->match($checker);
|
||||
};
|
||||
ok( $returned eq '0', 'match improper ref check') or diag('match accepted a ref other than Net::Connection');
|
||||
|
||||
# Create a connection with a matching UID and see if it matches
|
||||
my $conn=Net::Connection->new( $connection_args );
|
||||
$returned=0;
|
||||
eval{
|
||||
$returned=$checker->match( $conn );
|
||||
};
|
||||
ok( $returned eq '1', 'uid match check') or diag('Failed to match a matching good uid');
|
||||
|
||||
# Create a connection with a matching UID greater than 1000 protocol and make sure it does not match
|
||||
$connection_args->{uid}='1001';
|
||||
$connection_args->{username}='1001';
|
||||
$conn=Net::Connection->new( $connection_args );
|
||||
$returned=0;
|
||||
eval{
|
||||
$returned=$checker->match( $conn );
|
||||
};
|
||||
ok( $returned eq '1', 'uid match check 2') or diag('Failed to match a good uid');
|
||||
|
||||
# Create a connection with a matching UID greater than 1000 protocol and make sure it does not match
|
||||
$connection_args->{uid}='900';
|
||||
$connection_args->{username}='900';
|
||||
$conn=Net::Connection->new( $connection_args );
|
||||
$returned=1;
|
||||
eval{
|
||||
$returned=$checker->match( $conn );
|
||||
};
|
||||
ok( $returned eq '0', 'uid non-match check') or diag('Matched a UID that it should not of');
|
||||
|
||||
done_testing(8);
|
Yükleniyor…
Yeni konuda referans