[Rt-commit] rtir branch 4.0/improve-find-ip-logic created. 4.0.3-5-g19f34f91
BPS Git Server
git at git.bestpractical.com
Fri Jan 13 16:21:28 UTC 2023
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rtir".
The branch, 4.0/improve-find-ip-logic has been created
at 19f34f913fa94b8c633796aa40de2a1a38276ec3 (commit)
- Log -----------------------------------------------------------------
commit 19f34f913fa94b8c633796aa40de2a1a38276ec3
Author: Brad Embree <brad at bestpractical.com>
Date: Fri Jan 13 08:12:17 2023 -0800
Improve IPv6 Regex
Ensure IPv6 regex does not match all zero IPs or IPs with a zero CIDR
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 80ff0dff..f91f1073 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -79,7 +79,9 @@ my $IPv6_prefix_check_re = qr{(?<![0-9a-zA-Z:.])};
my $IPv6_suffix_check_re = qr{(?!\.?[0-9a-zA-Z:])};
my $IPv6_re = qr[
$IPv6_prefix_check_re
+ (?!0000:0000:0000:0000:0000:0000:0000:0000)
($Regexp::IPv6::IPv6_re)
+ (?!/0)
(?:/($IPv6_mask_re))?
$IPv6_suffix_check_re
]x;
@@ -119,16 +121,20 @@ sub Commit {
my $content = $attach->Content || '';
while ( $content =~ m/$IP_re/go ) {
if ( $1 && defined $2 ) { # IPv6/mask
- my $range = $2 == 128 ? $1 : (Net::CIDR::cidr2range( "$1/$2" ))[0]
- or next;
- $spots_left -= $self->AddIP(
- IP => $range, CustomField => $cf, Skip => \%existing
- );
+ unless ( $1 eq '::' ) {
+ my $range = $2 == 128 ? $1 : (Net::CIDR::cidr2range( "$1/$2" ))[0]
+ or next;
+ $spots_left -= $self->AddIP(
+ IP => $range, CustomField => $cf, Skip => \%existing
+ );
+ }
}
elsif ( $1 ) { # IPv6
- $spots_left -= $self->AddIP(
- IP => $1, CustomField => $cf, Skip => \%existing
- );
+ unless ( $1 eq '::' ) {
+ $spots_left -= $self->AddIP(
+ IP => $1, CustomField => $cf, Skip => \%existing
+ );
+ }
}
elsif ( $3 ) { # IPv4
$spots_left -= $self->AddIP(
commit f60c0ae002bdb84f94ffb780020a4dc75f0e114e
Author: Brad Embree <brad at bestpractical.com>
Date: Fri Jan 13 08:10:50 2023 -0800
Add tests for IPv6 all zero IPs
Add tests to ensure that all zero IPs are not added as IPs when
creating a ticket.
diff --git a/t/custom-fields/ipv6.t b/t/custom-fields/ipv6.t
index 7d789236..bd6175eb 100644
--- a/t/custom-fields/ipv6.t
+++ b/t/custom-fields/ipv6.t
@@ -592,6 +592,12 @@ my @invalid = (
# A trailing dot is allowed but not if there are words right after it
'abcd::34.3', 'abcd::192.168.1.2.3', '::add.z',
+
+ # ensure all zero addresses do not get added as IPs
+ '::', '0000:0000:0000:0000:0000:0000:0000:0000',
+ '::/0', '0000:0000:0000:0000:0000:0000:0000:0000/0',
+ '::/64', '0000:0000:0000:0000:0000:0000:0000:0000/64',
+ 'abcd:0000:0000:0000:0000:0000:0000:0000/0',
);
commit 7011b9fa8915225cf17f0ab52478de211297cec3
Author: Brad Embree <brad at bestpractical.com>
Date: Wed Jan 11 10:59:09 2023 -0800
Improve IPv4 Regex
Ensure IPv4 regex do not match all zero IPs or IPs with a zero CIDR
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 11a9afab..80ff0dff 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -61,7 +61,9 @@ my $IPv4_prefix_check_re = qr{(?<![0-9.])};
my $IPv4_suffix_check_re = qr{(?!\.?[0-9])};
my $IPv4_CIDR_re = qr{
$IPv4_prefix_check_re
+ (?!0\.0\.0\.0)
$RE{net}{CIDR}{IPv4}{-keep}
+ (?<!/0)
$IPv4_suffix_check_re
}x;
my $IPv4_re = qr[
commit 25b61a260b5bff69acd195672a68f2da9863faca
Author: Brad Embree <brad at bestpractical.com>
Date: Wed Jan 11 10:53:28 2023 -0800
Add tests for 0.0.0.0, 0.0.0.0/0, and 1.0.0.0/0
Add tests to ensure that all zero IPs are not added as IPs when
creating a ticket.
diff --git a/t/custom-fields/ip.t b/t/custom-fields/ip.t
index feea2125..e91917cf 100644
--- a/t/custom-fields/ip.t
+++ b/t/custom-fields/ip.t
@@ -296,6 +296,30 @@ diag "check that we parse correct IPs only" if $ENV{'TEST_VERBOSE'};
$ticket->Load( $id );
is($ticket->id, $id, 'loaded ticket');
is($ticket->CustomFieldValues('IP')->Count, 0, "IP wasn't added");
+
+ $id = $agent->create_ir( { Subject => "test ip", Content => '0.0.0.0' } );
+ ok($id, "created a ticket");
+
+ $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ is($ticket->id, $id, 'loaded ticket');
+ is($ticket->CustomFieldValues('IP')->Count, 0, "IP wasn't added");
+
+ $id = $agent->create_ir( { Subject => "test ip", Content => '0.0.0.0/0' } );
+ ok($id, "created a ticket");
+
+ $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ is($ticket->id, $id, 'loaded ticket');
+ is($ticket->CustomFieldValues('IP')->Count, 0, "IP wasn't added");
+
+ $id = $agent->create_ir( { Subject => "test ip", Content => '1.0.0.0/0' } );
+ ok($id, "created a ticket");
+
+ $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ is($ticket->id, $id, 'loaded ticket');
+ is($ticket->CustomFieldValues('IP')->Count, 0, "IP wasn't added");
}
diag "check that IPs in messages don't add duplicates" if $ENV{'TEST_VERBOSE'};
-----------------------------------------------------------------------
hooks/post-receive
--
rtir
More information about the rt-commit
mailing list