Permalink
Browse files

add support for ssl proxy and proxy auth

  • Loading branch information...
sni committed Nov 18, 2013
1 parent dc481e1 commit a4df2dc34a0c5f27eb4b958636548c8d493276f0
Showing with 52 additions and 12 deletions.
  1. +3 −0 Webinject/Changes
  2. +41 −10 Webinject/lib/Webinject.pm
  3. +8 −2 Webinject/t/06-Proxy.t
View
@@ -7,6 +7,9 @@ For information and documentation, visit the website at http://www.webinject.org
---------------------------------
Release History:
+Version 1.86 - Mon Nov 18 12:10:07 CET 2013
+ - add support for ssl proxy and proxy auth
+
Version 1.84 - Fri Nov 1 11:01:23 CET 2013
- add realserver support (Klapwijk)
View
@@ -92,6 +92,12 @@ Set maximum number of HTTP redirects. Default is 0.
Sets a proxy which is then used for http and https requests.
+ ex.: http://proxy.company.net:3128
+
+with authentication:
+
+ ex.: http://user:password@proxy.company.net:3128
+
=item output_dir
Output directory where all logfiles will go to. Defaults to current directory.
@@ -189,8 +195,6 @@ sub engine {
$self->_processcasefile();
- my $useragent = $self->_get_useragent();
-
# write opening tags for STDOUT.
$self->_writeinitialstdout();
@@ -298,9 +302,6 @@ sub engine {
my $endruntimer = time();
$self->{'result'}->{'totalruntime'} = ( int( 1000 * ( $endruntimer - $startruntimer ) ) / 1000 ); #elapsed time rounded to thousandths
- # required to clean up cookie files
- undef $useragent;
-
# do return/cleanup tasks
return $self->_finaltasks();
}
@@ -580,10 +581,10 @@ sub _run_test_case {
################################################################################
sub _get_useragent {
- my $self = shift;
+ my($self) = @_;
# construct LWP object
- my $useragent = LWP::UserAgent->new(keep_alive=>1);
+ my $useragent = LWP::UserAgent->new(); # do not set keepalive here, it breaks ssl proxy support
# store cookies in our LWP object
my($fh, $cookietempfilename) = tempfile(undef, UNLINK => 1);
@@ -603,10 +604,40 @@ sub _get_useragent {
# add proxy support if it is set in config.xml
if( $self->{'config'}->{'proxy'} ) {
+ # try IO::Socket::SSL first
+ eval {
+ require IO::Socket::SSL;
+ IO::Socket::SSL->import();
+ };
my $proxy = $self->{'config'}->{'proxy'};
- $proxy =~ s/^http:\/\///mx;
- $useragent->proxy([qw( http )], "http://".$proxy);
- $ENV{'HTTPS_PROXY'} = "http://".$proxy;
+ $proxy =~ s/^http(s|):\/\///mx;
+ # http just works
+ $useragent->proxy('http', 'http://'.$proxy);
+ # authentication?
+ my $proxyuser = '';
+ my $proxypass = '';
+ if($proxy =~ s/^(.*?):(.*?)@(.*)$/$3/gmx) {
+ $proxyuser = $1;
+ $proxypass = $2;
+ }
+ # ssl depends on which class we have
+ if($INC{'IO/Socket/SSL.pm'}) {
+ $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "IO::Socket::SSL";
+ if($proxypass) {
+ $proxy = $proxyuser.':'.$proxypass.'@'.$proxy;
+ }
+ my $con_proxy = 'connect://'.$proxy;
+ $useragent->proxy('https', $con_proxy);
+ } else {
+ # ssl proxy only works this way, see http://community.activestate.com/forum-topic/lwp-https-requests-proxy
+ $ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL";
+ $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
+ $ENV{HTTPS_PROXY} = $proxy;
+ $ENV{HTTPS_PROXY_USERNAME} = $proxyuser;
+ $ENV{HTTPS_PROXY_PASSWORD} = $proxypass;
+ # env proxy breaks the ssl proxy above
+ #$useragent->env_proxy();
+ }
}
# don't follow redirects unless set by config
View
@@ -25,6 +25,7 @@ use_ok('Webinject');
my $webinject = Webinject->new();
isa_ok($webinject, "Webinject", 'Object is a Webinject');
+# clean env
for my $key (qw/http_proxy https_proxy HTTP_PROXY HTTPS_PROXY/) {
delete($ENV{$key});
}
@@ -50,17 +51,22 @@ sub test_case {
'verifyresponsecode' => 200,
'verifypositive' => 'Google',
'url' => $url,
+ 'warning' => 30,
+ 'critical' => 30,
};
my $expected = {
'id' => 1,
- 'passedcount' => 2,
+ 'passedcount' => 4,
'failedcount' => 0,
'url' => $case->{'url'},
'logresponse' => 'yes',
'logrequest' => 'yes',
'verifyresponsecode' => 200,
'verifypositive' => $case->{'verifypositive'},
-
+ 'iscritical' => 0,
+ 'iswarning' => 0,
+ 'warning' => 30,
+ 'critical' => 30,
};
my $result = $webinject->_run_test_case($case);

0 comments on commit a4df2dc

Please sign in to comment.