diff --git a/tests/ChangeLog b/tests/ChangeLog index f485f93c..73d93a2f 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,33 @@ +2008-05-31 Micah Cowan + + * 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 + + * Test--spider.px: Make test expect 0 return code. + +2008-05-22 Micah Cowan + + * 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 * Makefile.am, Test-proxied-https-auth.px: Added a test for diff --git a/tests/FTPServer.pm b/tests/FTPServer.pm index 7c7f3e58..d8ad8b0c 100644 --- a/tests/FTPServer.pm +++ b/tests/FTPServer.pm @@ -833,14 +833,14 @@ sub run 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; - } + # my $pid = fork(); + # unless (defined $pid) { + # warn "fork: $!"; + # sleep 5; # Back off in case system is overloaded. + # next; + # } - if ($pid == 0) { # Child process. + if (1) { # Child process. # install signals $SIG{URG} = sub { diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index 97e91396..a307b737 100644 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -98,15 +98,25 @@ sub send_response { 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 diff --git a/tests/Makefile.am b/tests/Makefile.am index fefdbf1d..85369828 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,46 +46,7 @@ run-unit-tests: unit-tests$(EXEEXT) ./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 \ diff --git a/tests/Test--spider--no-content-disposition-trivial.px b/tests/Test--spider--no-content-disposition-trivial.px deleted file mode 100755 index 323db074..00000000 --- a/tests/Test--spider--no-content-disposition-trivial.px +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -use HTTPTest; - - -############################################################################### - -my $mainpage = < - - Main Page - - -

- Some text. -

- - -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 - diff --git a/tests/Test--spider--no-content-disposition.px b/tests/Test--spider--no-content-disposition.px deleted file mode 100755 index acf73a79..00000000 --- a/tests/Test--spider--no-content-disposition.px +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -use HTTPTest; - - -############################################################################### - -my $mainpage = < - - Main Page - - -

- Some text. -

- - -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 - diff --git a/tests/Test--spider-HTTP-Content-Disposition.px b/tests/Test--spider-HTTP-Content-Disposition.px deleted file mode 100755 index 79eaba5a..00000000 --- a/tests/Test--spider-HTTP-Content-Disposition.px +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -use HTTPTest; - - -############################################################################### - -my $mainpage = < - - Main Page - - -

- Some text. -

- - -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 - diff --git a/tests/Test--spider.px b/tests/Test--spider.px index c2c1263e..f412c762 100755 --- a/tests/Test--spider.px +++ b/tests/Test--spider.px @@ -34,7 +34,7 @@ my %urls = ( my $cmdline = $WgetTest::WGETPATH . " --spider http://localhost:8080/index.html"; -my $expected_error_code = 256; +my $expected_error_code = 0; my %expected_downloaded_files = ( ); diff --git a/tests/Test-N-HTTP-Content-Disposition.px b/tests/Test-N-HTTP-Content-Disposition.px index 8c5e4181..42aa39ad 100755 --- a/tests/Test-N-HTTP-Content-Disposition.px +++ b/tests/Test-N-HTTP-Content-Disposition.px @@ -25,7 +25,8 @@ my %urls = ( }, ); -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; diff --git a/tests/Test-N-current.px b/tests/Test-N-current.px index 47003c7e..16086ae8 100755 --- a/tests/Test-N-current.px +++ b/tests/Test-N-current.px @@ -15,6 +15,11 @@ my $currentversion = < { @@ -24,7 +29,7 @@ my %urls = ( "Content-type" => "text/plain", "Last-Modified" => "Sat, 09 Oct 2004 08:30:00 GMT", }, - content => $currentversion, + content => $modifiedversion, }, ); diff --git a/tests/Test-N-no-info.px b/tests/Test-N-no-info.px new file mode 100755 index 00000000..bd83f644 --- /dev/null +++ b/tests/Test-N-no-info.px @@ -0,0 +1,63 @@ +#!/usr/bin/perl -w + +use strict; + +use HTTPTest; + + +############################################################################### + +my $currentversion = < { + 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 + diff --git a/tests/Test-N-old.px b/tests/Test-N-old.px index 05383dbe..ee9a84e0 100755 --- a/tests/Test-N-old.px +++ b/tests/Test-N-old.px @@ -10,16 +10,14 @@ use HTTPTest; my $oldversion = < { diff --git a/tests/Test-N-smaller.px b/tests/Test-N-smaller.px new file mode 100755 index 00000000..9ad44c29 --- /dev/null +++ b/tests/Test-N-smaller.px @@ -0,0 +1,66 @@ +#!/usr/bin/perl -w + +use strict; + +use HTTPTest; + + +############################################################################### + +my $currentversion = < { + 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 + diff --git a/tests/Test-c-partial.px b/tests/Test-c-partial.px index ee48cbf6..ddf1d4be 100755 --- a/tests/Test-c-partial.px +++ b/tests/Test-c-partial.px @@ -9,17 +9,22 @@ use HTTPTest; my $partiallydownloaded = < { @@ -44,7 +49,7 @@ my %existing_files = ( my %expected_downloaded_files = ( 'somefile.txt' => { - content => $wholefile, + content => $downloadedfile, }, ); diff --git a/tests/run-px b/tests/run-px new file mode 100755 index 00000000..febb0de4 --- /dev/null +++ b/tests/run-px @@ -0,0 +1,63 @@ +#!/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"; +}