6 use WgetTest; # For $WGETPATH.
12 my $top_srcdir = shift @ARGV;
13 $key_path = "$top_srcdir/tests/certs/server-key.pem";
14 $cert_path = "$top_srcdir/tests/certs/server-cert.pem";
17 # Have we even built an HTTPS-supporting Wget?
19 my @version_lines = `${WgetTest::WGETPATH} --version`;
20 unless (grep /\+(openssl|gnutls)/, @version_lines) {
21 print "Not running test: Wget under test doesn't support HTTPS.\n";
30 my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost',
31 ReuseAddr => 1) or die "Cannot create server!!!";
38 while (defined ($line = <$conn>)) {
40 last if $line eq "\r\n";
43 my $rqst = HTTP::Request->parse($content)
44 or die "Couldn't parse request:\n$content\n";
56 for my $expect_inner_auth (0, 1) {
58 $rqst = $conn->get_request;
60 # TODO: expect no auth the first time, request it, expect it the second
63 die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
64 $rspn = HTTP::Response->new(200, 'OK');
65 $conn->send_response($rspn);
69 SSL_passwd_cb => sub { return "Hello"; });
71 $options{SSL_cert_file} = $cert_path if ($cert_path);
72 $options{SSL_key_file} = $key_path if ($key_path);
74 my @options = %options;
76 $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options)
77 or die "Couldn't initiate SSL";
79 $rqst = &get_request($conn)
80 or die "Didn't get proxied request\n";
82 unless ($expect_inner_auth) {
83 die "Early proxied auth\n" if $rqst->header('Authorization');
85 # TODO: handle non-persistent connection here.
86 $rspn = HTTP::Response->new(401, 'Unauthorized', [
87 'WWW-Authenticate' => 'Basic realm="gondor"',
90 $rspn->protocol('HTTP/1.0');
91 print $rspn->as_string;
92 print $conn $rspn->as_string;
94 die "No proxied auth\n" unless $rqst->header('Authorization');
96 $rspn = HTTP::Response->new(200, 'OK', [
97 'Content-Type' => 'text/plain',
98 'Connection' => 'close',
100 $rspn->protocol('HTTP/1.0');
102 print $rspn->as_string;
104 print $conn $rspn->as_string;
115 die "Couldn't fork" if ($pid < 0);
122 system ('rm -f needs-auth.txt');
123 my $pid = &fork_server;
126 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
127 . " --password=Dodgson -e https_proxy=localhost:{{port}}"
128 . " --no-check-certificate"
129 . " https://no.such.domain/needs-auth.txt";
130 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
132 my $code = system($cmdline);
133 system ('rm -f needs-auth.txt');
135 warn "Got code: $code\n" if $code;