Found and fixed a bug in ErrorHandler, canShowPerformanceIndicators.

It didn't work with CIDR format IP addresses.  I cannabilized the
code from canShowDebug and refactored it into its own method,
canShowBasedOnIP.  Both canShowDebug and canShowPerformanceIndicators call this.
Updated the docs for the debugIp setting to note that it's used for both
showDebug and showPerformanceIndicators.
Added about 20 more tests to ErrorHandler.t.  Only the two hard methods are
left, fatal (which closes the session at the end) and showDebug, which is
validating a ton of output.
This commit is contained in:
Colin Kuskie 2006-11-21 03:50:15 +00:00
parent 1d7446c500
commit a0d2326f9c
4 changed files with 157 additions and 23 deletions

View file

@ -74,6 +74,31 @@ sub audit {
}
#-------------------------------------------------------------------
=head2 canShowBasedOnIP ( $ipSetting )
Returns true if the the user's IP address matches the requested IP setting.
=head3 ipSetting
The setting to pull from the database. It should containt a CSV list of IP
addresses in CIDR format.
=cut
sub canShowBasedOnIP {
my $self = shift;
my $ipSetting = shift;
return 0 unless $ipSetting;
return 1 if ($self->session->setting->get($ipSetting) eq "");
my $ips = $self->session->setting->get($ipSetting);
$ips =~ s/\s+//g;
my @ips = split(",", $ips);
my $ok = WebGUI::Utility::isInSubnet($self->session->env->getIp, [ @ips] );
return $ok;
}
#-------------------------------------------------------------------
=head2 canShowDebug ( )
@ -86,12 +111,7 @@ sub canShowDebug {
my $self = shift;
return 0 unless ($self->session->setting->get("showDebug"));
return 0 unless (substr($self->session->http->getMimeType(),0,9) eq "text/html");
return 1 if ($self->session->setting->get("debugIp") eq "");
my $ips = $self->session->setting->get("debugIp");
$ips =~ s/\s+//g;
my @ips = split(",", $ips);
my $ok = WebGUI::Utility::isInSubnet($self->session->env->getIp, [ @ips] );
return $ok;
return $self->canShowBasedOnIP('debugIp');
}
#-------------------------------------------------------------------
@ -104,16 +124,8 @@ Returns true if the user meets the conditions to see performance indicators and
sub canShowPerformanceIndicators {
my $self = shift;
my $mask = $self->session->setting->get("debugIp");
my $ip = $self->session->env->getIp;
return (
(
$self->session->setting->get("showPerformanceIndicators")
) && (
$ip =~ /^$mask/ ||
$self->session->setting->get("debugIp") eq ""
)
);
return 0 unless $self->session->setting->get("showPerformanceIndicators");
return $self->canShowBasedOnIP('debugIp');
}

View file

@ -83,8 +83,8 @@ our $I18N = {
},
'debug ip description' => {
message => q|This will limit debugging output to a specific IP address or IP range. Enter the subnet that you want to be able to view debug output in CIDR format. For example: 10.0.0.0/24. Multiple CIDR addresses may be entered, separated by commas.|,
lastUpdated => 1139948380
message => q|This will limit debugging and/or performance output to a specific IP address or IP range. Enter the subnet that you want to be able to view debug output in CIDR format. For example: 10.0.0.0/24. Multiple CIDR addresses may be entered, separated by commas.|,
lastUpdated => 1164055466
},
'debug ip' => {