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

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