X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=tests%2FTest-proxied-https-auth.px;h=1de535786321ed379ddc78f57a80f53e710b490e;hp=b732d553bab3f626a5d5e0e4260bfa88d21340e6;hb=HEAD;hpb=8e9648a972b88fa6eb2293383bd281c6021394d2 diff --git a/tests/Test-proxied-https-auth.px b/tests/Test-proxied-https-auth.px index b732d553..1de53578 100755 --- a/tests/Test-proxied-https-auth.px +++ b/tests/Test-proxied-https-auth.px @@ -1,11 +1,26 @@ -#!/usr/bin/perl -use warnings; +#!/usr/bin/env perl + use strict; +use warnings; +use WgetFeature qw(https); use WgetTest; # For $WGETPATH. + +my $cert_path; +my $key_path; + +if (@ARGV) { + my $top_srcdir = shift @ARGV; + $key_path = "$top_srcdir/tests/certs/server-key.pem"; + $cert_path = "$top_srcdir/tests/certs/server-cert.pem"; +} + use HTTP::Daemon; use HTTP::Request; -use IO::Socket::SSL 'debug4'; +use IO::Socket::SSL; + +my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost', + ReuseAddr => 1) or die "Cannot create server!!!"; sub get_request { my $conn = shift; @@ -26,9 +41,7 @@ sub get_request { sub do_server { my $alrm = alarm 10; - my $s = HTTP::Daemon->new (LocalAddr => 'localhost', - LocalPort => '8080', - ReuseAddr => 1) or die "Cannot create server!!!"; + my $s = $SOCKET; my $conn; my $rqst; my $rspn; @@ -43,8 +56,16 @@ sub do_server { $rspn = HTTP::Response->new(200, 'OK'); $conn->send_response($rspn); - $conn = IO::Socket::SSL->new_from_fd($conn->fileno, SSL_server => 1, - SSL_passwd_cb => sub { return "Hello"; }) + my %options = ( + SSL_server => 1, + SSL_passwd_cb => sub { return "Hello"; }); + + $options{SSL_cert_file} = $cert_path if ($cert_path); + $options{SSL_key_file} = $key_path if ($key_path); + + my @options = %options; + + $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options) or die "Couldn't initiate SSL"; $rqst = &get_request($conn) @@ -68,6 +89,10 @@ sub do_server { 'Content-Type' => 'text/plain', 'Connection' => 'close', ], "foobarbaz\n"); + $rspn->protocol('HTTP/1.0'); + print "=====\n"; + print $rspn->as_string; + print "\n=====\n"; print $conn $rspn->as_string; } $conn->close; @@ -94,9 +119,11 @@ my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee" . " --password=Dodgson -e https_proxy=localhost:{{port}}" . " --no-check-certificate" . " https://no.such.domain/needs-auth.txt"; +$cmdline =~ s/{{port}}/$SOCKET->sockport()/e; my $code = system($cmdline); +system ('rm -f needs-auth.txt'); warn "Got code: $code\n" if $code; kill ('TERM', $pid); -exit $code; +exit ($code >> 8);