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

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