Permalink
Browse files

Merge pull request #22 from madsen/RT67947-verify_hostname

verify_hostname defaults to 0 if ssl_opts provided [RT#67947]
  • Loading branch information...
2 parents a406ab1 + a835fc7 commit 0a9516aa0d9c3167088a9a77b257360efe87651d @gisle committed Oct 14, 2011
Showing with 40 additions and 4 deletions.
  1. +2 −3 lib/LWP/UserAgent.pm
  2. +38 −1 t/base/ua.t
View
5 lib/LWP/UserAgent.pm
@@ -31,10 +31,9 @@ sub new
my $timeout = delete $cnf{timeout};
$timeout = 3*60 unless defined $timeout;
my $local_address = delete $cnf{local_address};
- my $ssl_opts = delete $cnf{ssl_opts};
- unless ($ssl_opts) {
+ my $ssl_opts = delete $cnf{ssl_opts} || {};
+ unless (exists $ssl_opts->{verify_hostname}) {
# The processing of HTTPS_CA_* below is for compatiblity with Crypt::SSLeay
- $ssl_opts = {};
if (exists $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}) {
$ssl_opts->{verify_hostname} = $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME};
}
View
39 t/base/ua.t
@@ -3,10 +3,17 @@
use strict;
use Test;
-plan tests => 21;
+plan tests => 31;
use LWP::UserAgent;
+# Prevent environment from interfering with test:
+delete $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME};
+delete $ENV{HTTPS_CA_FILE};
+delete $ENV{HTTPS_CA_DIR};
+delete $ENV{PERL_LWP_SSL_CA_FILE};
+delete $ENV{PERL_LWP_SSL_CA_PATH};
+
my $ua = LWP::UserAgent->new;
my $clone = $ua->clone;
@@ -55,3 +62,33 @@ ok($ua->ssl_opts("verify_hostname"), 0);
ok($ua->ssl_opts(verify_hostname => undef), 0);
ok($ua->ssl_opts("verify_hostname"), undef);
ok(join(":", $ua->ssl_opts), "");
+
+$ua = LWP::UserAgent->new(ssl_opts => {});
+ok($ua->ssl_opts("verify_hostname"), 1);
+
+$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
+ok($ua->ssl_opts("verify_hostname"), 0);
+
+$ua = LWP::UserAgent->new(ssl_opts => { SSL_ca_file => 'cert.dat'});
+ok($ua->ssl_opts("verify_hostname"), 1);
+ok($ua->ssl_opts("SSL_ca_file"), 'cert.dat');
+
+$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 1;
+$ua = LWP::UserAgent->new();
+ok($ua->ssl_opts("verify_hostname"), 1);
+
+$ua = LWP::UserAgent->new(ssl_opts => {});
+ok($ua->ssl_opts("verify_hostname"), 1);
+
+$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
+ok($ua->ssl_opts("verify_hostname"), 0);
+
+$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
+$ua = LWP::UserAgent->new();
+ok($ua->ssl_opts("verify_hostname"), 0);
+
+$ua = LWP::UserAgent->new(ssl_opts => {});
+ok($ua->ssl_opts("verify_hostname"), 0);
+
+$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
+ok($ua->ssl_opts("verify_hostname"), 1);

0 comments on commit 0a9516a

Please sign in to comment.