5 use WgetTest; # For $WGETPATH.
7 # Have we even built an HTTPS-supporting Wget?
9 my @version_lines = `${WgetTest::WGETPATH} --version`;
10 unless (grep /\+(openssl|gnutls)/, @version_lines) {
11 print "Not running test: Wget under test doesn't support HTTPS.\n";
20 my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost',
21 ReuseAddr => 1) or die "Cannot create server!!!";
28 while (defined ($line = <$conn>)) {
30 last if $line eq "\r\n";
33 my $rqst = HTTP::Request->parse($content)
34 or die "Couldn't parse request:\n$content\n";
46 for my $expect_inner_auth (0, 1) {
48 $rqst = $conn->get_request;
50 # TODO: expect no auth the first time, request it, expect it the second
53 die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
54 $rspn = HTTP::Response->new(200, 'OK');
55 $conn->send_response($rspn);
57 $conn = IO::Socket::SSL->new_from_fd($conn->fileno, SSL_server => 1,
58 SSL_passwd_cb => sub { return "Hello"; })
59 or die "Couldn't initiate SSL";
61 $rqst = &get_request($conn)
62 or die "Didn't get proxied request\n";
64 unless ($expect_inner_auth) {
65 die "Early proxied auth\n" if $rqst->header('Authorization');
67 # TODO: handle non-persistent connection here.
68 $rspn = HTTP::Response->new(401, 'Unauthorized', [
69 'WWW-Authenticate' => 'Basic realm="gondor"',
72 $rspn->protocol('HTTP/1.0');
73 print $rspn->as_string;
74 print $conn $rspn->as_string;
76 die "No proxied auth\n" unless $rqst->header('Authorization');
78 $rspn = HTTP::Response->new(200, 'OK', [
79 'Content-Type' => 'text/plain',
80 'Connection' => 'close',
82 $rspn->protocol('HTTP/1.0');
84 print $rspn->as_string;
86 print $conn $rspn->as_string;
97 die "Couldn't fork" if ($pid < 0);
104 system ('rm -f needs-auth.txt');
105 my $pid = &fork_server;
108 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
109 . " --password=Dodgson -e https_proxy=localhost:{{port}}"
110 . " --no-check-certificate"
111 . " https://no.such.domain/needs-auth.txt";
112 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
114 my $code = system($cmdline);
115 system ('rm -f needs-auth.txt');
117 warn "Got code: $code\n" if $code;