Here is a fix for tests/Test-proxied-https-auth.px.

- fixed the workflow of the test
- sync client and server on startup
- added valgrind support

Please review / test it (with GnuTLS and OpenSSL compiled Wget).

Tim
From 12fd2c5b6ebc5afe04e85b156b2d13f2fdb56096 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim Rühsen?= <[email protected]>
Date: Fri, 31 Oct 2014 09:40:21 +0100
Subject: [PATCH] fix tests/Test-proxied-https-auth.px

---
 tests/ChangeLog                  |  6 ++++
 tests/Test-proxied-https-auth.px | 62 ++++++++++++++++++++++++----------------
 2 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 5f37f63..2935b20 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-31  Tim Ruehsen <[email protected]>
+
+	* Test-proxied-https-auth.px: fix workflow,
+	  add valgrind support,
+	  sync parent / child (client / server)
+
 2014-10-30  Mike Frysinger <[email protected]>

 	* WgetFeature.pm: fix skip exit code to 77
diff --git a/tests/Test-proxied-https-auth.px b/tests/Test-proxied-https-auth.px
index 272003f..2bfaf9e 100755
--- a/tests/Test-proxied-https-auth.px
+++ b/tests/Test-proxied-https-auth.px
@@ -50,36 +50,38 @@ sub get_request {

 sub do_server {
     my ($synch_callback) = @_;
-    my $alrm = alarm 10;
     my $s = $SOCKET;
     my $conn;
     my $rqst;
     my $rspn;

+    # sync with the parent
     $synch_callback->();

-    for my $expect_inner_auth (0, 1) {
-        $conn = $s->accept;
-        $rqst = $conn->get_request;
-
-        # TODO: expect no auth the first time, request it, expect it the second
-        #   time.
-
-        die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
-        $rspn = HTTP::Response->new(200, 'OK');
-        $conn->send_response($rspn);
+    # Simulate a HTTPS proxy server with tunneling.

-        my %options = (
-            SSL_server => 1,
-            SSL_passwd_cb => sub { return "Hello"; });
+    $conn = $s->accept;
+    $rqst = $conn->get_request;
+    die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
+    $rspn = HTTP::Response->new(200, 'OK');
+    $conn->send_response($rspn);

-        $options{SSL_cert_file} = $cert_path if ($cert_path);
-        $options{SSL_key_file} = $key_path if ($key_path);
+    # The connection to the client is still alive at this point
+    #  now switch from plain to SSL (for simulating a transparent tunnel
+    #  to an HTTPS server.

-        my @options = %options;
+    my %options = (
+        SSL_server => 1,
+        SSL_passwd_cb => sub { return "Hello"; });
+    $options{SSL_cert_file} = $cert_path if ($cert_path);
+    $options{SSL_key_file} = $key_path if ($key_path);
+    my @options = %options;
+    $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options)
+        or die "Couldn't initiate SSL";

-        $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options)
-            or die "Couldn't initiate SSL";
+    for my $expect_inner_auth (0, 1) {
+        # TODO: expect no auth the first time, request it, expect it the second
+        #   time.

         $rqst = &get_request($conn)
             or die "Didn't get proxied request\n";
@@ -108,11 +110,11 @@ sub do_server {
             print STDERR "\n=====\n";
             print $conn $rspn->as_string;
         }
-        $conn->close;
     }
+
+    $conn->close;
     undef $conn;
     undef $s;
-    alarm $alrm;
 }

 sub fork_server {
@@ -126,6 +128,7 @@ sub fork_server {
         # child
         close FROM_CHILD;
         do_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
+        exit 0;
     } else {
         # parent
         close TO_PARENT;
@@ -136,7 +139,7 @@ sub fork_server {
     return $pid;
 }

-system ('rm -f needs-auth.txt');
+unlink "needs-auth.txt";
 my $pid = &fork_server;

 my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
@@ -145,9 +148,18 @@ my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
     . " https://no.such.domain/needs-auth.txt";;
 $cmdline =~ s/{{port}}/$SOCKET->sockport()/e;

-my $code = system($cmdline);
-system ('rm -f needs-auth.txt');
+my $valgrind = $ENV{VALGRIND_TESTS};
+if (!defined $valgrind || $valgrind eq "" || $valgrind == 0) {
+    # Valgrind not requested - leave $cmdline as it is
+} elsif ($valgrind == 1) {
+    $cmdline = "valgrind --error-exitcode01 --leak-check=yes --track-origins=yes " . $cmdline;
+} else {
+    $cmdline = $valgrind . " " . $cmdline;
+}
+
+my $code = system($cmdline . " 2>&1") >> 8;
+unlink "needs-auth.txt";

 warn "Got code: $code\n" if $code;
 kill ('TERM', $pid);
-exit ($code >> 8);
+exit ($code != 0);
--
2.1.1

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to