[Rt-commit] rtir branch, rtit-4.0-ip-parse, created. 4.0.0-2-g0374b456
Craig Kaiser
craig at bestpractical.com
Thu Mar 1 16:26:11 EST 2018
The branch, rtit-4.0-ip-parse has been created
at 0374b4566b5b2368dd4ade544c8c891c87a90783 (commit)
- Log -----------------------------------------------------------------
commit 683719269ea54896ee8959b92eadf6d8b18947ac
Author: craig Kaiser <craig at bestpractical.com>
Date: Thu Mar 1 14:39:43 2018 -0500
Tighten regex to avoid false positives on ipv6
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 589b0916..e498a2ff 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -75,9 +75,10 @@ my $IPv4_re = qr[
my $IPv6_mask_re = qr{12[0-8]|1[01][0-9]|[1-9]?[0-9]};
my $IPv6_prefix_check_re = qr{(?<![0-9a-fA-F:.])};
my $IPv6_sufix_check_re = qr{(?!(?:\:{0,2}|\.)[0-9a-fA-F])};
+my $regex = qr/^::(?::[0-9a-fA-F]{1,4}){0,5}(?:(?::[0-9a-fA-F]{1,4}){1,2}|:(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})))|[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}:(?:[0-9a-fA-F]{1,4}|:)|(?::(?:[0-9a-fA-F]{1,4})?|(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-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-4][0-9]|[0-1]?[0-9]{1,2}))|(?::[0-9a-fA-F]{1,4}){1,2})|:))|(?:(?::[0-9a-fA-F]{1,4}){0,4}(?::(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))|(?::[0-9a-fA-F]{1,4}){1,2})|:))/p;
my $IPv6_re = qr[
$IPv6_prefix_check_re
- ($Regexp::IPv6::IPv6_re)
+ ($regex)
(?:/($IPv6_mask_re))?
$IPv6_sufix_check_re
]x;
commit 0374b4566b5b2368dd4ade544c8c891c87a90783
Author: craig Kaiser <craig at bestpractical.com>
Date: Thu Mar 1 14:40:22 2018 -0500
Test error prone string for ipv6
diff --git a/t/custom-fields/ipv6.t b/t/custom-fields/ipv6.t
index afd3b4c1..c1b11942 100644
--- a/t/custom-fields/ipv6.t
+++ b/t/custom-fields/ipv6.t
@@ -576,5 +576,32 @@ diag "merge ticket with the same IP";
is( $has[0], '::ac10:1', "has value" );
}
+diag "create a ticket via web with IP in error prone message" if $ENV{'TEST_VERBOSE'};
+{
+ my $content = 'Scan::Address_Scan 123.45.678.123 ffe:1900:4545:3:200:f8ff:fe21:67cf';
+ my $expected = "ffe:1900:4545:3:200:f8ff:fe21:67cf";
+
+ my $incident_id; # countermeasure couldn't be created without incident id
+ foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Countermeasures' ) {
+ diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
+
+ my $id = $agent->create_rtir_ticket_ok(
+ $queue,
+ {
+ Subject => "test ip in message",
+ ($queue eq 'Countermeasures'? (Incident => $incident_id): ()),
+ Content => "$content",
+ },
+ );
+ $incident_id = $id if $queue eq 'Incidents';
+
+ $agent->content_like( qr/\Q$expected/, "IP on the page" );
+
+ my $ticket = RT::Ticket->new( $RT::SystemUser );
+ $ticket->Load( $id );
+ ok( $ticket->id, 'loaded ticket' );
+ is( $ticket->FirstCustomFieldValue('IP'), $expected, 'correct value' );
+ }
+}
undef $agent;
done_testing();
-----------------------------------------------------------------------
More information about the rt-commit
mailing list