+2008-05-31 Micah Cowan <micah@cowan.name>
+
+ * Test-N-current.px: Ensure we catch failures.
+
+ * Test-N-old.px: Make it test only the timestamp, and not the
+ content length in addition.
+
+ * Test-N-smaller.px, Test-N-no-info.px: added.
+
+ * Test-c-partial.px: Improve checking that the file was
+ partially retrieved, rather than overwritten.
+
+ * run-px: Added Test-N-smaller.px, Test-N-no-info.px.
+
+ * HTTPServer.pm: Return 416 for fully-retrieved content, rather
+ than 206 with a zero content-length.
+
+2008-05-23 Micah Cowan <micah@cowan.name>
+
+ * Test--spider.px: Make test expect 0 return code.
+
+2008-05-22 Micah Cowan <micah@cowan.name>
+
+ * Makefile.am (run-px-tests): Replaced ugly list of tests with
+ run-px Perl script to manage running them.
+
+ * run-px: Added.
+
+ * FTPServer.pm (run): Avoid re-forking. Fixes bug #20458.
+
2008-04-26 Micah Cowan <micah@cowan.name>
* Makefile.am, Test-proxied-https-auth.px: Added a test for
print STDERR "got a connection from: $client_ipnum\n" if $log;
# fork off a process to handle this connection.
- my $pid = fork();
- unless (defined $pid) {
- warn "fork: $!";
- sleep 5; # Back off in case system is overloaded.
- next;
- }
-
- if ($pid == 0) { # Child process.
+ # my $pid = fork();
+ # unless (defined $pid) {
+ # warn "fork: $!";
+ # sleep 5; # Back off in case system is overloaded.
+ # next;
+ # }
+
+ if (1) { # Child process.
# install signals
$SIG{URG} = sub {
my $start = $1 ? $1 : 0;
my $end = $2 ? $2 : ($content_len - 1);
my $len = $2 ? ($2 - $start) : ($content_len - $start);
- $resp->header("Accept-Ranges" => "bytes");
- $resp->header("Content-Length" => $len);
- $resp->header("Content-Range" => "bytes $start-$end/$content_len");
- $resp->header("Keep-Alive" => "timeout=15, max=100");
- $resp->header("Connection" => "Keep-Alive");
- $con->send_basic_header(206, "Partial Content", $resp->protocol);
- print $con $resp->headers_as_string($CRLF);
- print $con $CRLF;
- print $con substr($content, $start, $len);
+ if ($len) {
+ $resp->header("Accept-Ranges" => "bytes");
+ $resp->header("Content-Length" => $len);
+ $resp->header("Content-Range"
+ => "bytes $start-$end/$content_len");
+ $resp->header("Keep-Alive" => "timeout=15, max=100");
+ $resp->header("Connection" => "Keep-Alive");
+ $con->send_basic_header(206,
+ "Partial Content", $resp->protocol);
+ print $con $resp->headers_as_string($CRLF);
+ print $con $CRLF;
+ print $con substr($content, $start, $len);
+ } else {
+ $con->send_basic_header(416, "Range Not Satisfiable",
+ $resp->protocol);
+ $resp->header("Keep-Alive" => "timeout=15, max=100");
+ $resp->header("Connection" => "Keep-Alive");
+ print $con $CRLF;
+ }
next;
}
# fill in content
./unit-tests$(EXEEXT)
run-px-tests: WgetTest.pm
- $(PERLRUN) $(srcdir)/Test-proxied-https-auth.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-proxy-auth-basic.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-auth-basic.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-c-full.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-c-partial.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-c.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-E-k-K.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-E-k.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-ftp.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-HTTP-Content-Disposition-1.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-HTTP-Content-Disposition-2.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-HTTP-Content-Disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N-current-HTTP-CD.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N-current.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N-HTTP-Content-Disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N--no-content-disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N--no-content-disposition-trivial.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--no-content-disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--no-content-disposition-trivial.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N-old.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-nonexisting-quiet.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-noop.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-np.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-N.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-O-HTTP-Content-Disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-O--no-content-disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-O--no-content-disposition-trivial.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-O-nonexisting.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-O.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-Restrict-Lowercase.px && echo && echo
- $(PERLRUN) $(srcdir)/Test-Restrict-Uppercase.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider-fail.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider-HTTP-Content-Disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider--no-content-disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider--no-content-disposition-trivial.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider-r-HTTP-Content-Disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider-r--no-content-disposition.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider-r--no-content-disposition-trivial.px && echo && echo
- $(PERLRUN) $(srcdir)/Test--spider-r.px && echo && echo
+ ./run-px $(top_srcdir)
EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \
Test-auth-basic.px Test-c-full.px Test-c-partial.px \
+++ /dev/null
-#!/usr/bin/perl -w
-
-use strict;
-
-use HTTPTest;
-
-
-###############################################################################
-
-my $mainpage = <<EOF;
-<html>
-<head>
- <title>Main Page</title>
-</head>
-<body>
- <p>
- Some text.
- </p>
-</body>
-</html>
-EOF
-
-# code, msg, headers, content
-my %urls = (
- '/index.html' => {
- code => "200",
- msg => "Dontcare",
- headers => {
- "Content-type" => "text/html",
- },
- content => $mainpage,
- },
-);
-
-my $cmdline = $WgetTest::WGETPATH . " --spider --no-content-disposition http://localhost:8080/index.html";
-
-my $expected_error_code = 256;
-
-my %expected_downloaded_files = (
-);
-
-###############################################################################
-
-my $the_test = HTTPTest->new (name => "Test--spider--no-content-disposition-trivial",
- input => \%urls,
- cmdline => $cmdline,
- errcode => $expected_error_code,
- output => \%expected_downloaded_files);
-exit $the_test->run();
-
-# vim: et ts=4 sw=4
-
+++ /dev/null
-#!/usr/bin/perl -w
-
-use strict;
-
-use HTTPTest;
-
-
-###############################################################################
-
-my $mainpage = <<EOF;
-<html>
-<head>
- <title>Main Page</title>
-</head>
-<body>
- <p>
- Some text.
- </p>
-</body>
-</html>
-EOF
-
-# code, msg, headers, content
-my %urls = (
- '/index.html' => {
- code => "200",
- msg => "Dontcare",
- headers => {
- "Content-type" => "text/html",
- "Content-Disposition" => "attachment; filename=\"filename.html\"",
- },
- content => $mainpage,
- },
-);
-
-my $cmdline = $WgetTest::WGETPATH . " --spider --no-content-disposition http://localhost:8080/index.html";
-
-my $expected_error_code = 256;
-
-my %expected_downloaded_files = (
-);
-
-###############################################################################
-
-my $the_test = HTTPTest->new (name => "Test--spider--no-content-disposition",
- input => \%urls,
- cmdline => $cmdline,
- errcode => $expected_error_code,
- output => \%expected_downloaded_files);
-exit $the_test->run();
-
-# vim: et ts=4 sw=4
-
+++ /dev/null
-#!/usr/bin/perl -w
-
-use strict;
-
-use HTTPTest;
-
-
-###############################################################################
-
-my $mainpage = <<EOF;
-<html>
-<head>
- <title>Main Page</title>
-</head>
-<body>
- <p>
- Some text.
- </p>
-</body>
-</html>
-EOF
-
-# code, msg, headers, content
-my %urls = (
- '/index.html' => {
- code => "200",
- msg => "Dontcare",
- headers => {
- "Content-type" => "text/html",
- "Content-Disposition" => "attachment; filename=\"filename.html\"",
- },
- content => $mainpage,
- },
-);
-
-my $cmdline = $WgetTest::WGETPATH . " --spider http://localhost:8080/index.html";
-
-my $expected_error_code = 256;
-
-my %expected_downloaded_files = (
-);
-
-###############################################################################
-
-my $the_test = HTTPTest->new (name => "Test--spider-HTTP-Content-Disposition",
- input => \%urls,
- cmdline => $cmdline,
- errcode => $expected_error_code,
- output => \%expected_downloaded_files);
-exit $the_test->run();
-
-# vim: et ts=4 sw=4
-
my $cmdline = $WgetTest::WGETPATH . " --spider http://localhost:8080/index.html";
-my $expected_error_code = 256;
+my $expected_error_code = 0;
my %expected_downloaded_files = (
);
},
);
-my $cmdline = $WgetTest::WGETPATH . " -N http://localhost:8080/dummy.txt";
+my $cmdline = $WgetTest::WGETPATH . " -N --content-disposition "
+ . "http://localhost:8080/dummy.txt";
my $expected_error_code = 0;
55555555555555555555555555555555555555555555555555
EOF
+# The server should serve a slightly different content, but with the
+# same length, so we can test which version was downloaded.
+my $modifiedversion = $currentversion;
+$modifiedversion =~ s/^(.{20}).(.*)$/$1x$2/s;
+
# code, msg, headers, content
my %urls = (
'/somefile.txt' => {
"Content-type" => "text/plain",
"Last-Modified" => "Sat, 09 Oct 2004 08:30:00 GMT",
},
- content => $currentversion,
+ content => $modifiedversion,
},
);
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+use HTTPTest;
+
+
+###############################################################################
+
+my $currentversion = <<EOF;
+11111111111111111111111111111111111111111111111111
+222222222222222222222222222222222222222222222222222222222222
+3333333333333333333333333333333333333333333333333333333333333333333333
+444444444444444444444444444444444444444444444444444444444444
+55555555555555555555555555555555555555555555555555
+EOF
+
+my $newversion = <<EOF;
+11111111111111111111111111111111111111111111111111
+222222222222222222222222222222222222222222222222222222222222
+EOF
+
+# code, msg, headers, content
+my %urls = (
+ '/somefile.txt' => {
+ code => "200",
+ msg => "Dontcare",
+ headers => {
+ "Content-type" => "text/plain",
+ },
+ content => $newversion,
+ },
+);
+
+my $cmdline = $WgetTest::WGETPATH . " -N http://localhost:8080/somefile.txt";
+
+my $expected_error_code = 0;
+
+my %existing_files = (
+ 'somefile.txt' => {
+ content => $currentversion,
+ timestamp => 1097310600, # "Sat, 09 Oct 2004 08:30:00 GMT"
+ },
+);
+
+my %expected_downloaded_files = (
+ 'somefile.txt' => {
+ content => $newversion,
+ },
+);
+
+###############################################################################
+
+my $the_test = HTTPTest->new (name => "Test-N-current",
+ input => \%urls,
+ cmdline => $cmdline,
+ errcode => $expected_error_code,
+ existing => \%existing_files,
+ output => \%expected_downloaded_files);
+exit $the_test->run();
+
+# vim: et ts=4 sw=4
+
my $oldversion = <<EOF;
11111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222
-EOF
-
-my $newversion = <<EOF;
-11111111111111111111111111111111111111111111111111
-222222222222222222222222222222222222222222222222222222222222
3333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444
55555555555555555555555555555555555555555555555555
EOF
+my $newversion = $oldversion;
+$newversion =~ s/^(.{20}).(.*)$/$1x$2/s;
+
# code, msg, headers, content
my %urls = (
'/somefile.txt' => {
--- /dev/null
+#!/usr/bin/perl -w
+
+use strict;
+
+use HTTPTest;
+
+
+###############################################################################
+
+my $currentversion = <<EOF;
+11111111111111111111111111111111111111111111111111
+222222222222222222222222222222222222222222222222222222222222
+3333333333333333333333333333333333333333333333333333333333333333333333
+444444444444444444444444444444444444444444444444444444444444
+55555555555555555555555555555555555555555555555555
+EOF
+
+my $newversion = <<EOF;
+11111111111111111111111111111111111111111111111111
+222222222222222222222222222222222222222222222222222222222222
+EOF
+
+# code, msg, headers, content
+my %urls = (
+ '/somefile.txt' => {
+ code => "200",
+ msg => "Dontcare",
+ headers => {
+ "Content-type" => "text/plain",
+ "Content-Length" => length $newversion,
+ "Last-Modified" => "Sat, 09 Oct 2004 08:30:00 GMT",
+ },
+ content => $newversion,
+ },
+);
+
+my $cmdline = $WgetTest::WGETPATH . " -N http://localhost:8080/somefile.txt";
+
+my $expected_error_code = 0;
+
+my %existing_files = (
+ 'somefile.txt' => {
+ content => $currentversion,
+ timestamp => 1097310600, # "Sat, 09 Oct 2004 08:30:00 GMT"
+ },
+);
+
+my %expected_downloaded_files = (
+ 'somefile.txt' => {
+ content => $newversion,
+ timestamp => 1097310600, # "Sat, 09 Oct 2004 08:30:00 GMT"
+ },
+);
+
+###############################################################################
+
+my $the_test = HTTPTest->new (name => "Test-N-current",
+ input => \%urls,
+ cmdline => $cmdline,
+ errcode => $expected_error_code,
+ existing => \%existing_files,
+ output => \%expected_downloaded_files);
+exit $the_test->run();
+
+# vim: et ts=4 sw=4
+
my $partiallydownloaded = <<EOF;
11111111111111111111111111111111111111111111111111
-222222222222222222222222222222222222222222222222222222222222
+22222222x222222222222222222222222222222222222222222222222222
EOF
-my $wholefile = <<EOF;
-11111111111111111111111111111111111111111111111111
-222222222222222222222222222222222222222222222222222222222222
+my $rest = <<EOF;
3333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444
55555555555555555555555555555555555555555555555555
EOF
+my $wholefile = <<EOF . $rest;
+11111111111111111111111111111111111111111111111111
+222222222222222222222222222222222222222222222222222222222222
+EOF
+
+my $downloadedfile = $partiallydownloaded . $rest;
+
# code, msg, headers, content
my %urls = (
'/somefile.txt' => {
my %expected_downloaded_files = (
'somefile.txt' => {
- content => $wholefile,
+ content => $downloadedfile,
},
);
--- /dev/null
+#!/usr/bin/env perl
+use warnings;
+
+die "Please specify the top source directory.\n" if (!@ARGV);
+my $top_srcdir = shift @ARGV;
+
+my @tests = (
+ 'Test-auth-basic.px',
+ 'Test-proxy-auth-basic.px',
+ 'Test-proxied-https-auth.px',
+ 'Test-N-HTTP-Content-Disposition.px',
+ 'Test--spider.px',
+ 'Test-c-full.px',
+ 'Test-c-partial.px',
+ 'Test-c.px',
+ 'Test-E-k-K.px',
+ 'Test-E-k.px',
+ 'Test-ftp.px',
+ 'Test-HTTP-Content-Disposition-1.px',
+ 'Test-HTTP-Content-Disposition-2.px',
+ 'Test-HTTP-Content-Disposition.px',
+ 'Test-N-current.px',
+ 'Test-N-smaller.px',
+ 'Test-N-no-info.px',
+ 'Test-N--no-content-disposition.px',
+ 'Test-N--no-content-disposition-trivial.px',
+ 'Test--no-content-disposition.px',
+ 'Test--no-content-disposition-trivial.px',
+ 'Test-N-old.px',
+ 'Test-nonexisting-quiet.px',
+ 'Test-noop.px',
+ 'Test-np.px',
+ 'Test-N.px',
+ 'Test-O-HTTP-Content-Disposition.px',
+ 'Test-O--no-content-disposition.px',
+ 'Test-O--no-content-disposition-trivial.px',
+ 'Test-O-nonexisting.px',
+ 'Test-O.px',
+ 'Test-Restrict-Lowercase.px',
+ 'Test-Restrict-Uppercase.px',
+ 'Test--spider-fail.px',
+ 'Test--spider-r-HTTP-Content-Disposition.px',
+ 'Test--spider-r--no-content-disposition.px',
+ 'Test--spider-r--no-content-disposition-trivial.px',
+ 'Test--spider-r.px',
+);
+
+my @results;
+
+for my $test (@tests) {
+ print "Running $test\n\n";
+ system("$top_srcdir/tests/$test");
+ push @results, $?;
+}
+
+for (my $i=0; $i != @tests; ++$i) {
+ if ($results[$i] == 0) {
+ print "pass: ";
+ } else {
+ print "FAIL: ";
+ }
+ print "$tests[$i]\n";
+}