mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
* Test-proxied-https-auth.px:
add valgrind support, sync parent / child (client / server) Fixed the missing synchronization between server and client. Without this, we experienced random test failures. Also added valgrind support.
This commit is contained in:
parent
e52879514f
commit
2303793a62
@ -1,3 +1,8 @@
|
|||||||
|
2014-11-03 Tim Ruehsen <tim.ruehsen@gmx.de>
|
||||||
|
|
||||||
|
* Test-proxied-https-auth.px: add valgrind support,
|
||||||
|
sync parent / child (client / server)
|
||||||
|
|
||||||
2014-10-31 Pär Karlsson <feinorgh@gmail.com>
|
2014-10-31 Pär Karlsson <feinorgh@gmail.com>
|
||||||
* WgetTests.pm: Proper conditional operators, tidied up code, idiomatic
|
* WgetTests.pm: Proper conditional operators, tidied up code, idiomatic
|
||||||
improvements as per modern Perl best practices.
|
improvements as per modern Perl best practices.
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
|
# Simulate a tunneling proxy to a HTTPS URL that needs authentication.
|
||||||
|
# Use two connections (Connection: close)
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
@ -50,33 +52,32 @@ sub get_request {
|
|||||||
|
|
||||||
sub do_server {
|
sub do_server {
|
||||||
my ($synch_callback) = @_;
|
my ($synch_callback) = @_;
|
||||||
my $alrm = alarm 10;
|
|
||||||
my $s = $SOCKET;
|
my $s = $SOCKET;
|
||||||
my $conn;
|
my $conn;
|
||||||
my $rqst;
|
my $rqst;
|
||||||
my $rspn;
|
my $rspn;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
# sync with the parent
|
||||||
$synch_callback->();
|
$synch_callback->();
|
||||||
|
|
||||||
|
# Simulate a HTTPS proxy server with tunneling.
|
||||||
|
|
||||||
for my $expect_inner_auth (0, 1) {
|
for my $expect_inner_auth (0, 1) {
|
||||||
$conn = $s->accept;
|
$conn = $s->accept;
|
||||||
$rqst = $conn->get_request;
|
$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');
|
die "Method not CONNECT\n" if ($rqst->method ne 'CONNECT');
|
||||||
$rspn = HTTP::Response->new(200, 'OK');
|
$rspn = HTTP::Response->new(200, 'OK');
|
||||||
$conn->send_response($rspn);
|
$conn->send_response($rspn);
|
||||||
|
|
||||||
my %options = (
|
# Now switch from plain to SSL (for simulating a transparent tunnel
|
||||||
SSL_server => 1,
|
# to an HTTPS server).
|
||||||
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)
|
$conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options)
|
||||||
or die "Couldn't initiate SSL";
|
or die "Couldn't initiate SSL";
|
||||||
@ -87,14 +88,10 @@ sub do_server {
|
|||||||
unless ($expect_inner_auth) {
|
unless ($expect_inner_auth) {
|
||||||
die "Early proxied auth\n" if $rqst->header('Authorization');
|
die "Early proxied auth\n" if $rqst->header('Authorization');
|
||||||
|
|
||||||
# TODO: handle non-persistent connection here.
|
|
||||||
$rspn = HTTP::Response->new(401, 'Unauthorized', [
|
$rspn = HTTP::Response->new(401, 'Unauthorized', [
|
||||||
'WWW-Authenticate' => 'Basic realm="gondor"',
|
'WWW-Authenticate' => 'Basic realm="gondor"',
|
||||||
Connection => 'close'
|
Connection => 'close'
|
||||||
]);
|
]);
|
||||||
$rspn->protocol('HTTP/1.0');
|
|
||||||
print STDERR $rspn->as_string;
|
|
||||||
print $conn $rspn->as_string;
|
|
||||||
} else {
|
} else {
|
||||||
die "No proxied auth\n" unless $rqst->header('Authorization');
|
die "No proxied auth\n" unless $rqst->header('Authorization');
|
||||||
|
|
||||||
@ -102,17 +99,19 @@ sub do_server {
|
|||||||
'Content-Type' => 'text/plain',
|
'Content-Type' => 'text/plain',
|
||||||
'Connection' => 'close',
|
'Connection' => 'close',
|
||||||
], "foobarbaz\n");
|
], "foobarbaz\n");
|
||||||
$rspn->protocol('HTTP/1.0');
|
|
||||||
print STDERR "=====\n";
|
|
||||||
print STDERR $rspn->as_string;
|
|
||||||
print STDERR "\n=====\n";
|
|
||||||
print $conn $rspn->as_string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rspn->protocol('HTTP/1.0');
|
||||||
|
print STDERR "=====\n";
|
||||||
|
print STDERR $rspn->as_string;
|
||||||
|
print STDERR "\n=====\n";
|
||||||
|
print $conn $rspn->as_string;
|
||||||
|
|
||||||
$conn->close;
|
$conn->close;
|
||||||
}
|
}
|
||||||
|
|
||||||
undef $conn;
|
undef $conn;
|
||||||
undef $s;
|
undef $s;
|
||||||
alarm $alrm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fork_server {
|
sub fork_server {
|
||||||
@ -126,6 +125,7 @@ sub fork_server {
|
|||||||
# child
|
# child
|
||||||
close FROM_CHILD;
|
close FROM_CHILD;
|
||||||
do_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
|
do_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
|
||||||
|
exit 0;
|
||||||
} else {
|
} else {
|
||||||
# parent
|
# parent
|
||||||
close TO_PARENT;
|
close TO_PARENT;
|
||||||
@ -136,7 +136,7 @@ sub fork_server {
|
|||||||
return $pid;
|
return $pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
system ('rm -f needs-auth.txt');
|
unlink "needs-auth.txt";
|
||||||
my $pid = &fork_server;
|
my $pid = &fork_server;
|
||||||
|
|
||||||
my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
|
my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
|
||||||
@ -145,9 +145,18 @@ my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee"
|
|||||||
. " https://no.such.domain/needs-auth.txt";
|
. " https://no.such.domain/needs-auth.txt";
|
||||||
$cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
|
$cmdline =~ s/{{port}}/$SOCKET->sockport()/e;
|
||||||
|
|
||||||
my $code = system($cmdline);
|
my $valgrind = $ENV{VALGRIND_TESTS};
|
||||||
system ('rm -f needs-auth.txt');
|
if (!defined $valgrind || $valgrind eq "" || $valgrind == 0) {
|
||||||
|
# Valgrind not requested - leave $cmdline as it is
|
||||||
|
} elsif ($valgrind == 1) {
|
||||||
|
$cmdline = "valgrind --error-exitcode=301 --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;
|
warn "Got code: $code\n" if $code;
|
||||||
kill ('TERM', $pid);
|
kill ('TERM', $pid);
|
||||||
exit ($code >> 8);
|
exit ($code != 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user