[Rt-commit] rtir branch, 5.0/fix-net-whois-test-functionality, created. 4.0.1rc1-201-g28405d48
Aaron Trevena
ast at bestpractical.com
Mon Jun 29 07:17:24 EDT 2020
The branch, 5.0/fix-net-whois-test-functionality has been created
at 28405d48fa1f43597bd123cdccb4e24960da2ae8 (commit)
- Log -----------------------------------------------------------------
commit 5cf0332c818a3744bd78c05581361c9f712efe78
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Jun 26 12:14:22 2020 +0100
Hand-parse non-RIPE whois ip lookup response
Hand-parse ip address lookup responses from non-RIPE whois servers
in GetMailFromIP page
Prior to upgrading to Net::Whois::RIPE 2.x we could iterate through
attributes for the result of queries.The updated API replacing the
attributes method call with Net::Whois::Object throws fatal errors on
responses for ip and dns lookups with any server except ripe.net
See https://github.com/arhuman/Net-Whois-RIPE/issues/27
diff --git a/html/RTIR/Tools/Elements/GetEmailFromIP b/html/RTIR/Tools/Elements/GetEmailFromIP
index 0d768be7..9aed912a 100644
--- a/html/RTIR/Tools/Elements/GetEmailFromIP
+++ b/html/RTIR/Tools/Elements/GetEmailFromIP
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2020 Best Practical Solutions, LLC
%# <sales at bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -62,18 +62,50 @@ unless ( $iterator ) {
$field ||= 'notify';
-my @objects = Net::Whois::Object->new($iterator);
-my @res;
-foreach my $obj (@objects) {
- foreach my $attr ( grep lc $_ eq lc $field, $obj->attributes ) {
- push @res, $obj->$attr();
+my @res = ( );
+if ($server eq 'whois.ripe.net') {
+ # Trap possible failures when parsing results
+ # Net::Whois currently dies in some cases, so we need to eval
+ my @objects;
+ eval {
+ @objects = Net::Whois::Object->new($iterator);
+ };
+ if ( $@ ) {
+ RT->Logger->warn('Unable to parse WHOIS results for query ' . $q);
+ RT->Logger->debug($@);
+ $$error = loc('Unable to parse results from WHOIS lookup');
+ }
+ else {
+ foreach my $obj (@objects) {
+ foreach my $attr ( grep lc $_ eq lc $field, $obj->attributes ) {
+ push @res, $obj->$attr();
+ }
+ }
+
+ }
+}
+else {
+ while ( ! $iterator->is_exhausted() ) {
+ foreach my $line ( split /\n/, $iterator->value() ) {
+ # Parse simple "Field: Value" lines in response, ignoring spaces at start
+ # as Net::Whois::Object can't parse and fails with a fatal error
+ if ( $line =~ /^\s*(\S+\s?\S*):\s*(.*)/ ) {
+ my ($attribute, $value) = ($1,$2);
+ next unless (defined($attribute) && $attribute);
+ if (lc $attribute eq lc $field) {
+ push(@res, $value);
+ }
+ }
+ }
}
}
+
unless ( @res ) {
$$error = loc("Whois server response did not include field '[_1]'", $field);
return;
}
+
($$address) = grep defined && length, @res;
</%INIT>
commit b9f3b90d2d8d343a96675b8714c2ea8a41e182c4
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Jun 26 16:12:43 2020 +0100
Hand-parse non-RIPE server domain lookup responses
Prior to upgrading to Net::Whois::RIPE 2.x we could iterate through
attributes for the result of queries. The updated API replacing the
attributes method call with Net::Whois::Object throws fatal errors for
responses for ip and dns lookups for servers except ripe.net
(https://github.com/arhuman/Net-Whois-RIPE/issues/27) so we parse
those responses.
diff --git a/html/RTIR/Tools/Elements/ToolResultsWhois b/html/RTIR/Tools/Elements/ToolResultsWhois
index 9e7110d3..c2a101ab 100644
--- a/html/RTIR/Tools/Elements/ToolResultsWhois
+++ b/html/RTIR/Tools/Elements/ToolResultsWhois
@@ -57,13 +57,44 @@
<b><% $WhoisError %></b>
% }
<%PERL>
+
+# Prior to upgrading to Net::Whois::RIPE 2.x we could iterate through attributes for the result
+# of this query for any server. The updated API replacing the attributes method call
+# with Net::Whois::Object throws fatal errors for servers other than ripe.net
+# (https://github.com/arhuman/Net-Whois-RIPE/issues/27)
+
my $DoInvestigate = 0;
if ($WhoisIterator) {
- while ( $WhoisIterator->isnt_exhausted) {
- my $block = $WhoisIterator->value;
- $SavedContent .= $block . "\n";
- my @lines_starting_with_space = grep /^(\s+)(\w+)/, $block;
- if ($handparse || $#lines_starting_with_space >= 4) { #we couldn't parse that. suck
+ my $content;
+ if ($WhoisServer eq 'whois.ripe.net') {
+ my @objects = Net::Whois::Object->new($WhoisIterator);
+ foreach my $object ( @objects ) {
+ my %seen;
+ foreach my $attribute ($object->attributes()) {
+ next if ($seen{$attribute});
+ $seen{$attribute} = 1;
+ my @values;
+ foreach my $value ( $object->$attribute() ) {
+ next unless ($value);
+ push (@values, (ref($value) eq 'ARRAY' ) ? @$value : $value);
+ }
+ next unless (scalar @values);
+ my $content = join("\n", ' ', @values);
+</%perl>
+ <b><%$attribute%></b>:
+ <& /Elements/MakeClicky,
+ ticket => $TicketObj,
+ lookup_params => "ticket=" . ($TicketObj ? $TicketObj->id : 0) . "&server=$WhoisServer",
+ content => \$content &>
+ <% $content |n %><br />
+<%perl>
+ }
+ }
+ }
+ else {
+ while ( $WhoisIterator->isnt_exhausted) {
+ my $block = $WhoisIterator->value;
+ $SavedContent .= $block . "\n";
my $content = join "", $block;
$m->comp('/Elements/MakeClicky',
object => $TicketObj,
@@ -72,38 +103,9 @@ if ($WhoisIterator) {
$DoInvestigate = 1 if $content =~ /Requestorbox/ig;
</%PERL>
<pre><% $content |n %></pre><br />
-% } else {
-Structured RIPE whois data returned.
-Click <a href="Lookup.html?q=<% $q |u %>&server=<% $WhoisServer |u %>&handparse=1">here</a> to manually parse this data.
-<%perl>
-my @objects = Net::Whois::Object->new($WhoisIterator);
-foreach my $object ( @objects ) {
- my %seen;
- foreach my $attribute ($object->attributes()) {
- next if ($seen{$attribute});
- $seen{$attribute} = 1;
- my @values;
- foreach my $value ( $object->$attribute() ) {
- next unless ($value);
- push (@values, (ref($value) eq 'ARRAY' ) ? @$value : $value);
- }
- next unless (scalar @values);
- my $value = join("\n", ' ', @values);
-</%perl>
- <b><%$attribute%></b>:
-<& /Elements/MakeClicky,
- ticket => $TicketObj,
- lookup_params => "ticket=".$TicketObj->id,
- content => \$value &>
-<% $value |n %><br />
-<%perl>
- }
- }
-
- }
- }
- }
-</%perl>
+% }
+% }
+%}
%# Don't offer the option of Investigating to unless there are addresses
% if ( $DoInvestigate ) {
<& /Elements/Submit,
@@ -136,7 +138,6 @@ foreach my $object ( @objects ) {
<%args>
$q => undef
-$handparse => 1
$TicketObj => undef
$WhoisServer => undef
$server => undef
commit 28405d48fa1f43597bd123cdccb4e24960da2ae8
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Jun 26 12:15:39 2020 +0100
Add more tests for lookup tool
Add tests for RIPE server lookup
Add tests for ip lookup
diff --git a/t/tools/lookup.t b/t/tools/lookup.t
index d62c2dd2..dd558b8f 100644
--- a/t/tools/lookup.t
+++ b/t/tools/lookup.t
@@ -20,7 +20,6 @@ unless ($agent->status == 200){
diag "Test Lookup page directly";
{
$agent->get_ok("/RTIR/Tools/Lookup.html", "Loaded Lookup page");
-
SKIP:{
skip "No network", 3 if $no_network;
$agent->form_name('ToolFormWhois');
@@ -30,6 +29,20 @@ SKIP:{
$agent->content_contains('WHOIS Results');
$agent->content_contains('IANA WHOIS server');
$agent->next_warning_like( qr/Asked to run a full text search from Lookup\.html/ );
+}
+ $agent->get_ok("/RTIR/Tools/Lookup.html", "Loaded Lookup page");
+SKIP:{
+ skip "No network", 3 if $no_network;
+ $agent->form_name('ToolFormWhois');
+ $agent->field('q', 'bestpractical.com');
+ $agent->select('WhoisServer', 'RIPE');
+ $agent->click;
+ $agent->content_contains('WHOIS Results');
+ $agent->content_contains('response');
+ $agent->content_contains('comment');
+ $agent->content_contains('ERROR:101');
+ $agent->content_contains('No entries found in source RIPE');
+ $agent->next_warning_like( qr/Asked to run a full text search from Lookup\.html/ );
}
}
@@ -57,5 +70,37 @@ SKIP:{
}
}
+diag "Test IP Lookup";
+{
+ $agent->get_ok("/RTIR/Tools/ScriptedAction.html?loop=IP", "Loaded Lookup page");
+
+ SKIP:{
+ skip "No network", 2 if $no_network;
+ $agent->form_name('ScriptedAction');
+ $agent->field('IPs', '45.33.11.14');
+ $agent->field('field', 'organisation');
+ $agent->select('server', 'whois.iana.org');
+ $agent->click;
+ $agent->content_contains('Address test results');
+ $agent->content_contains('45.33.11.14');
+ $agent->content_contains('Administered by ARIN');
+ }
+
+ $agent->get_ok("/RTIR/Tools/ScriptedAction.html?loop=IP", "Loaded Lookup page");
+
+ SKIP:{
+ skip "No network", 2 if $no_network;
+ $agent->form_name('ScriptedAction');
+ $agent->field('IPs', '45.33.11.14');
+ $agent->field('field', 'netname');
+ $agent->select('server', 'whois.ripe.net');
+ $agent->click;
+ $agent->content_contains('Address test results');
+ $agent->content_contains('45.33.11.14');
+ $agent->content_contains('NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK');
+ }
+}
+
+
undef $agent;
done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list