6 use WgetTest; # For $WGETPATH.
8 # Have we even built an HTTPS-supporting Wget?
10 my @version_lines = `${WgetTest::WGETPATH} --version`;
11 unless (grep /\+(openssl|gnutls)/, @version_lines) {
12 print "Not running test: Wget under test doesn't support HTTPS.\n";
21 my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost',
22 ReuseAddr => 1) or die "Cannot create server!!!";
29 while (defined ($line = <$conn>)) {
31 last if $line eq "\r\n";
34 my $rqst = HTTP::Request->parse($content)
35 or die "Couldn't parse request:\n$content\n";
47 for my $expect_inner_auth (0, 1) {
49 $rqst = $conn->get_request;
51 # TODO: expect no auth the first time, request it, expect it the second
54 die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
55 $rspn = HTTP::Response->new(200, 'OK');
56 $conn->send_response($rspn);
58 $conn = IO::Socket::SSL->new_from_fd($conn->fileno, SSL_server => 1,
59 SSL_passwd_cb => sub { return "Hello"; })
60 or die "Couldn't initiate SSL";
62 $rqst = &get_request($conn)
63 or die "Didn't get proxied request\n";
65 unless ($expect_inner_auth) {
66 die "Early proxied auth\n" if $rqst->header('Authorization');
68 # TODO: handle non-persistent connection here.
69 $rspn = HTTP::Response->new(401, 'Unauthorized', [
70 'WWW-Authenticate' => 'Basic realm="gondor"',
73 $rspn->protocol('HTTP/1.0');
74 print $rspn->as_string;
75 print $conn $rspn->as_string;
77 die "No proxied auth\n" unless $rqst->header('Authorization');
79 $rspn = HTTP::Response->new(200, 'OK', [
80 'Content-Type' => 'text/plain',
81 'Connection' => 'close',
83 $rspn->protocol('HTTP/1.0');
85 print $rspn->as_string;
87 print $conn $rspn->as_string;
98 die "Couldn't fork" if ($pid < 0);
105 system ('rm -f needs-auth.txt');
106 my $pid = &fork_server;
109 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
110 . " --password=Dodgson -e https_proxy=localhost:{{port}}"
111 . " --no-check-certificate"
112 . " https://no.such.domain/needs-auth.txt";
113 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
115 my $code = system($cmdline);
116 system ('rm -f needs-auth.txt');
118 warn "Got code: $code\n" if $code;