[Bps-public-commit] LWP-UserAgent-Paranoid branch, master, updated. 0.96

Alex Vandiver alexmv at bestpractical.com
Mon Aug 11 13:48:21 EDT 2014


The branch, master has been updated
       via  26216dad8cd8e77ea68f894879bdc1569105f7e1 (commit)
       via  1e8775c389bf1e09d128949a4b2d2d7eb528d974 (commit)
      from  785e93765eeb6f333ac01c0563eb585c1bb0a7d7 (commit)

Summary of changes:
 Changes                       |  6 ++++++
 META.yml                      |  2 +-
 README                        | 11 ++++++++---
 lib/LWP/UserAgent/Paranoid.pm | 22 ++++++++++++++++------
 t/basic.t                     |  5 +++++
 5 files changed, 36 insertions(+), 10 deletions(-)

- Log -----------------------------------------------------------------
commit 1e8775c389bf1e09d128949a4b2d2d7eb528d974
Author: Thomas Sibley <tsibley at cpan.org>
Date:   Sat Aug 9 12:17:32 2014 -0700

    Make resolver read-only as setting it after creation doesn't work
    
    See [rt.cpan.org #97906].

diff --git a/README b/README
index 5373c52..804ba2b 100644
--- a/README
+++ b/README
@@ -11,6 +11,9 @@ SYNOPSIS
         # use $ua as a normal LWP::UserAgent...
         my $response = $ua->get("http://example.com");
 
+        # allow requests to localhost and 127.0.0.1
+        $ua->resolver->whitelisted_hosts(['localhost', '127.0.0.1']);
+
 DESCRIPTION
     This module is a more modern LWPx::ParanoidAgent with cleaner internals
     and a very similar feature set. It is a not a drop-in replacement,
@@ -60,9 +63,11 @@ METHODS
     seconds are OK.
 
   resolver
-    Gets/sets the DNS resolver which is used to block private hosts. There
-    is little need to set your own but if you do it should be an
-    Net::DNS::Paranoid object.
+    Gets the DNS resolver which is used to block private hosts. There is
+    little need to set your own but if you do it should be an
+    Net::DNS::Paranoid object. This attribute is read-only, so if you want
+    to replace the resolver you need to call "new" again to create a new
+    LWP::UserAgent::Paranoid.
 
     Use the blocking and whitelisting methods on the resolver to customize
     the behaviour.
diff --git a/lib/LWP/UserAgent/Paranoid.pm b/lib/LWP/UserAgent/Paranoid.pm
index 0976b4d..5ceca89 100644
--- a/lib/LWP/UserAgent/Paranoid.pm
+++ b/lib/LWP/UserAgent/Paranoid.pm
@@ -17,6 +17,7 @@ use Scalar::Util          qw/ refaddr /;
 use Time::HiRes           qw/ alarm /;
 use LWPx::ParanoidHandler qw//;
 use Net::DNS::Paranoid    qw//;
+use Carp                  qw//;
 
 =head1 SYNOPSIS
 
@@ -28,6 +29,9 @@ use Net::DNS::Paranoid    qw//;
     # use $ua as a normal LWP::UserAgent...
     my $response = $ua->get("http://example.com");
 
+    # allow requests to localhost and 127.0.0.1
+    $ua->resolver->whitelisted_hosts(['localhost', '127.0.0.1']);
+
 =head1 DESCRIPTION
 
 This module is a more modern L<LWPx::ParanoidAgent> with cleaner internals and
@@ -87,9 +91,10 @@ are OK.
 
 =head2 resolver
 
-Gets/sets the DNS resolver which is used to block private hosts.  There is
-little need to set your own but if you do it should be an L<Net::DNS::Paranoid>
-object.
+Gets the DNS resolver which is used to block private hosts.  There is little
+need to set your own but if you do it should be an L<Net::DNS::Paranoid>
+object.  This attribute is read-only, so if you want to replace the resolver
+you need to call L</new> again to create a new L<LWP::UserAgent::Paranoid>.
 
 Use the blocking and whitelisting methods on the resolver to customize the
 behaviour.
@@ -107,7 +112,7 @@ sub new {
 
     my $self = $class->SUPER::new(%opts);
     $self->request_timeout($timeout);
-    $self->resolver($resolver);
+    $self->_elem("resolver", $resolver);
 
     LWPx::ParanoidHandler::make_paranoid($self, $self->resolver);
 
@@ -115,7 +120,12 @@ sub new {
 }
 
 sub request_timeout { shift->_elem("request_timeout", @_) }
-sub resolver        { shift->_elem("resolver", @_) }
+sub resolver        {
+    my $self = shift;
+    Carp::croak("resolver is read-only; to use a new resolver, create a new user agent")
+        if @_;
+    return $self->_elem("resolver");
+}
 
 sub __timed_out { Carp::croak("Client timed out request") }
 sub __with_timeout {
diff --git a/t/basic.t b/t/basic.t
index 95f1a52..9f4a2b9 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -3,6 +3,7 @@ use warnings;
 
 use Test::More;
 use LWP::UserAgent::Paranoid::Test;
+use Net::DNS::Paranoid;
 
 my ($SERVER, $TCP) = server(sub { [200,[],["OK"]] });
 my $ua = create_ua_ok();
@@ -12,4 +13,8 @@ get_status_is($ua, $SERVER, 403, "localhost is forbidden");
 $ua->resolver->whitelisted_hosts(["127.0.0.1"]);
 get_status_is($ua, $SERVER, 200, "localhost is now OK");
 
+my ($ok, $err) = (eval { $ua->resolver( Net::DNS::Paranoid->new ) } || 0, $@);
+ok !$ok, "couldn't set new resolver";
+like $err, qr/resolver is read-only/, "resolver is read-only";
+
 done_testing;

commit 26216dad8cd8e77ea68f894879bdc1569105f7e1
Author: Thomas Sibley <tsibley at cpan.org>
Date:   Sat Aug 9 12:18:59 2014 -0700

    Releng for 0.96

diff --git a/Changes b/Changes
index 8430bab..75b4d3c 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,9 @@
+0.96    Sat Aug  9 12:10:11 PDT 2014
+    * Change resolver to read-only since setting it after ->new doesn't
+      actually work.  The method will now die if called as a setter, which
+      should catch existing uses.  Thanks to Randy Stauner for the report!
+      Fixes [rt.cpan.org #97906].
+
 0.95    Thu Jun 19 12:10:48 PDT 2014
     * Require Time::HiRes 1.9716 to fix a non-functional alarm()
       (Thomas Sibley)
diff --git a/META.yml b/META.yml
index a718ef0..5c903e7 100644
--- a/META.yml
+++ b/META.yml
@@ -30,4 +30,4 @@ requires:
 resources:
   license: http://opensource.org/licenses/gpl-license.php
   repository: https://github.com/bestpractical/lwp-useragent-paranoid.git
-version: 0.95
+version: 0.96
diff --git a/lib/LWP/UserAgent/Paranoid.pm b/lib/LWP/UserAgent/Paranoid.pm
index 5ceca89..1a8895f 100644
--- a/lib/LWP/UserAgent/Paranoid.pm
+++ b/lib/LWP/UserAgent/Paranoid.pm
@@ -11,7 +11,7 @@ LWP::UserAgent::Paranoid - A modern LWPx::ParanoidAgent for safer requests
 package LWP::UserAgent::Paranoid;
 use base 'LWP::UserAgent';
 
-our $VERSION = "0.95";
+our $VERSION = "0.96";
 
 use Scalar::Util          qw/ refaddr /;
 use Time::HiRes           qw/ alarm /;

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list