Blame SOURCES/wget-1.14-fix-synchronization-in-Test-proxied-https-auth.patch

87e294
From 082e7194605e99f0e50f8909fcaf10adee747cc8 Mon Sep 17 00:00:00 2001
87e294
From: Tomas Hozza <thozza@redhat.com>
87e294
Date: Fri, 5 May 2017 13:46:11 +0200
87e294
Subject: [PATCH] Fix client/server synchronization in
87e294
 Test-proxied-https-auth.px test
87e294
87e294
Combination of upstream commits vithout adding support for Valgrind:
87e294
3eff3ad69a46364475e1f4abdf9412cfa87e3d6c
87e294
2303793a626158627bdb2ac255e0f58697682b24
87e294
87e294
Signed-off-by: Tomas Hozza <thozza@redhat.com>
87e294
---
87e294
 tests/Test-proxied-https-auth.px | 82 +++++++++++++++++++++++-----------------
87e294
 1 file changed, 48 insertions(+), 34 deletions(-)
87e294
87e294
diff --git a/tests/Test-proxied-https-auth.px b/tests/Test-proxied-https-auth.px
87e294
index 1de5357..e1a6c44 100755
87e294
--- a/tests/Test-proxied-https-auth.px
87e294
+++ b/tests/Test-proxied-https-auth.px
87e294
@@ -1,4 +1,6 @@
87e294
 #!/usr/bin/env perl
87e294
+# Simulate a tunneling proxy to a HTTPS URL that needs authentication.
87e294
+# Use two connections (Connection: close)
87e294
 
87e294
 use strict;
87e294
 use warnings;
87e294
@@ -39,31 +41,33 @@ sub get_request {
87e294
 }
87e294
 
87e294
 sub do_server {
87e294
-    my $alrm = alarm 10;
87e294
-
87e294
+    my ($synch_callback) = @_;
87e294
     my $s = $SOCKET;
87e294
     my $conn;
87e294
     my $rqst;
87e294
     my $rspn;
87e294
+
87e294
+    my %options = (
87e294
+        SSL_server => 1,
87e294
+        SSL_passwd_cb => sub { return "Hello"; });
87e294
+    $options{SSL_cert_file} = $cert_path if ($cert_path);
87e294
+    $options{SSL_key_file} = $key_path if ($key_path);
87e294
+    my @options = %options;
87e294
+
87e294
+    # sync with the parent
87e294
+    $synch_callback->();
87e294
+
87e294
+    # Simulate a HTTPS proxy server with tunneling.
87e294
+
87e294
     for my $expect_inner_auth (0, 1) {
87e294
         $conn = $s->accept;
87e294
         $rqst = $conn->get_request;
87e294
-
87e294
-        # TODO: expect no auth the first time, request it, expect it the second
87e294
-        #   time.
87e294
-
87e294
         die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
87e294
         $rspn = HTTP::Response->new(200, 'OK');
87e294
         $conn->send_response($rspn);
87e294
 
87e294
-        my %options = (
87e294
-            SSL_server => 1,
87e294
-            SSL_passwd_cb => sub { return "Hello"; });
87e294
-
87e294
-        $options{SSL_cert_file} = $cert_path if ($cert_path);
87e294
-        $options{SSL_key_file} = $key_path if ($key_path);
87e294
-
87e294
-        my @options = %options;
87e294
+        # Now switch from plain to SSL (for simulating a transparent tunnel
87e294
+        # to an HTTPS server).
87e294
 
87e294
         $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options)
87e294
             or die "Couldn't initiate SSL";
87e294
@@ -74,14 +78,10 @@ sub do_server {
87e294
         unless ($expect_inner_auth) {
87e294
             die "Early proxied auth\n" if $rqst->header('Authorization');
87e294
 
87e294
-            # TODO: handle non-persistent connection here.
87e294
             $rspn = HTTP::Response->new(401, 'Unauthorized', [
87e294
                 'WWW-Authenticate' => 'Basic realm="gondor"',
87e294
                 Connection => 'close'
87e294
                 ]);
87e294
-            $rspn->protocol('HTTP/1.0');
87e294
-            print $rspn->as_string;
87e294
-            print $conn $rspn->as_string;
87e294
         } else {
87e294
             die "No proxied auth\n" unless $rqst->header('Authorization');
87e294
 
87e294
@@ -89,41 +89,55 @@ sub do_server {
87e294
                 'Content-Type' => 'text/plain',
87e294
                 'Connection' => 'close',
87e294
                 ], "foobarbaz\n");
87e294
-            $rspn->protocol('HTTP/1.0');
87e294
-            print "=====\n";
87e294
-            print $rspn->as_string;
87e294
-            print "\n=====\n";
87e294
-            print $conn $rspn->as_string;
87e294
         }
87e294
+
87e294
+        $rspn->protocol('HTTP/1.0');
87e294
+        print STDERR "=====\n";
87e294
+        print STDERR $rspn->as_string;
87e294
+        print STDERR "\n=====\n";
87e294
+        print $conn $rspn->as_string;
87e294
+
87e294
         $conn->close;
87e294
     }
87e294
+
87e294
     undef $conn;
87e294
     undef $s;
87e294
-    alarm $alrm;
87e294
 }
87e294
 
87e294
 sub fork_server {
87e294
-    my $pid = fork;
87e294
-    die "Couldn't fork" if ($pid < 0);
87e294
-    return $pid if $pid;
87e294
+    pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!";
87e294
+    select((select(TO_PARENT), $| = 1)[0]);
87e294
+
87e294
+    my $pid = fork();
87e294
+    if ($pid < 0) {
87e294
+        die "Cannot fork";
87e294
+    } elsif ($pid == 0) {
87e294
+        # child
87e294
+        close FROM_CHILD;
87e294
+        do_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
87e294
+        exit 0;
87e294
+    } else {
87e294
+        # parent
87e294
+        close TO_PARENT;
87e294
+        chomp(my $line = <FROM_CHILD>);
87e294
+        close FROM_CHILD;
87e294
+    }
87e294
 
87e294
-    &do_server;
87e294
-    exit;
87e294
+    return $pid;
87e294
 }
87e294
 
87e294
-system ('rm -f needs-auth.txt');
87e294
+unlink "needs-auth.txt";
87e294
 my $pid = &fork_server;
87e294
 
87e294
-sleep 1;
87e294
 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
87e294
     . " --password=Dodgson -e https_proxy=localhost:{{port}}"
87e294
     . " --no-check-certificate"
87e294
     . " https://no.such.domain/needs-auth.txt";
87e294
 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
87e294
 
87e294
-my $code = system($cmdline);
87e294
-system ('rm -f needs-auth.txt');
87e294
+my $code = system($cmdline . " 2>&1") >> 8;
87e294
+unlink "needs-auth.txt";
87e294
 
87e294
 warn "Got code: $code\n" if $code;
87e294
 kill ('TERM', $pid);
87e294
-exit ($code >> 8);
87e294
+exit ($code != 0);
87e294
-- 
87e294
2.7.4
87e294