diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-03-05 10:08:13 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-03-05 10:08:13 +0900 |
commit | 61fb427c104d6f2334aaee9c7d90d8287d521b17 (patch) | |
tree | e4caa30fa69cb51705f22392cab8cf9c04dffb94 /tests | |
parent | 1478f6ab011981e9a986c0c30da680635d3e77bf (diff) | |
download | wget-61fb427c104d6f2334aaee9c7d90d8287d521b17.tar.gz wget-61fb427c104d6f2334aaee9c7d90d8287d521b17.tar.bz2 wget-61fb427c104d6f2334aaee9c7d90d8287d521b17.zip |
Imported Upstream version 1.16.1upstream/1.16.1
Diffstat (limited to 'tests')
94 files changed, 2202 insertions, 1241 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index a873f7e..4f81679 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,222 @@ +2014-11-26 Tim Ruehsen <tim.ruehsen@gmx.de> + + * HTTPServer.pm: Substitue server port in HTTP headers + + This allows us to use references like + "Location" => "http://localhost:{{port}}/whatever + in test cases. + +2014-11-05 Tim Ruehsen <tim.ruehsen@gmx.de> + + * Makefile.am: added $(LIB_CLOCK_GETTIME) to unit test linkage + + Reported-by: kdevel@vogtner.de + +2014-11-05 Tim Ruehsen <tim.ruehsen@gmx.de> + + * Test-stdouterr.px: fix skip exit code to 77 + +2014-11-03 Pär Karlsson <feinorgh@gmail.com> + * WgetFeature.pm: Fixed finding of WgetFeature.cfg when using separate + build dirs. + * WgetFeature.pm: Fixed warning from BLOCK eval, made it indo EXPR eval + +2014-11-03 Tim Ruehsen <tim.ruehsen@gmx.de> + + * added new test Test-proxied-https-auth-keepalive.px + +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> + * WgetTests.pm: Proper conditional operators, tidied up code, idiomatic + improvements as per modern Perl best practices. + * WgetFeature.pm: Tidied up code, idiomatic improvements for readability + * FTPServer.pm: Tidied up code (perltidy -gnu) + * FTPTest.pm: Likewise + * HTTPServer.pm: Likewise + * HTTPTest.pm: Likewise + +2014-10-30 Mike Frysinger <vapier@gentoo.org> + + * WgetFeature.pm: fix skip exit code to 77 + +2014-10-25 Tim Ruehsen <tim.ruehsen@gmx.de> + + * WgetTests.pm (run): generate valgrind command line if requested + * Makefile.am: set/export VALGRIND_TESTS + +2014-10-28 Tim Ruehsen <tim.ruehsen@gmx.de> + + * tests/Test-proxied-https-auth.px: synchronize client and server + +2014-10-28 Giuseppe Scrivano <gscrivan@redhat.com> + + * Makefile.am: Replace $FOO with @VAR@. + +2014-10-06 Tim Ruehsen <tim.ruehsen@gmx.de> + + * Test-iri.px: fixed encodings + * Test-iri-forced-remote.px: fixed encodings + * Test-iri-percent.px: fixed encodings + * Test-idn-meta.px: fixed encodings + +2014-10-02 Tim Ruehsen <tim.ruehsen@gmx.de> + + * tests/WgetTests.pm: use filename as default test name + * tests/Test-*.px: removed redundant 'name => ...' + +2014-10-01 Tim Ruehsen <tim.ruehsen@gmx.de> + + * tests/Makefile.am: remove run-px, fixing dist-check + +2014-10-01 Tim Ruehsen <tim.ruehsen@gmx.de> + + * Test--post-file.px: name => "Test--post-file", fixing race + condition. + * Test-N-no-info.px: name => "Test-N-no-info", fixing race + condition. + * Test-N-smaller.px: name => "Test-N-smaller", fixing race + condition. + * Test-c-shorter.px: name => "Test-c-shorter", fixing race + condition. + * Test-proxy-auth-basic.px: name => "Test-proxy-auth-basic", + fixing race condition. + * Test-proxied-https-auth.px: removed debug print line. + +2014-09-25 Tim Ruehsen <tim.ruehsen@gmx.de> + + * Makefile.am: Modified to use parallel test harness + * Test-proxied-https-auth.px: get $top_srcdir from ENV + * run-px: removed + * WgetTest.pm.in: removed + * WgetTest.pm: get $top_srcdir from ENV + +2014-06-11 Giuseppe Scrivano <gscrivan@redhat.com> + + * Makefile.am: Remove @VAR@ with $FOO. + + * FTPTest.pm: Remove terminating empty lines. + * HTTPServer.pm: Likewise. + * HTTPTest.pm: Likewise. + * Test--httpsonly-r.px: Likewise. + * Test--no-content-disposition-trivial.px: Likewise. + * Test--no-content-disposition.px: Likewise. + * Test--spider-fail.px: Likewise. + * Test--spider-r--no-content-disposition-trivial.px: Likewise. + * Test--spider-r--no-content-disposition.px: Likewise. + * Test--spider-r-HTTP-Content-Disposition.px: Likewise. + * Test--spider-r.px: Likewise. + * Test--spider.px: Likewise. + * Test--start-pos--continue.px: Likewise. + * Test--start-pos.px: Likewise. + * Test-E-k-K.px: Likewise. + * Test-E-k.px: Likewise. + * Test-HTTP-Content-Disposition-1.px: Likewise. + * Test-HTTP-Content-Disposition-2.px: Likewise. + * Test-HTTP-Content-Disposition.px: Likewise. + * Test-N--no-content-disposition-trivial.px: Likewise. + * Test-N--no-content-disposition.px: Likewise. + * Test-N-HTTP-Content-Disposition.px: Likewise. + * Test-N-current.px: Likewise. + * Test-N-no-info.px: Likewise. + * Test-N-old.px: Likewise. + * Test-N-smaller.px: Likewise. + * Test-N.px: Likewise. + * Test-O--no-content-disposition-trivial.px: Likewise. + * Test-O--no-content-disposition.px: Likewise. + * Test-O-HTTP-Content-Disposition.px: Likewise. + * Test-O-nc.px: Likewise. + * Test-O-nonexisting.px: Likewise. + * Test-O.px: Likewise. + * Test-Restrict-Lowercase.px: Likewise. + * Test-Restrict-Uppercase.px: Likewise. + * Test-auth-basic.px: Likewise. + * Test-auth-no-challenge-url.px: Likewise. + * Test-auth-no-challenge.px: Likewise. + * Test-auth-with-content-disposition.px: Likewise. + * Test-c-full.px: Likewise. + * Test-c-partial.px: Likewise. + * Test-c-shorter.px: Likewise. + * Test-c.px: Likewise. + * Test-cookies-401.px: Likewise. + * Test-cookies.px: Likewise. + * Test-ftp--start-pos.px: Likewise. + * Test-ftp-bad-list.px: Likewise. + * Test-ftp-iri-disabled.px: Likewise. + * Test-ftp-iri-fallback.px: Likewise. + * Test-ftp-iri-recursive.px: Likewise. + * Test-ftp-iri.px: Likewise. + * Test-ftp-list-Multinet.px: Likewise. + * Test-ftp-list-UNIX-hidden.px: Likewise. + * Test-ftp-list-Unknown-a.px: Likewise. + * Test-ftp-list-Unknown-hidden.px: Likewise. + * Test-ftp-list-Unknown-list-a-fails.px: Likewise. + * Test-ftp-list-Unknown.px: Likewise. + * Test-ftp-pasv-fail.px: Likewise. + * Test-ftp-recursive.px: Likewise. + * Test-ftp.px: Likewise. + * Test-i-ftp.px: Likewise. + * Test-i-http.px: Likewise. + * Test-idn-cmd-utf8.px: Likewise. + * Test-idn-cmd.px: Likewise. + * Test-idn-headers.px: Likewise. + * Test-idn-meta.px: Likewise. + * Test-idn-robots-utf8.px: Likewise. + * Test-idn-robots.px: Likewise. + * Test-iri-disabled.px: Likewise. + * Test-iri-forced-remote.px: Likewise. + * Test-iri-list.px: Likewise. + * Test-iri-percent.px: Likewise. + * Test-iri.px: Likewise. + * Test-k.px: Likewise. + * Test-meta-robots.px: Likewise. + * Test-nonexisting-quiet.px: Likewise. + * Test-noop.px: Likewise. + * Test-np.px: Likewise. + * Test-proxy-auth-basic.px: Likewise. + * Test-restrict-ascii.px: Likewise. + * Test-stdouterr.px: Likewise. + * WgetTest.pm.in: Likewise. + +2014-40-22 Tim Ruehsen <tim.ruehsen@gmx.de> + + * Test-204.px: added file + * run-px: added Test-204.px + * Makefile.am: added Test-204.px + +2014-04-22 Giuseppe Scrivano <gscrivan@redhat.com> + + * Makefile.am (EXTRA_DIST): Add missing Test--start-pos.px, + Test-ftp--start-pos.px and Test--start-pos--continue.px. + +2014-02-24 Yousong Zhou <yszhou4tech@gmail.com> (tiny change) + + * tests/Test--httpsonly-r.px: Add feature constraint on https. + +2014-02-13 Yousong Zhou <yszhou4tech@gmail.com> + + * Test--start-pos.px: Test --start-pos for HTTP downloads. + * Test-ftp--start-pos.px: Test --start-pos for FTP downloads. + * Test--start-pos--continue.px: Test the case when --start-pos and + --continue were both specified. + +2014-02-13 Yousong Zhou <yszhou4tech@gmail.com> + + * Wget.pm.in: Exclude existing files from the check of unexpected + downloads. + +2014-02-13 Yousong Zhou <yszhou4tech@gmail.com> + + * FTPServer.pm: Fix the handling of TYPE command and avoid endless + loop when doing binary mode RETR. + +2014-01-23 Lars Wendler <polynomial-c@gentoo.org> (tiny change) + + * Test--post-file.px: Do not fail when wget has no debug support. + 2013-11-04 Darshit Shah <darnir@gmail.com> * Makefile.am: Add new tests introduced in last commit to diff --git a/tests/FTPServer.pm b/tests/FTPServer.pm index 2ac72e3..3d7d8a5 100644 --- a/tests/FTPServer.pm +++ b/tests/FTPServer.pm @@ -19,43 +19,40 @@ my $GOT_SIGURG = 0; # connection states my %_connection_states = ( - 'NEWCONN' => 0x01, - 'WAIT4PWD' => 0x02, - 'LOGGEDIN' => 0x04, - 'TWOSOCKS' => 0x08, -); + 'NEWCONN' => 0x01, + 'WAIT4PWD' => 0x02, + 'LOGGEDIN' => 0x04, + 'TWOSOCKS' => 0x08, + ); # subset of FTP commands supported by these server and the respective # connection states in which they are allowed my %_commands = ( + # Standard commands from RFC 959. - 'CWD' => $_connection_states{LOGGEDIN} | - $_connection_states{TWOSOCKS}, -# 'EPRT' => $_connection_states{LOGGEDIN}, -# 'EPSV' => $_connection_states{LOGGEDIN}, + 'CWD' => $_connection_states{LOGGEDIN} | $_connection_states{TWOSOCKS}, + + # 'EPRT' => $_connection_states{LOGGEDIN}, + # 'EPSV' => $_connection_states{LOGGEDIN}, 'LIST' => $_connection_states{TWOSOCKS}, -# 'LPRT' => $_connection_states{LOGGEDIN}, -# 'LPSV' => $_connection_states{LOGGEDIN}, + + # 'LPRT' => $_connection_states{LOGGEDIN}, + # 'LPSV' => $_connection_states{LOGGEDIN}, 'PASS' => $_connection_states{WAIT4PWD}, 'PASV' => $_connection_states{LOGGEDIN}, 'PORT' => $_connection_states{LOGGEDIN}, - 'PWD' => $_connection_states{LOGGEDIN} | - $_connection_states{TWOSOCKS}, - 'QUIT' => $_connection_states{LOGGEDIN} | - $_connection_states{TWOSOCKS}, + 'PWD' => $_connection_states{LOGGEDIN} | $_connection_states{TWOSOCKS}, + 'QUIT' => $_connection_states{LOGGEDIN} | $_connection_states{TWOSOCKS}, 'REST' => $_connection_states{TWOSOCKS}, 'RETR' => $_connection_states{TWOSOCKS}, 'SYST' => $_connection_states{LOGGEDIN}, - 'TYPE' => $_connection_states{LOGGEDIN} | - $_connection_states{TWOSOCKS}, + 'TYPE' => $_connection_states{LOGGEDIN} | $_connection_states{TWOSOCKS}, 'USER' => $_connection_states{NEWCONN}, + # From ftpexts Internet Draft. - 'SIZE' => $_connection_states{LOGGEDIN} | - $_connection_states{TWOSOCKS}, + 'SIZE' => $_connection_states{LOGGEDIN} | $_connection_states{TWOSOCKS}, ); - - # COMMAND-HANDLING ROUTINES sub _CWD_command @@ -67,7 +64,8 @@ sub _CWD_command my $new_path = FTPPaths::path_merge($conn->{'dir'}, $path); # Split the path into its component parts and process each separately. - if (! $paths->dir_exists($new_path)) { + if (!$paths->dir_exists($new_path)) + { print {$conn->{socket}} "550 Directory not found.\r\n"; return; } @@ -81,25 +79,24 @@ sub _LIST_command my ($conn, $cmd, $path) = @_; my $paths = $conn->{'paths'}; - my $ReturnEmptyList = ( $paths->GetBehavior('list_empty_if_list_a') && - $path eq '-a'); - my $SkipHiddenFiles = ( $paths->GetBehavior('list_no_hidden_if_list') && - ( ! $path ) ); + my $ReturnEmptyList = + ($paths->GetBehavior('list_empty_if_list_a') && $path eq '-a'); + my $SkipHiddenFiles = + ($paths->GetBehavior('list_no_hidden_if_list') && (!$path)); if ($paths->GetBehavior('list_fails_if_list_a') && $path eq '-a') - { - print {$conn->{socket}} "500 Unknown command\r\n"; - return; - } - + { + print {$conn->{socket}} "500 Unknown command\r\n"; + return; + } if (!$paths->GetBehavior('list_dont_clean_path')) - { + { # This is something of a hack. Some clients expect a Unix server # to respond to flags on the 'ls command line'. Remove these flags # and ignore them. This is particularly an issue with ncftp 2.4.3. $path =~ s/^-[a-zA-Z0-9]+\s?//; - } + } my $dir = $conn->{'dir'}; @@ -111,39 +108,44 @@ sub _LIST_command my $listing; if (!$ReturnEmptyList) - { + { $dir = FTPPaths::path_merge($dir, $path); - $listing = $paths->get_list($dir,$SkipHiddenFiles); - unless ($listing) { + $listing = $paths->get_list($dir, $SkipHiddenFiles); + unless ($listing) + { print {$conn->{socket}} "550 File or directory not found.\r\n"; return; } - } + } print STDERR "_LIST_command - dir is: $dir\n" if $log; print {$conn->{socket}} "150 Opening data connection for file listing.\r\n"; # Open a path back to the client. - my $sock = __open_data_connection ($conn); - unless ($sock) { + my $sock = __open_data_connection($conn); + unless ($sock) + { print {$conn->{socket}} "425 Can't open data connection.\r\n"; return; } if (!$ReturnEmptyList) - { - for my $item (@$listing) { + { + for my $item (@$listing) + { print $sock "$item\r\n"; } - } + } - unless ($sock->close) { + unless ($sock->close) + { print {$conn->{socket}} "550 Error closing data connection: $!\r\n"; return; } - print {$conn->{socket}} "226 Listing complete. Data connection has been closed.\r\n"; + print {$conn->{socket}} + "226 Listing complete. Data connection has been closed.\r\n"; } sub _PASS_command @@ -155,10 +157,15 @@ sub _PASS_command print STDERR "switching to LOGGEDIN state\n" if $log; $conn->{state} = $_connection_states{LOGGEDIN}; - if ($conn->{username} eq "anonymous") { - print {$conn->{socket}} "202 Anonymous user access is always granted.\r\n"; - } else { - print {$conn->{socket}} "230 Authentication not implemented yet, access is always granted.\r\n"; + if ($conn->{username} eq "anonymous") + { + print {$conn->{socket}} + "202 Anonymous user access is always granted.\r\n"; + } + else + { + print {$conn->{socket}} + "230 Authentication not implemented yet, access is always granted.\r\n"; } } @@ -167,28 +174,31 @@ sub _PASV_command my ($conn, $cmd, $rest) = @_; # Open a listening socket - but don't actually accept on it yet. - "0" =~ /(0)/; # Perl 5.7 / IO::Socket::INET bug workaround. - my $sock = IO::Socket::INET->new (LocalHost => '127.0.0.1', - LocalPort => '0', - Listen => 1, - Reuse => 1, - Proto => 'tcp', - Type => SOCK_STREAM); - - unless ($sock) { + "0" =~ /(0)/; # Perl 5.7 / IO::Socket::INET bug workaround. + my $sock = IO::Socket::INET->new( + LocalHost => '127.0.0.1', + LocalPort => '0', + Listen => 1, + Reuse => 1, + Proto => 'tcp', + Type => SOCK_STREAM + ); + + unless ($sock) + { # Return a code 550 here, even though this is not in the RFC. XXX print {$conn->{socket}} "550 Can't open a listening socket.\r\n"; return; } - $conn->{passive} = 1; + $conn->{passive} = 1; $conn->{passive_socket} = $sock; # Get our port number. my $sockport = $sock->sockport; # Split the port number into high and low components. - my $p1 = int ($sockport / 256); + my $p1 = int($sockport / 256); my $p2 = $sockport % 256; $conn->{state} = $_connection_states{TWOSOCKS}; @@ -204,33 +214,42 @@ sub _PORT_command # The arguments to PORT are a1,a2,a3,a4,p1,p2 where a1 is the # most significant part of the address (eg. 127,0,0,1) and # p1 is the most significant part of the port. - unless ($rest =~ /^\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})/) { + unless ($rest =~ + /^\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})/ + ) + { print {$conn->{socket}} "501 Syntax error in PORT command.\r\n"; return; } # Check host address. - unless ($1 > 0 && $1 < 224 && - $2 >= 0 && $2 < 256 && - $3 >= 0 && $3 < 256 && - $4 >= 0 && $4 < 256) { + unless ( $1 > 0 + && $1 < 224 + && $2 >= 0 + && $2 < 256 + && $3 >= 0 + && $3 < 256 + && $4 >= 0 + && $4 < 256) + { print {$conn->{socket}} "501 Invalid host address.\r\n"; return; } # Construct host address and port number. my $peeraddrstring = "$1.$2.$3.$4"; - my $peerport = $5 * 256 + $6; + my $peerport = $5 * 256 + $6; # Check port number. - unless ($peerport > 0 && $peerport < 65536) { + unless ($peerport > 0 && $peerport < 65536) + { print {$conn->{socket}} "501 Invalid port number.\r\n"; } $conn->{peeraddrstring} = $peeraddrstring; - $conn->{peeraddr} = inet_aton ($peeraddrstring); - $conn->{peerport} = $peerport; - $conn->{passive} = 0; + $conn->{peeraddr} = inet_aton($peeraddrstring); + $conn->{peerport} = $peerport; + $conn->{passive} = 0; $conn->{state} = $_connection_states{TWOSOCKS}; @@ -253,8 +272,10 @@ sub _REST_command { my ($conn, $cmd, $restart_from) = @_; - unless ($restart_from =~ /^([1-9][0-9]*|0)$/) { - print {$conn->{socket}} "501 REST command needs a numeric argument.\r\n"; + unless ($restart_from =~ /^([1-9][0-9]*|0)$/) + { + print {$conn->{socket}} + "501 REST command needs a numeric argument.\r\n"; return; } @@ -270,19 +291,21 @@ sub _RETR_command $path = FTPPaths::path_merge($conn->{dir}, $path); my $info = $conn->{'paths'}->get_info($path); - unless ($info->{'_type'} eq 'f') { + unless ($info->{'_type'} eq 'f') + { print {$conn->{socket}} "550 File not found.\r\n"; return; } - print {$conn->{socket}} "150 Opening " . - ($conn->{type} eq 'A' ? "ASCII mode" : "BINARY mode") . - " data connection.\r\n"; + print {$conn->{socket}} "150 Opening " + . ($conn->{type} eq 'A' ? "ASCII mode" : "BINARY mode") + . " data connection.\r\n"; # Open a path back to the client. - my $sock = __open_data_connection ($conn); + my $sock = __open_data_connection($conn); - unless ($sock) { + unless ($sock) + { print {$conn->{socket}} "425 Can't open data connection.\r\n"; return; } @@ -290,33 +313,37 @@ sub _RETR_command my $content = $info->{'content'}; # Restart the connection from previous point? - if ($conn->{restart}) { + if ($conn->{restart}) + { $content = substr($content, $conn->{restart}); $conn->{restart} = 0; } # What mode are we sending this file in? - unless ($conn->{type} eq 'A') # Binary type. + unless ($conn->{type} eq 'A') # Binary type. { - my ($r, $buffer, $n, $w); - + my ($r, $buffer, $n, $w, $sent); # Copy data. - while ($buffer = substr($content, 0, 65536)) + $sent = 0; + while ($sent < length($content)) { + $buffer = substr($content, $sent, 65536); $r = length $buffer; # Restart alarm clock timer. alarm $conn->{idle_timeout}; - for ($n = 0; $n < $r; ) + for ($n = 0 ; $n < $r ;) { - $w = syswrite ($sock, $buffer, $r - $n, $n); + $w = syswrite($sock, $buffer, $r - $n, $n); # Cleanup and exit if there was an error. - unless (defined $w) { + unless (defined $w) + { close $sock; - print {$conn->{socket}} "426 File retrieval error: $!. Data connection has been closed.\r\n"; + print {$conn->{socket}} + "426 File retrieval error: $!. Data connection has been closed.\r\n"; return; } @@ -324,24 +351,32 @@ sub _RETR_command } # Transfer aborted by client? - if ($GOT_SIGURG) { + if ($GOT_SIGURG) + { $GOT_SIGURG = 0; close $sock; - print {$conn->{socket}} "426 Transfer aborted. Data connection closed.\r\n"; + print {$conn->{socket}} + "426 Transfer aborted. Data connection closed.\r\n"; return; } + $sent += $r; } # Cleanup and exit if there was an error. - unless (defined $r) { + unless (defined $r) + { close $sock; - print {$conn->{socket}} "426 File retrieval error: $!. Data connection has been closed.\r\n"; + print {$conn->{socket}} + "426 File retrieval error: $!. Data connection has been closed.\r\n"; return; } - } else { # ASCII type. - # Copy data. + } + else + { # ASCII type. + # Copy data. my @lines = split /\r\n?|\n/, $content; - for (@lines) { + for (@lines) + { # Remove any native line endings. s/[\n\r]+$//; @@ -352,21 +387,25 @@ sub _RETR_command print $sock "$_\r\n"; # Transfer aborted by client? - if ($GOT_SIGURG) { + if ($GOT_SIGURG) + { $GOT_SIGURG = 0; close $sock; - print {$conn->{socket}} "426 Transfer aborted. Data connection closed.\r\n"; + print {$conn->{socket}} + "426 Transfer aborted. Data connection closed.\r\n"; return; } } } - unless (close ($sock)) { + unless (close($sock)) + { print {$conn->{socket}} "550 File retrieval error: $!.\r\n"; return; } - print {$conn->{socket}} "226 File retrieval complete. Data connection has been closed.\r\n"; + print {$conn->{socket}} + "226 File retrieval complete. Data connection has been closed.\r\n"; } sub _SIZE_command @@ -375,13 +414,16 @@ sub _SIZE_command $path = FTPPaths::path_merge($conn->{dir}, $path); my $info = $conn->{'paths'}->get_info($path); - unless ($info) { + unless ($info) + { print {$conn->{socket}} "550 File or directory not found.\r\n"; return; } - if ($info->{'_type'} eq 'd') { - print {$conn->{socket}} "550 SIZE command is not supported on directories.\r\n"; + if ($info->{'_type'} eq 'd') + { + print {$conn->{socket}} + "550 SIZE command is not supported on directories.\r\n"; return; } @@ -395,13 +437,14 @@ sub _SYST_command my ($conn, $cmd, $dummy) = @_; if ($conn->{'paths'}->GetBehavior('syst_response')) - { - print {$conn->{socket}} $conn->{'paths'}->GetBehavior('syst_response') . "\r\n"; - } + { + print {$conn->{socket}} $conn->{'paths'}->GetBehavior('syst_response') + . "\r\n"; + } else - { + { print {$conn->{socket}} "215 UNIX Type: L8\r\n"; - } + } } sub _TYPE_command @@ -409,14 +452,22 @@ sub _TYPE_command my ($conn, $cmd, $type) = @_; # See RFC 959 section 5.3.2. - if ($type =~ /^([AI])$/i) { - $conn->{type} = 'A'; - } elsif ($type =~ /^([AI])\sN$/i) { - $conn->{type} = 'A'; - } elsif ($type =~ /^L\s8$/i) { + if ($type =~ /^([AI])$/i) + { + $conn->{type} = $1; + } + elsif ($type =~ /^([AI])\sN$/i) + { + $conn->{type} = $1; + } + elsif ($type =~ /^L\s8$/i) + { $conn->{type} = 'L8'; - } else { - print {$conn->{socket}} "504 This server does not support TYPE $type.\r\n"; + } + else + { + print {$conn->{socket}} + "504 This server does not support TYPE $type.\r\n"; return; } @@ -433,14 +484,16 @@ sub _USER_command print STDERR "switching to WAIT4PWD state\n" if $log; $conn->{state} = $_connection_states{WAIT4PWD}; - if ($conn->{username} eq "anonymous") { + if ($conn->{username} eq "anonymous") + { print {$conn->{socket}} "230 Anonymous user access granted.\r\n"; - } else { + } + else + { print {$conn->{socket}} "331 Password required.\r\n"; } } - # HELPER ROUTINES sub __open_data_connection @@ -449,36 +502,41 @@ sub __open_data_connection my $sock; - if ($conn->{passive}) { + if ($conn->{passive}) + { # Passive mode - wait for a connection from the client. - accept ($sock, $conn->{passive_socket}) or return undef; - } else { + accept($sock, $conn->{passive_socket}) or return undef; + } + else + { # Active mode - connect back to the client. - "0" =~ /(0)/; # Perl 5.7 / IO::Socket::INET bug workaround. - $sock = IO::Socket::INET->new (LocalAddr => '127.0.0.1', - PeerAddr => $conn->{peeraddrstring}, - PeerPort => $conn->{peerport}, - Proto => 'tcp', - Type => SOCK_STREAM) or return undef; + "0" =~ /(0)/; # Perl 5.7 / IO::Socket::INET bug workaround. + $sock = IO::Socket::INET->new( + LocalAddr => '127.0.0.1', + PeerAddr => $conn->{peeraddrstring}, + PeerPort => $conn->{peerport}, + Proto => 'tcp', + Type => SOCK_STREAM + ) + or return undef; } return $sock; } - ########################################################################### # FTPSERVER CLASS ########################################################################### { - my %_attr_data = ( # DEFAULT - _input => undef, - _localAddr => 'localhost', - _localPort => undef, - _reuseAddr => 1, - _rootDir => Cwd::getcwd(), - _server_behavior => {}, - ); + my %_attr_data = ( # DEFAULT + _input => undef, + _localAddr => 'localhost', + _localPort => undef, + _reuseAddr => 1, + _rootDir => Cwd::getcwd(), + _server_behavior => {}, + ); sub _default_for { @@ -492,34 +550,44 @@ sub __open_data_connection } } - -sub new { +sub new +{ my ($caller, %args) = @_; my $caller_is_obj = ref($caller); - my $class = $caller_is_obj || $caller; - my $self = bless {}, $class; - foreach my $attrname ($self->_standard_keys()) { + my $class = $caller_is_obj || $caller; + my $self = bless {}, $class; + foreach my $attrname ($self->_standard_keys()) + { my ($argname) = ($attrname =~ /^_(.*)/); - if (exists $args{$argname}) { + if (exists $args{$argname}) + { $self->{$attrname} = $args{$argname}; - } elsif ($caller_is_obj) { + } + elsif ($caller_is_obj) + { $self->{$attrname} = $caller->{$attrname}; - } else { + } + else + { $self->{$attrname} = $self->_default_for($attrname); } } + # create server socket - "0" =~ /(0)/; # Perl 5.7 / IO::Socket::INET bug workaround. - $self->{_server_sock} - = IO::Socket::INET->new (LocalHost => $self->{_localAddr}, - LocalPort => $self->{_localPort}, - Listen => 1, - Reuse => $self->{_reuseAddr}, - Proto => 'tcp', - Type => SOCK_STREAM) - or die "bind: $!"; - - foreach my $file (keys %{$self->{_input}}) { + "0" =~ /(0)/; # Perl 5.7 / IO::Socket::INET bug workaround. + $self->{_server_sock} = + IO::Socket::INET->new( + LocalHost => $self->{_localAddr}, + LocalPort => $self->{_localPort}, + Listen => 1, + Reuse => $self->{_reuseAddr}, + Proto => 'tcp', + Type => SOCK_STREAM + ) + or die "bind: $!"; + + foreach my $file (keys %{$self->{_input}}) + { my $ref = \$self->{_input}{$file}{content}; $$ref =~ s/{{port}}/$self->sockport/eg; } @@ -527,18 +595,18 @@ sub new { return $self; } - sub run { my ($self, $synch_callback) = @_; my $initialized = 0; # turn buffering off on STDERR - select((select(STDERR), $|=1)[0]); + select((select(STDERR), $| = 1)[0]); # initialize command table my $command_table = {}; - foreach (keys %_commands) { + foreach (keys %_commands) + { my $subname = "_${_}_command"; $command_table->{$_} = \&$subname; } @@ -546,7 +614,8 @@ sub run my $old_ils = $/; $/ = "\r\n"; - if (!$initialized) { + if (!$initialized) + { $synch_callback->(); $initialized = 1; } @@ -555,14 +624,14 @@ sub run my $server_sock = $self->{_server_sock}; # the accept loop - while (my $client_addr = accept (my $socket, $server_sock)) + while (my $client_addr = accept(my $socket, $server_sock)) { # turn buffering off on $socket - select((select($socket), $|=1)[0]); + select((select($socket), $| = 1)[0]); # find out who connected - my ($client_port, $client_ip) = sockaddr_in ($client_addr); - my $client_ipnum = inet_ntoa ($client_ip); + my ($client_port, $client_ip) = sockaddr_in($client_addr); + my $client_ipnum = inet_ntoa($client_ip); # print who connected print STDERR "got a connection from: $client_ipnum\n" if $log; @@ -575,11 +644,12 @@ sub run # next; # } - if (1) { # Child process. + if (1) + { # Child process. # install signals - $SIG{URG} = sub { - $GOT_SIGURG = 1; + $SIG{URG} = sub { + $GOT_SIGURG = 1; }; $SIG{PIPE} = sub { @@ -588,33 +658,35 @@ sub run }; $SIG{ALRM} = sub { - print STDERR "Connection idle timeout expired. Closing server.\n"; + print STDERR + "Connection idle timeout expired. Closing server.\n"; exit; }; #$SIG{CHLD} = 'IGNORE'; - print STDERR "in child\n" if $log; my $conn = { - 'paths' => FTPPaths->new($self->{'_input'}, - $self->{'_server_behavior'}), - 'socket' => $socket, - 'state' => $_connection_states{NEWCONN}, - 'dir' => '/', - 'restart' => 0, - 'idle_timeout' => 60, # 1 minute timeout - 'rootdir' => $self->{_rootDir}, - }; - - print {$conn->{socket}} "220 GNU Wget Testing FTP Server ready.\r\n"; + 'paths' => + FTPPaths->new($self->{'_input'}, $self->{'_server_behavior'}), + 'socket' => $socket, + 'state' => $_connection_states{NEWCONN}, + 'dir' => '/', + 'restart' => 0, + 'idle_timeout' => 60, # 1 minute timeout + 'rootdir' => $self->{_rootDir}, + }; + + print {$conn->{socket}} + "220 GNU Wget Testing FTP Server ready.\r\n"; # command handling loop - for (;;) { + for (; ;) + { print STDERR "waiting for request\n" if $log; - last unless defined (my $req = <$socket>); + last unless defined(my $req = <$socket>); # Remove trailing CRLF. $req =~ s/[\n\r]+$//; @@ -623,7 +695,8 @@ sub run # Get the command. # See also RFC 2640 section 3.1. - unless ($req =~ m/^([A-Z]{3,4})\s?(.*)/i) { + unless ($req =~ m/^([A-Z]{3,4})\s?(.*)/i) + { # badly formed command exit 0; } @@ -638,34 +711,41 @@ sub run my ($cmd, $rest) = (uc $1, $2); # Got a command which matches in the table? - unless (exists $command_table->{$cmd}) { + unless (exists $command_table->{$cmd}) + { print {$conn->{socket}} "500 Unrecognized command.\r\n"; next; } # Command requires user to be authenticated? - unless ($_commands{$cmd} | $conn->{state}) { + unless ($_commands{$cmd} | $conn->{state}) + { print {$conn->{socket}} "530 Not logged in.\r\n"; next; } # Handle the QUIT command specially. - if ($cmd eq "QUIT") { - print {$conn->{socket}} "221 Goodbye. Service closing connection.\r\n"; + if ($cmd eq "QUIT") + { + print {$conn->{socket}} + "221 Goodbye. Service closing connection.\r\n"; last; } - if (defined ($self->{_server_behavior}{fail_on_pasv}) - && $cmd eq 'PASV') { + if (defined($self->{_server_behavior}{fail_on_pasv}) + && $cmd eq 'PASV') + { undef $self->{_server_behavior}{fail_on_pasv}; close $socket; last; } # Run the command. - &{$command_table->{$cmd}} ($conn, $cmd, $rest); + &{$command_table->{$cmd}}($conn, $cmd, $rest); } - } else { # Father + } + else + { # Father close $socket; } } @@ -673,18 +753,19 @@ sub run $/ = $old_ils; } -sub sockport { +sub sockport +{ my $self = shift; return $self->{_server_sock}->sockport; } - package FTPPaths; use POSIX qw(strftime); # not a method -sub final_component { +sub final_component +{ my $path = shift; $path =~ s|.*/||; @@ -692,34 +773,49 @@ sub final_component { } # not a method -sub path_merge { - my ($a, $b) = @_; +sub path_merge +{ + my ($path_a, $path_b) = @_; - return $a unless $b; + if (!$path_b) + { + return $path_a; + } - if ($b =~ m.^/.) { - $a = ''; - $b =~ s.^/..; + if ($path_b =~ m.^/.) + { + $path_a = ''; + $path_b =~ s.^/..; } - $a =~ s./$..; + $path_a =~ s./$..; - my @components = split('/', $b); + my @components = split m{/}msx, $path_b; - foreach my $c (@components) { - if ($c =~ /^\.?$/) { + foreach my $c (@components) + { + if ($c =~ /^\.?$/) + { next; - } elsif ($c eq '..') { - next if $a eq ''; - $a =~ s|/[^/]*$||; - } else { - $a .= "/$c"; + } + elsif ($c eq '..') + { + if (!$path_a) + { + next; + } + $path_a =~ s|/[^/]*$||; + } + else + { + $path_a .= "/$c"; } } - return $a; + return $path_a; } -sub new { +sub new +{ my ($this, @args) = @_; my $class = ref($this) || $this; my $self = {}; @@ -728,19 +824,23 @@ sub new { return $self; } -sub initialize { +sub initialize +{ my ($self, $urls, $behavior) = @_; my $paths = {_type => 'd'}; # From a path like '/foo/bar/baz.txt', construct $paths such that # $paths->{'foo'}->{'bar'}->{'baz.txt'} is # $urls->{'/foo/bar/baz.txt'}. - for my $path (keys %$urls) { - my @components = split('/', $path); + for my $path (keys %$urls) + { + my @components = split m{/}msx, $path; shift @components; my $x = $paths; - for my $c (@components) { - unless (exists $x->{$c}) { + for my $c (@components) + { + if (!exists $x->{$c}) + { $x->{$c} = {_type => 'd'}; } $x = $x->{$c}; @@ -749,32 +849,40 @@ sub initialize { $x->{_type} = 'f'; } - $self->{'_paths'} = $paths; + $self->{'_paths'} = $paths; $self->{'_behavior'} = $behavior; + return 1; } -sub get_info { +sub get_info +{ my ($self, $path, $node) = @_; $node = $self->{'_paths'} unless $node; my @components = split('/', $path); shift @components if @components && $components[0] eq ''; - for my $c (@components) { - if ($node->{'_type'} eq 'd') { + for my $c (@components) + { + if ($node->{'_type'} eq 'd') + { $node = $node->{$c}; - } else { - return undef; + } + else + { + return; } } return $node; } -sub dir_exists { +sub dir_exists +{ my ($self, $path) = @_; - return $self->exists($path, 'd'); + return $self->path_exists($path, 'd'); } -sub exists { +sub path_exists +{ # type is optional, in which case we don't check it. my ($self, $path, $type) = @_; my $paths = $self->{'_paths'}; @@ -786,52 +894,67 @@ sub exists { return 1; } -sub _format_for_list { +sub _format_for_list +{ my ($self, $name, $info) = @_; # XXX: mode should be specifyable as part of the node info. my $mode_str; - if ($info->{'_type'} eq 'd') { + if ($info->{'_type'} eq 'd') + { $mode_str = 'dr-xr-xr-x'; - } else { + } + else + { $mode_str = '-r--r--r--'; } my $size = 0; - if ($info->{'_type'} eq 'f') { - $size = length $info->{'content'}; - if ($self->{'_behavior'}{'bad_list'}) { + if ($info->{'_type'} eq 'f') + { + $size = length $info->{'content'}; + if ($self->{'_behavior'}{'bad_list'}) + { $size = 0; } } - my $date = strftime ("%b %e %H:%M", localtime); + my $date = strftime("%b %e %H:%M", localtime); return "$mode_str 1 0 0 $size $date $name"; } -sub get_list { +sub get_list +{ my ($self, $path, $no_hidden) = @_; my $info = $self->get_info($path); - return undef unless defined $info; + if (!defined $info) + { + return; + } my $list = []; - if ($info->{'_type'} eq 'd') { - for my $item (keys %$info) { + if ($info->{'_type'} eq 'd') + { + for my $item (keys %$info) + { next if $item =~ /^_/; + # 2013-10-17 Andrea Urbani (matfanjol) # I skip the hidden files if requested - if (($no_hidden) && - (defined($info->{$item}->{'attr'})) && - (index($info->{$item}->{'attr'}, "H")>=0)) - { + if ( ($no_hidden) + && (defined($info->{$item}->{'attr'})) + && (index($info->{$item}->{'attr'}, "H") >= 0)) + { # This is an hidden file and I don't want to see it! print STDERR "get_list: Skipped hidden file [$item]\n"; - } + } else - { + { push @$list, $self->_format_for_list($item, $info->{$item}); - } + } } - } else { + } + else + { push @$list, $self->_format_for_list(final_component($path), $info); } @@ -856,9 +979,10 @@ sub get_list { # to the url files # syst_response : if defined, its content is printed # out as SYST response -sub GetBehavior { - my ($self, $name) = @_; - return $self->{'_behavior'}{$name}; +sub GetBehavior +{ + my ($self, $name) = @_; + return $self->{'_behavior'}{$name}; } 1; diff --git a/tests/FTPTest.pm b/tests/FTPTest.pm index c1d3d26..50385ad 100644 --- a/tests/FTPTest.pm +++ b/tests/FTPTest.pm @@ -4,14 +4,13 @@ use strict; use warnings; use FTPServer; -use WgetTest; +use WgetTests; our @ISA = qw(WgetTest); my $VERSION = 0.01; - { - my %_attr_data = ( # DEFAULT + my %_attr_data = ( # DEFAULT ); sub _default_for @@ -28,29 +27,32 @@ my $VERSION = 0.01; } } - -sub _setup_server { +sub _setup_server +{ my $self = shift; - $self->{_server} = FTPServer->new (input => $self->{_input}, - server_behavior => - $self->{_server_behavior}, - LocalAddr => 'localhost', - ReuseAddr => 1, - rootDir => "$self->{_workdir}/$self->{_name}/input") or die "Cannot create server!!!"; + $self->{_server} = FTPServer->new( + input => $self->{_input}, + server_behavior => $self->{_server_behavior}, + LocalAddr => 'localhost', + ReuseAddr => 1, + rootDir => "$self->{_workdir}/$self->{_name}/input" + ) + or die "Cannot create server!!!"; } - -sub _launch_server { - my $self = shift; +sub _launch_server +{ + my $self = shift; my $synch_func = shift; - $self->{_server}->run ($synch_func); + $self->{_server}->run($synch_func); } -sub _substitute_port { +sub _substitute_port +{ my $self = shift; - my $ret = shift; + my $ret = shift; $ret =~ s/{{port}}/$self->{_server}->sockport/eg; return $ret; } @@ -58,4 +60,3 @@ sub _substitute_port { 1; # vim: et ts=4 sw=4 - diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index 065ea1e..dd8ec04 100644 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -8,47 +8,58 @@ use HTTP::Status; use HTTP::Headers; use HTTP::Response; -our @ISA=qw(HTTP::Daemon); +our @ISA = qw(HTTP::Daemon); my $VERSION = 0.01; -my $CRLF = "\015\012"; # "\r\n" is not portable -my $log = undef; +my $CRLF = "\015\012"; # "\r\n" is not portable +my $log = undef; -sub run { +sub run +{ my ($self, $urls, $synch_callback) = @_; my $initialized = 0; - while (1) { - if (!$initialized) { + while (1) + { + if (!$initialized) + { $synch_callback->(); $initialized = 1; } my $con = $self->accept(); print STDERR "Accepted a new connection\n" if $log; - while (my $req = $con->get_request) { + while (my $req = $con->get_request) + { #my $url_path = $req->url->path; my $url_path = $req->url->as_string; - if ($url_path =~ m{/$}) { # append 'index.html' + if ($url_path =~ m{/$}) + { # append 'index.html' $url_path .= 'index.html'; } + #if ($url_path =~ m{^/}) { # remove trailing '/' # $url_path = substr ($url_path, 1); #} - if ($log) { + if ($log) + { print STDERR "Method: ", $req->method, "\n"; print STDERR "Path: ", $url_path, "\n"; print STDERR "Available URLs: ", "\n"; - foreach my $key (keys %$urls) { + foreach my $key (keys %$urls) + { print STDERR $key, "\n"; } } - if (exists($urls->{$url_path})) { + if (exists($urls->{$url_path})) + { print STDERR "Serving requested URL: ", $url_path, "\n" if $log; next unless ($req->method eq "HEAD" || $req->method eq "GET"); my $url_rec = $urls->{$url_path}; $self->send_response($req, $url_rec, $con); - } else { + } + else + { print STDERR "Requested wrong URL: ", $url_path, "\n" if $log; $con->send_error($HTTP::Status::RC_FORBIDDEN); last; @@ -59,73 +70,90 @@ sub run { } } -sub send_response { +sub send_response +{ my ($self, $req, $url_rec, $con) = @_; # create response my ($code, $msg, $headers); my $send_content = ($req->method eq "GET"); - if (exists $url_rec->{'auth_method'}) { + if (exists $url_rec->{'auth_method'}) + { ($send_content, $code, $msg, $headers) = - $self->handle_auth($req, $url_rec); - } elsif (!$self->verify_request_headers ($req, $url_rec)) { + $self->handle_auth($req, $url_rec); + } + elsif (!$self->verify_request_headers($req, $url_rec)) + { ($send_content, $code, $msg, $headers) = - ('', 400, 'Mismatch on expected headers', {}); - } else { + ('', 400, 'Mismatch on expected headers', {}); + } + else + { ($code, $msg) = @{$url_rec}{'code', 'msg'}; $headers = $url_rec->{headers}; } - my $resp = HTTP::Response->new ($code, $msg); + my $resp = HTTP::Response->new($code, $msg); print STDERR "HTTP::Response: \n", $resp->as_string if $log; - while (my ($name, $value) = each %{$headers}) { + while (my ($name, $value) = each %{$headers}) + { # print STDERR "setting header: $name = $value\n"; + $value = $self->_substitute_port($value); $resp->header($name => $value); } print STDERR "HTTP::Response with headers: \n", $resp->as_string if $log; - if ($send_content) { + if ($send_content) + { my $content = $url_rec->{content}; - if (exists($url_rec->{headers}{"Content-Length"})) { + if (exists($url_rec->{headers}{"Content-Length"})) + { # Content-Length and length($content) don't match # manually prepare the HTTP response - $con->send_basic_header($url_rec->{code}, $resp->message, $resp->protocol); + $con->send_basic_header($url_rec->{code}, $resp->message, + $resp->protocol); print $con $resp->headers_as_string($CRLF); print $con $CRLF; print $con $content; next; } - if ($req->header("Range") && !$url_rec->{'force_code'}) { + if ($req->header("Range") && !$url_rec->{'force_code'}) + { $req->header("Range") =~ m/bytes=(\d*)-(\d*)/; my $content_len = length($content); - my $start = $1 ? $1 : 0; - my $end = $2 ? $2 : ($content_len - 1); - my $len = $2 ? ($2 - $start) : ($content_len - $start); - if ($len > 0) { - $resp->header("Accept-Ranges" => "bytes"); + my $start = $1 ? $1 : 0; + my $end = $2 ? $2 : ($content_len - 1); + my $len = $2 ? ($2 - $start) : ($content_len - $start); + if ($len > 0) + { + $resp->header("Accept-Ranges" => "bytes"); $resp->header("Content-Length" => $len); - $resp->header("Content-Range" - => "bytes $start-$end/$content_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); + "Partial Content", $resp->protocol); print $con $resp->headers_as_string($CRLF); print $con $CRLF; print $con substr($content, $start, $len); - } else { + } + else + { $con->send_basic_header(416, "Range Not Satisfiable", - $resp->protocol); + $resp->protocol); $resp->header("Keep-Alive" => "timeout=15, max=100"); $resp->header("Connection" => "Keep-Alive"); print $con $CRLF; } next; } + # fill in content $content = $self->_substitute_port($content) if defined $content; $resp->content($content); - print STDERR "HTTP::Response with content: \n", $resp->as_string if $log; + print STDERR "HTTP::Response with content: \n", $resp->as_string + if $log; } $con->send_response($resp); @@ -134,60 +162,81 @@ sub send_response { # Generates appropriate response content based on the authentication # status of the URL. -sub handle_auth { +sub handle_auth +{ my ($self, $req, $url_rec) = @_; my ($send_content, $code, $msg, $headers); + # Catch failure to set code, msg: $code = 500; $msg = "Didn't set response code in handle_auth"; + # Most cases, we don't want to send content. $send_content = 0; + # Initialize headers $headers = {}; my $authhdr = $req->header('Authorization'); # Have we sent the challenge yet? - unless ($url_rec->{auth_challenged} || $url_rec->{auth_no_challenge}) { + unless ($url_rec->{auth_challenged} || $url_rec->{auth_no_challenge}) + { # Since we haven't challenged yet, we'd better not # have received authentication (for our testing purposes). - if ($authhdr) { + if ($authhdr) + { $code = 400; $msg = "You sent auth before I sent challenge"; - } else { + } + else + { # Send challenge $code = 401; $msg = "Authorization Required"; - $headers->{'WWW-Authenticate'} = $url_rec->{'auth_method'} - . " realm=\"wget-test\""; + $headers->{'WWW-Authenticate'} = + $url_rec->{'auth_method'} . " realm=\"wget-test\""; $url_rec->{auth_challenged} = 1; } - } elsif (!defined($authhdr)) { + } + elsif (!defined($authhdr)) + { # We've sent the challenge; we should have received valid # authentication with this one. A normal server would just # resend the challenge; but since this is a test, wget just # failed it. $code = 400; $msg = "You didn't send auth after I sent challenge"; - if ($url_rec->{auth_no_challenge}) { - $msg = "--auth-no-challenge but no auth sent." + if ($url_rec->{auth_no_challenge}) + { + $msg = "--auth-no-challenge but no auth sent."; } - } else { + } + else + { my ($sent_method) = ($authhdr =~ /^(\S+)/g); - unless ($sent_method eq $url_rec->{'auth_method'}) { + unless ($sent_method eq $url_rec->{'auth_method'}) + { # Not the authorization type we were expecting. $code = 400; - $msg = "Expected auth type $url_rec->{'auth_method'} but got " - . "$sent_method"; - } elsif (($sent_method eq 'Digest' - && &verify_auth_digest($authhdr, $url_rec, \$msg)) - || - ($sent_method eq 'Basic' - && &verify_auth_basic($authhdr, $url_rec, \$msg))) { + $msg = "Expected auth type $url_rec->{'auth_method'} but got " + . "$sent_method"; + } + elsif ( + ( + $sent_method eq 'Digest' + && &verify_auth_digest($authhdr, $url_rec, \$msg) + ) + || ( $sent_method eq 'Basic' + && &verify_auth_basic($authhdr, $url_rec, \$msg)) + ) + { # SUCCESSFUL AUTH: send expected message, headers, content. ($code, $msg) = @{$url_rec}{'code', 'msg'}; - $headers = $url_rec->{headers}; + $headers = $url_rec->{headers}; $send_content = 1; - } else { + } + else + { $code = 400; } } @@ -195,43 +244,58 @@ sub handle_auth { return ($send_content, $code, $msg, $headers); } -sub verify_auth_digest { - return undef; # Not yet implemented. +sub verify_auth_digest +{ + return undef; # Not yet implemented. } -sub verify_auth_basic { +sub verify_auth_basic +{ require MIME::Base64; my ($authhdr, $url_rec, $msgref) = @_; - my $expected = MIME::Base64::encode_base64($url_rec->{'user'} . ':' - . $url_rec->{'passwd'}, ''); + my $expected = + MIME::Base64::encode_base64( + $url_rec->{'user'} . ':' . $url_rec->{'passwd'}, + ''); my ($got) = $authhdr =~ /^Basic (.*)$/; - if ($got eq $expected) { + if ($got eq $expected) + { return 1; - } else { + } + else + { $$msgref = "Wanted ${expected} got ${got}"; return undef; } } -sub verify_request_headers { +sub verify_request_headers +{ my ($self, $req, $url_rec) = @_; return 1 unless exists $url_rec->{'request_headers'}; - for my $hdrname (keys %{$url_rec->{'request_headers'}}) { + for my $hdrname (keys %{$url_rec->{'request_headers'}}) + { my $must_not_match; my $ehdr = $url_rec->{'request_headers'}{$hdrname}; - if ($must_not_match = ($hdrname =~ /^!(\w+)/)) { + if ($must_not_match = ($hdrname =~ /^!(\w+)/)) + { $hdrname = $1; } - my $rhdr = $req->header ($hdrname); - if ($must_not_match) { - if (defined $rhdr && $rhdr =~ $ehdr) { + my $rhdr = $req->header($hdrname); + if ($must_not_match) + { + if (defined $rhdr && $rhdr =~ $ehdr) + { $rhdr = '' unless defined $rhdr; print STDERR "\n*** Match forbidden $hdrname: $rhdr =~ $ehdr\n"; return undef; } - } else { - unless (defined $rhdr && $rhdr =~ $ehdr) { + } + else + { + unless (defined $rhdr && $rhdr =~ $ehdr) + { $rhdr = '' unless defined $rhdr; print STDERR "\n*** Mismatch on $hdrname: $rhdr =~ $ehdr\n"; return undef; @@ -242,9 +306,10 @@ sub verify_request_headers { return 1; } -sub _substitute_port { +sub _substitute_port +{ my $self = shift; - my $ret = shift; + my $ret = shift; $ret =~ s/{{port}}/$self->sockport/eg; return $ret; } @@ -252,4 +317,3 @@ sub _substitute_port { 1; # vim: et ts=4 sw=4 - diff --git a/tests/HTTPTest.pm b/tests/HTTPTest.pm index 883213d..00f079f 100644 --- a/tests/HTTPTest.pm +++ b/tests/HTTPTest.pm @@ -4,14 +4,13 @@ use strict; use warnings; use HTTPServer; -use WgetTest; +use WgetTests; our @ISA = qw(WgetTest); my $VERSION = 0.01; - { - my %_attr_data = ( # DEFAULT + my %_attr_data = ( # DEFAULT ); sub _default_for @@ -28,25 +27,26 @@ my $VERSION = 0.01; } } - -sub _setup_server { +sub _setup_server +{ my $self = shift; - $self->{_server} = HTTPServer->new (LocalAddr => 'localhost', - ReuseAddr => 1) - or die "Cannot create server!!!"; + $self->{_server} = HTTPServer->new(LocalAddr => 'localhost', + ReuseAddr => 1) + or die "Cannot create server!!!"; } - -sub _launch_server { - my $self = shift; +sub _launch_server +{ + my $self = shift; my $synch_func = shift; - $self->{_server}->run ($self->{_input}, $synch_func); + $self->{_server}->run($self->{_input}, $synch_func); } -sub _substitute_port { +sub _substitute_port +{ my $self = shift; - my $ret = shift; + my $ret = shift; $ret =~ s/{{port}}/$self->{_server}->sockport/eg; return $ret; } @@ -54,4 +54,3 @@ sub _substitute_port { 1; # vim: et ts=4 sw=4 - diff --git a/tests/Makefile.am b/tests/Makefile.am index bea262e..ae96f5b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -27,21 +27,12 @@ # shall include the source code for the parts of OpenSSL used as well # as that of the covered work. +# see http://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html#Parallel-Test-Harness + # # Version: @VERSION@ # -PERL = perl -PERLRUN = $(PERL) -I$(srcdir) - -LIBS = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME) - -.PHONY: test run-unit-tests run-px-tests - -check-local: test - -test: ../src/wget$(EXEEXT) run-unit-tests run-px-tests - ../src/wget$(EXEEXT): cd ../src && $(MAKE) $(AM_MAKEFLAGS) @@ -53,14 +44,7 @@ test: ../src/wget$(EXEEXT) run-unit-tests run-px-tests ../lib/libgnu.a: cd ../lib && $(MAKE) $(AM_MAKEFLAGS) -run-unit-tests: unit-tests$(EXEEXT) ../src/libunittest.a - ./unit-tests$(EXEEXT) - -run-px-tests: WgetTest.pm ../src/wget$(EXEEXT) - $(srcdir)/run-px $(top_srcdir) - -EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ - WgetFeature.pm WgetFeature.cfg \ +PX_TESTS = \ Test-auth-basic.px \ Test-auth-no-challenge.px \ Test-auth-no-challenge-url.px \ @@ -88,6 +72,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test-ftp-list-Unknown-hidden.px \ Test-ftp-list-Unknown-list-a-fails.px \ Test-ftp-list-UNIX-hidden.px \ + Test-ftp--start-pos.px \ Test-HTTP-Content-Disposition-1.px \ Test-HTTP-Content-Disposition-2.px \ Test-HTTP-Content-Disposition.px \ @@ -127,6 +112,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test-O.px \ Test--post-file.px \ Test-proxied-https-auth.px \ + Test-proxied-https-auth-keepalive.px \ Test-proxy-auth-basic.px \ Test-restrict-ascii.px \ Test-Restrict-Lowercase.px \ @@ -138,11 +124,24 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test--spider-r--no-content-disposition.px \ Test--spider-r--no-content-disposition-trivial.px \ Test--spider-r.px \ + Test--start-pos.px \ + Test--start-pos--continue.px \ Test--httpsonly-r.px \ - run-px certs + Test-204.px + +EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ + WgetTests.pm WgetFeature.pm WgetFeature.cfg $(PX_TESTS) \ + certs check_PROGRAMS = unit-tests unit_tests_SOURCES = -LDADD = ../src/libunittest.a ../lib/libgnu.a $(LIBS) +LDADD = ../src/libunittest.a ../lib/libgnu.a $(LIBS) $(LIB_CLOCK_GETTIME) CLEANFILES = *~ *.bak core core.[0-9]* + +TESTS = ./unit-tests$(EXEEXT) $(PX_TESTS) +TEST_EXTENSIONS = .px +PX_LOG_COMPILER = $(PERL) +AM_PX_LOG_FLAGS = -I$(srcdir) +AM_TESTS_ENVIRONMENT = export WGETRC=/dev/null; export SYSTEM_WGETRC=/dev/null;\ + export VALGRIND_TESTS="@VALGRIND_TESTS@"; diff --git a/tests/Makefile.in b/tests/Makefile.in index c3b9341..723dc76 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -43,6 +43,8 @@ # shall include the source code for the parts of OpenSSL used as well # as that of the covered work. +# see http://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html#Parallel-Test-Harness + # # Version: @VERSION@ # @@ -112,7 +114,7 @@ host_triplet = @host@ check_PROGRAMS = unit-tests$(EXEEXT) subdir = tests DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(srcdir)/WgetTest.pm.in ChangeLog + $(top_srcdir)/build-aux/test-driver ChangeLog ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ $(top_srcdir)/m4/absolute-header.m4 $(top_srcdir)/m4/alloca.m4 \ @@ -128,14 +130,15 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ $(top_srcdir)/m4/extern-inline.m4 \ $(top_srcdir)/m4/fatal-signal.m4 $(top_srcdir)/m4/fcntl-o.m4 \ $(top_srcdir)/m4/fcntl.m4 $(top_srcdir)/m4/fcntl_h.m4 \ - $(top_srcdir)/m4/float_h.m4 $(top_srcdir)/m4/fseek.m4 \ - $(top_srcdir)/m4/fseeko.m4 $(top_srcdir)/m4/fstat.m4 \ - $(top_srcdir)/m4/ftell.m4 $(top_srcdir)/m4/ftello.m4 \ - $(top_srcdir)/m4/futimens.m4 $(top_srcdir)/m4/getaddrinfo.m4 \ - $(top_srcdir)/m4/getdelim.m4 $(top_srcdir)/m4/getdtablesize.m4 \ - $(top_srcdir)/m4/getline.m4 $(top_srcdir)/m4/getopt.m4 \ - $(top_srcdir)/m4/getpass.m4 $(top_srcdir)/m4/gettext.m4 \ - $(top_srcdir)/m4/gettime.m4 $(top_srcdir)/m4/gettimeofday.m4 \ + $(top_srcdir)/m4/float_h.m4 $(top_srcdir)/m4/fnmatch.m4 \ + $(top_srcdir)/m4/fseek.m4 $(top_srcdir)/m4/fseeko.m4 \ + $(top_srcdir)/m4/fstat.m4 $(top_srcdir)/m4/ftell.m4 \ + $(top_srcdir)/m4/ftello.m4 $(top_srcdir)/m4/futimens.m4 \ + $(top_srcdir)/m4/getaddrinfo.m4 $(top_srcdir)/m4/getdelim.m4 \ + $(top_srcdir)/m4/getdtablesize.m4 $(top_srcdir)/m4/getline.m4 \ + $(top_srcdir)/m4/getopt.m4 $(top_srcdir)/m4/getpass.m4 \ + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gettime.m4 \ + $(top_srcdir)/m4/gettimeofday.m4 \ $(top_srcdir)/m4/gl-openssl.m4 $(top_srcdir)/m4/glibc21.m4 \ $(top_srcdir)/m4/gnulib-common.m4 \ $(top_srcdir)/m4/gnulib-comp.m4 $(top_srcdir)/m4/hostent.m4 \ @@ -143,21 +146,24 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/inet_ntop.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intmax_t.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/ioctl.m4 \ - $(top_srcdir)/m4/langinfo_h.m4 $(top_srcdir)/m4/largefile.m4 \ - $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ - $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/iswblank.m4 $(top_srcdir)/m4/langinfo_h.m4 \ + $(top_srcdir)/m4/largefile.m4 $(top_srcdir)/m4/lib-ld.m4 \ + $(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \ + $(top_srcdir)/m4/libunistring-base.m4 \ $(top_srcdir)/m4/localcharset.m4 $(top_srcdir)/m4/locale-fr.m4 \ $(top_srcdir)/m4/locale-ja.m4 $(top_srcdir)/m4/locale-zh.m4 \ $(top_srcdir)/m4/locale_h.m4 $(top_srcdir)/m4/localeconv.m4 \ $(top_srcdir)/m4/lock.m4 $(top_srcdir)/m4/longlong.m4 \ $(top_srcdir)/m4/lseek.m4 $(top_srcdir)/m4/lstat.m4 \ - $(top_srcdir)/m4/malloc.m4 $(top_srcdir)/m4/mbrtowc.m4 \ - $(top_srcdir)/m4/mbsinit.m4 $(top_srcdir)/m4/mbstate_t.m4 \ - $(top_srcdir)/m4/mbtowc.m4 $(top_srcdir)/m4/md5.m4 \ - $(top_srcdir)/m4/memchr.m4 $(top_srcdir)/m4/mkdir.m4 \ + $(top_srcdir)/m4/malloc.m4 $(top_srcdir)/m4/mbchar.m4 \ + $(top_srcdir)/m4/mbiter.m4 $(top_srcdir)/m4/mbrtowc.m4 \ + $(top_srcdir)/m4/mbsinit.m4 $(top_srcdir)/m4/mbsrtowcs.m4 \ + $(top_srcdir)/m4/mbstate_t.m4 $(top_srcdir)/m4/mbtowc.m4 \ + $(top_srcdir)/m4/md5.m4 $(top_srcdir)/m4/memchr.m4 \ + $(top_srcdir)/m4/memrchr.m4 $(top_srcdir)/m4/mkdir.m4 \ $(top_srcdir)/m4/mkostemp.m4 $(top_srcdir)/m4/mkstemp.m4 \ - $(top_srcdir)/m4/mmap-anon.m4 $(top_srcdir)/m4/mode_t.m4 \ - $(top_srcdir)/m4/msvc-inval.m4 \ + $(top_srcdir)/m4/mktime.m4 $(top_srcdir)/m4/mmap-anon.m4 \ + $(top_srcdir)/m4/mode_t.m4 $(top_srcdir)/m4/msvc-inval.m4 \ $(top_srcdir)/m4/msvc-nothrow.m4 $(top_srcdir)/m4/multiarch.m4 \ $(top_srcdir)/m4/netdb_h.m4 $(top_srcdir)/m4/netinet_in_h.m4 \ $(top_srcdir)/m4/nl_langinfo.m4 $(top_srcdir)/m4/nls.m4 \ @@ -182,42 +188,45 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ $(top_srcdir)/m4/stdbool.m4 $(top_srcdir)/m4/stddef_h.m4 \ $(top_srcdir)/m4/stdint.m4 $(top_srcdir)/m4/stdint_h.m4 \ $(top_srcdir)/m4/stdio_h.m4 $(top_srcdir)/m4/stdlib_h.m4 \ - $(top_srcdir)/m4/strcase.m4 $(top_srcdir)/m4/strcasestr.m4 \ - $(top_srcdir)/m4/strchrnul.m4 $(top_srcdir)/m4/strerror.m4 \ - $(top_srcdir)/m4/strerror_r.m4 $(top_srcdir)/m4/string_h.m4 \ - $(top_srcdir)/m4/strings_h.m4 $(top_srcdir)/m4/strtok_r.m4 \ - $(top_srcdir)/m4/sys_ioctl_h.m4 \ + $(top_srcdir)/m4/strcase.m4 $(top_srcdir)/m4/strchrnul.m4 \ + $(top_srcdir)/m4/strerror.m4 $(top_srcdir)/m4/strerror_r.m4 \ + $(top_srcdir)/m4/string_h.m4 $(top_srcdir)/m4/strings_h.m4 \ + $(top_srcdir)/m4/strndup.m4 $(top_srcdir)/m4/strnlen.m4 \ + $(top_srcdir)/m4/strptime.m4 $(top_srcdir)/m4/strtok_r.m4 \ + $(top_srcdir)/m4/strtoll.m4 $(top_srcdir)/m4/sys_ioctl_h.m4 \ $(top_srcdir)/m4/sys_select_h.m4 \ $(top_srcdir)/m4/sys_socket_h.m4 \ $(top_srcdir)/m4/sys_stat_h.m4 $(top_srcdir)/m4/sys_time_h.m4 \ $(top_srcdir)/m4/sys_types_h.m4 $(top_srcdir)/m4/sys_uio_h.m4 \ $(top_srcdir)/m4/sys_wait_h.m4 $(top_srcdir)/m4/tempname.m4 \ $(top_srcdir)/m4/threadlib.m4 $(top_srcdir)/m4/time_h.m4 \ - $(top_srcdir)/m4/timespec.m4 $(top_srcdir)/m4/tmpdir.m4 \ - $(top_srcdir)/m4/unistd-safer.m4 $(top_srcdir)/m4/unistd_h.m4 \ - $(top_srcdir)/m4/unlocked-io.m4 $(top_srcdir)/m4/utimbuf.m4 \ - $(top_srcdir)/m4/utimens.m4 $(top_srcdir)/m4/utimes.m4 \ - $(top_srcdir)/m4/vasnprintf.m4 $(top_srcdir)/m4/vasprintf.m4 \ - $(top_srcdir)/m4/vsnprintf.m4 $(top_srcdir)/m4/wait-process.m4 \ - $(top_srcdir)/m4/waitpid.m4 $(top_srcdir)/m4/warn-on-use.m4 \ - $(top_srcdir)/m4/wchar_h.m4 $(top_srcdir)/m4/wchar_t.m4 \ - $(top_srcdir)/m4/wcrtomb.m4 $(top_srcdir)/m4/wctype_h.m4 \ + $(top_srcdir)/m4/time_r.m4 $(top_srcdir)/m4/timegm.m4 \ + $(top_srcdir)/m4/timespec.m4 $(top_srcdir)/m4/tm_gmtoff.m4 \ + $(top_srcdir)/m4/tmpdir.m4 $(top_srcdir)/m4/unistd-safer.m4 \ + $(top_srcdir)/m4/unistd_h.m4 $(top_srcdir)/m4/unlocked-io.m4 \ + $(top_srcdir)/m4/utimbuf.m4 $(top_srcdir)/m4/utimens.m4 \ + $(top_srcdir)/m4/utimes.m4 $(top_srcdir)/m4/vasnprintf.m4 \ + $(top_srcdir)/m4/vasprintf.m4 $(top_srcdir)/m4/vsnprintf.m4 \ + $(top_srcdir)/m4/wait-process.m4 $(top_srcdir)/m4/waitpid.m4 \ + $(top_srcdir)/m4/warn-on-use.m4 $(top_srcdir)/m4/wchar_h.m4 \ + $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/wcrtomb.m4 \ + $(top_srcdir)/m4/wctype_h.m4 $(top_srcdir)/m4/wcwidth.m4 \ $(top_srcdir)/m4/wget.m4 $(top_srcdir)/m4/wint_t.m4 \ $(top_srcdir)/m4/write.m4 $(top_srcdir)/m4/xalloc.m4 \ - $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/configure.ac + $(top_srcdir)/m4/xsize.m4 $(top_srcdir)/m4/xstrndup.m4 \ + $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/src/config.h -CONFIG_CLEAN_FILES = WgetTest.pm +CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am_unit_tests_OBJECTS = unit_tests_OBJECTS = $(am_unit_tests_OBJECTS) unit_tests_LDADD = $(LDADD) am__DEPENDENCIES_1 = -am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) unit_tests_DEPENDENCIES = ../src/libunittest.a ../lib/libgnu.a \ - $(am__DEPENDENCIES_2) + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -251,6 +260,208 @@ am__can_run_installinfo = \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +am__tty_colors_dummy = \ + mgn= red= grn= lgn= blu= brg= std=; \ + am__color_tests=no +am__tty_colors = { \ + $(am__tty_colors_dummy); \ + if test "X$(AM_COLOR_TESTS)" = Xno; then \ + am__color_tests=no; \ + elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ + am__color_tests=yes; \ + elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ + am__color_tests=yes; \ + fi; \ + if test $$am__color_tests = yes; then \ + red='[0;31m'; \ + grn='[0;32m'; \ + lgn='[1;32m'; \ + blu='[1;34m'; \ + mgn='[0;35m'; \ + brg='[1m'; \ + std='[m'; \ + fi; \ +} +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +am__recheck_rx = ^[ ]*:recheck:[ ]* +am__global_test_result_rx = ^[ ]*:global-test-result:[ ]* +am__copy_in_global_log_rx = ^[ ]*:copy-in-global-log:[ ]* +# A command that, given a newline-separated list of test names on the +# standard input, print the name of the tests that are to be re-run +# upon "make recheck". +am__list_recheck_tests = $(AWK) '{ \ + recheck = 1; \ + while ((rc = (getline line < ($$0 ".trs"))) != 0) \ + { \ + if (rc < 0) \ + { \ + if ((getline line2 < ($$0 ".log")) < 0) \ + recheck = 0; \ + break; \ + } \ + else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \ + { \ + recheck = 0; \ + break; \ + } \ + else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \ + { \ + break; \ + } \ + }; \ + if (recheck) \ + print $$0; \ + close ($$0 ".trs"); \ + close ($$0 ".log"); \ +}' +# A command that, given a newline-separated list of test names on the +# standard input, create the global log from their .trs and .log files. +am__create_global_log = $(AWK) ' \ +function fatal(msg) \ +{ \ + print "fatal: making $@: " msg | "cat >&2"; \ + exit 1; \ +} \ +function rst_section(header) \ +{ \ + print header; \ + len = length(header); \ + for (i = 1; i <= len; i = i + 1) \ + printf "="; \ + printf "\n\n"; \ +} \ +{ \ + copy_in_global_log = 1; \ + global_test_result = "RUN"; \ + while ((rc = (getline line < ($$0 ".trs"))) != 0) \ + { \ + if (rc < 0) \ + fatal("failed to read from " $$0 ".trs"); \ + if (line ~ /$(am__global_test_result_rx)/) \ + { \ + sub("$(am__global_test_result_rx)", "", line); \ + sub("[ ]*$$", "", line); \ + global_test_result = line; \ + } \ + else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \ + copy_in_global_log = 0; \ + }; \ + if (copy_in_global_log) \ + { \ + rst_section(global_test_result ": " $$0); \ + while ((rc = (getline line < ($$0 ".log"))) != 0) \ + { \ + if (rc < 0) \ + fatal("failed to read from " $$0 ".log"); \ + print line; \ + }; \ + printf "\n"; \ + }; \ + close ($$0 ".trs"); \ + close ($$0 ".log"); \ +}' +# Restructured Text title. +am__rst_title = { sed 's/.*/ & /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; } +# Solaris 10 'make', and several other traditional 'make' implementations, +# pass "-e" to $(SHELL), and POSIX 2008 even requires this. Work around it +# by disabling -e (using the XSI extension "set +e") if it's set. +am__sh_e_setup = case $$- in *e*) set +e;; esac +# Default flags passed to test drivers. +am__common_driver_flags = \ + --color-tests "$$am__color_tests" \ + --enable-hard-errors "$$am__enable_hard_errors" \ + --expect-failure "$$am__expect_failure" +# To be inserted before the command running the test. Creates the +# directory for the log if needed. Stores in $dir the directory +# containing $f, in $tst the test, in $log the log. Executes the +# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and +# passes TESTS_ENVIRONMENT. Set up options for the wrapper that +# will run the test scripts (or their associated LOG_COMPILER, if +# thy have one). +am__check_pre = \ +$(am__sh_e_setup); \ +$(am__vpath_adj_setup) $(am__vpath_adj) \ +$(am__tty_colors); \ +srcdir=$(srcdir); export srcdir; \ +case "$@" in \ + */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;; \ + *) am__odir=.;; \ +esac; \ +test "x$$am__odir" = x"." || test -d "$$am__odir" \ + || $(MKDIR_P) "$$am__odir" || exit $$?; \ +if test -f "./$$f"; then dir=./; \ +elif test -f "$$f"; then dir=; \ +else dir="$(srcdir)/"; fi; \ +tst=$$dir$$f; log='$@'; \ +if test -n '$(DISABLE_HARD_ERRORS)'; then \ + am__enable_hard_errors=no; \ +else \ + am__enable_hard_errors=yes; \ +fi; \ +case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$f[\ \ ]* | *[\ \ ]$$dir$$f[\ \ ]*) \ + am__expect_failure=yes;; \ + *) \ + am__expect_failure=no;; \ +esac; \ +$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT) +# A shell command to get the names of the tests scripts with any registered +# extension removed (i.e., equivalently, the names of the test logs, with +# the '.log' extension removed). The result is saved in the shell variable +# '$bases'. This honors runtime overriding of TESTS and TEST_LOGS. Sadly, +# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)", +# since that might cause problem with VPATH rewrites for suffix-less tests. +# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'. +am__set_TESTS_bases = \ + bases='$(TEST_LOGS)'; \ + bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ + bases=`echo $$bases` +RECHECK_LOGS = $(TEST_LOGS) +AM_RECURSIVE_TARGETS = check recheck +TEST_SUITE_LOG = test-suite.log +LOG_DRIVER = $(SHELL) $(top_srcdir)/build-aux/test-driver +LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS) +am__set_b = \ + case '$@' in \ + */*) \ + case '$*' in \ + */*) b='$*';; \ + *) b=`echo '$@' | sed 's/\.log$$//'`; \ + esac;; \ + *) \ + b='$*';; \ + esac +am__test_logs1 = $(TESTS:=.log) +am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) +TEST_LOGS = $(am__test_logs2:.px.log=.log) +PX_LOG_DRIVER = $(SHELL) $(top_srcdir)/build-aux/test-driver +PX_LOG_COMPILE = $(PX_LOG_COMPILER) $(AM_PX_LOG_FLAGS) $(PX_LOG_FLAGS) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) pkglibexecdir = @pkglibexecdir@ ACLOCAL = @ACLOCAL@ @@ -294,6 +505,7 @@ EOVERFLOW_VALUE = @EOVERFLOW_VALUE@ ERRNO_H = @ERRNO_H@ EXEEXT = @EXEEXT@ FLOAT_H = @FLOAT_H@ +FNMATCH_H = @FNMATCH_H@ GETADDRINFO_LIB = @GETADDRINFO_LIB@ GETOPT_H = @GETOPT_H@ GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@ @@ -471,6 +683,7 @@ GNULIB_PUTCHAR = @GNULIB_PUTCHAR@ GNULIB_PUTENV = @GNULIB_PUTENV@ GNULIB_PUTS = @GNULIB_PUTS@ GNULIB_PWRITE = @GNULIB_PWRITE@ +GNULIB_QSORT_R = @GNULIB_QSORT_R@ GNULIB_RAISE = @GNULIB_RAISE@ GNULIB_RANDOM = @GNULIB_RANDOM@ GNULIB_RANDOM_R = @GNULIB_RANDOM_R@ @@ -592,6 +805,8 @@ GNULIB_WMEMMOVE = @GNULIB_WMEMMOVE@ GNULIB_WMEMSET = @GNULIB_WMEMSET@ GNULIB_WRITE = @GNULIB_WRITE@ GNULIB__EXIT = @GNULIB__EXIT@ +GNUTLS_CFLAGS = @GNUTLS_CFLAGS@ +GNUTLS_LIBS = @GNUTLS_LIBS@ GREP = @GREP@ HAVE_ACCEPT4 = @HAVE_ACCEPT4@ HAVE_ARPA_INET_H = @HAVE_ARPA_INET_H@ @@ -789,6 +1004,7 @@ HAVE_UNLOCKPT = @HAVE_UNLOCKPT@ HAVE_UNSIGNED_LONG_LONG_INT = @HAVE_UNSIGNED_LONG_LONG_INT@ HAVE_USLEEP = @HAVE_USLEEP@ HAVE_UTIMENSAT = @HAVE_UTIMENSAT@ +HAVE_VALGRIND = @HAVE_VALGRIND@ HAVE_VASPRINTF = @HAVE_VASPRINTF@ HAVE_VDPRINTF = @HAVE_VDPRINTF@ HAVE_WCHAR_H = @HAVE_WCHAR_H@ @@ -858,15 +1074,20 @@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ +LIBPSL_CFLAGS = @LIBPSL_CFLAGS@ +LIBPSL_LIBS = @LIBPSL_LIBS@ LIBPTH = @LIBPTH@ LIBPTH_PREFIX = @LIBPTH_PREFIX@ -LIBS = @LIBICONV@ @LIBINTL@ @LIBS@ $(LIB_CLOCK_GETTIME) +LIBS = @LIBS@ LIBSOCKET = @LIBSOCKET@ LIBSSL = @LIBSSL@ LIBSSL_PREFIX = @LIBSSL_PREFIX@ LIBTHREAD = @LIBTHREAD@ +LIBUNISTRING_UNITYPES_H = @LIBUNISTRING_UNITYPES_H@ +LIBUNISTRING_UNIWIDTH_H = @LIBUNISTRING_UNIWIDTH_H@ LIB_CLOCK_GETTIME = @LIB_CLOCK_GETTIME@ LIB_CRYPTO = @LIB_CRYPTO@ +LIB_POSIX_SPAWN = @LIB_POSIX_SPAWN@ LIB_SELECT = @LIB_SELECT@ LOCALCHARSET_TESTS_ENVIRONMENT = @LOCALCHARSET_TESTS_ENVIRONMENT@ LOCALE_FR = @LOCALE_FR@ @@ -951,6 +1172,8 @@ NEXT_UNISTD_H = @NEXT_UNISTD_H@ NEXT_WCHAR_H = @NEXT_WCHAR_H@ NEXT_WCTYPE_H = @NEXT_WCTYPE_H@ OBJEXT = @OBJEXT@ +OPENSSL_CFLAGS = @OPENSSL_CFLAGS@ +OPENSSL_LIBS = @OPENSSL_LIBS@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ @@ -959,13 +1182,23 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PERL = perl +PCRE_CFLAGS = @PCRE_CFLAGS@ +PCRE_LIBS = @PCRE_LIBS@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ POD2MAN = @POD2MAN@ POSUB = @POSUB@ PRAGMA_COLUMNS = @PRAGMA_COLUMNS@ PRAGMA_SYSTEM_HEADER = @PRAGMA_SYSTEM_HEADER@ PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ PTRDIFF_T_SUFFIX = @PTRDIFF_T_SUFFIX@ +PYTHON = @PYTHON@ +PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@ +PYTHON_PLATFORM = @PYTHON_PLATFORM@ +PYTHON_PREFIX = @PYTHON_PREFIX@ +PYTHON_VERSION = @PYTHON_VERSION@ RANLIB = @RANLIB@ REPLACE_BTOWC = @REPLACE_BTOWC@ REPLACE_CALLOC = @REPLACE_CALLOC@ @@ -1057,10 +1290,12 @@ REPLACE_PTSNAME = @REPLACE_PTSNAME@ REPLACE_PTSNAME_R = @REPLACE_PTSNAME_R@ REPLACE_PUTENV = @REPLACE_PUTENV@ REPLACE_PWRITE = @REPLACE_PWRITE@ +REPLACE_QSORT_R = @REPLACE_QSORT_R@ REPLACE_RAISE = @REPLACE_RAISE@ REPLACE_RANDOM_R = @REPLACE_RANDOM_R@ REPLACE_READ = @REPLACE_READ@ REPLACE_READLINK = @REPLACE_READLINK@ +REPLACE_READLINKAT = @REPLACE_READLINKAT@ REPLACE_REALLOC = @REPLACE_REALLOC@ REPLACE_REALPATH = @REPLACE_REALPATH@ REPLACE_REMOVE = @REPLACE_REMOVE@ @@ -1092,6 +1327,7 @@ REPLACE_STRTOK_R = @REPLACE_STRTOK_R@ REPLACE_STRUCT_LCONV = @REPLACE_STRUCT_LCONV@ REPLACE_STRUCT_TIMEVAL = @REPLACE_STRUCT_TIMEVAL@ REPLACE_SYMLINK = @REPLACE_SYMLINK@ +REPLACE_SYMLINKAT = @REPLACE_SYMLINKAT@ REPLACE_TIMEGM = @REPLACE_TIMEGM@ REPLACE_TMPFILE = @REPLACE_TMPFILE@ REPLACE_TOWLOWER = @REPLACE_TOWLOWER@ @@ -1116,6 +1352,7 @@ REPLACE_WCTOMB = @REPLACE_WCTOMB@ REPLACE_WCWIDTH = @REPLACE_WCWIDTH@ REPLACE_WRITE = @REPLACE_WRITE@ SCHED_H = @SCHED_H@ +SED = @SED@ SERVENT_LIB = @SERVENT_LIB@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ @@ -1134,6 +1371,9 @@ UNDEFINE_STRTOK_R = @UNDEFINE_STRTOK_R@ UNISTD_H_HAVE_WINSOCK2_H = @UNISTD_H_HAVE_WINSOCK2_H@ UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ USE_NLS = @USE_NLS@ +UUID_CFLAGS = @UUID_CFLAGS@ +UUID_LIBS = @UUID_LIBS@ +VALGRIND_TESTS = @VALGRIND_TESTS@ VERSION = @VERSION@ WCHAR_T_SUFFIX = @WCHAR_T_SUFFIX@ WINDOWS_64_BIT_OFF_T = @WINDOWS_64_BIT_OFF_T@ @@ -1142,6 +1382,8 @@ WINT_T_SUFFIX = @WINT_T_SUFFIX@ XGETTEXT = @XGETTEXT@ XGETTEXT_015 = @XGETTEXT_015@ XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@ +ZLIB_CFLAGS = @ZLIB_CFLAGS@ +ZLIB_LIBS = @ZLIB_LIBS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -1187,9 +1429,13 @@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ +pkgpyexecdir = @pkgpyexecdir@ +pkgpythondir = @pkgpythondir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +pyexecdir = @pyexecdir@ +pythondir = @pythondir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ @@ -1199,9 +1445,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -PERLRUN = $(PERL) -I$(srcdir) -EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ - WgetFeature.pm WgetFeature.cfg \ +PX_TESTS = \ Test-auth-basic.px \ Test-auth-no-challenge.px \ Test-auth-no-challenge-url.px \ @@ -1229,6 +1473,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test-ftp-list-Unknown-hidden.px \ Test-ftp-list-Unknown-list-a-fails.px \ Test-ftp-list-UNIX-hidden.px \ + Test-ftp--start-pos.px \ Test-HTTP-Content-Disposition-1.px \ Test-HTTP-Content-Disposition-2.px \ Test-HTTP-Content-Disposition.px \ @@ -1268,6 +1513,7 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test-O.px \ Test--post-file.px \ Test-proxied-https-auth.px \ + Test-proxied-https-auth-keepalive.px \ Test-proxy-auth-basic.px \ Test-restrict-ascii.px \ Test-Restrict-Lowercase.px \ @@ -1279,15 +1525,29 @@ EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ Test--spider-r--no-content-disposition.px \ Test--spider-r--no-content-disposition-trivial.px \ Test--spider-r.px \ + Test--start-pos.px \ + Test--start-pos--continue.px \ Test--httpsonly-r.px \ - run-px certs + Test-204.px + +EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ + WgetTests.pm WgetFeature.pm WgetFeature.cfg $(PX_TESTS) \ + certs unit_tests_SOURCES = -LDADD = ../src/libunittest.a ../lib/libgnu.a $(LIBS) +LDADD = ../src/libunittest.a ../lib/libgnu.a $(LIBS) $(LIB_CLOCK_GETTIME) CLEANFILES = *~ *.bak core core.[0-9]* +TESTS = ./unit-tests$(EXEEXT) $(PX_TESTS) +TEST_EXTENSIONS = .px +PX_LOG_COMPILER = $(PERL) +AM_PX_LOG_FLAGS = -I$(srcdir) +AM_TESTS_ENVIRONMENT = export WGETRC=/dev/null; export SYSTEM_WGETRC=/dev/null;\ + export VALGRIND_TESTS="@VALGRIND_TESTS@"; + all: all-am .SUFFIXES: +.SUFFIXES: .log .px .px$(EXEEXT) .trs $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -1318,8 +1578,6 @@ $(top_srcdir)/configure: $(am__configure_deps) $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): -WgetTest.pm: $(top_builddir)/config.status $(srcdir)/WgetTest.pm.in - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ clean-checkPROGRAMS: -test -z "$(check_PROGRAMS)" || rm -f $(check_PROGRAMS) @@ -1340,6 +1598,169 @@ ctags CTAGS: cscope cscopelist: +# Recover from deleted '.trs' file; this should ensure that +# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create +# both 'foo.log' and 'foo.trs'. Break the recipe in two subshells +# to avoid problems with "make -n". +.log.trs: + rm -f $< $@ + $(MAKE) $(AM_MAKEFLAGS) $< + +# Leading 'am--fnord' is there to ensure the list of targets does not +# expand to empty, as could happen e.g. with make check TESTS=''. +am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck) +am--force-recheck: + @: + +$(TEST_SUITE_LOG): $(TEST_LOGS) + @$(am__set_TESTS_bases); \ + am__f_ok () { test -f "$$1" && test -r "$$1"; }; \ + redo_bases=`for i in $$bases; do \ + am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \ + done`; \ + if test -n "$$redo_bases"; then \ + redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \ + redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \ + if $(am__make_dryrun); then :; else \ + rm -f $$redo_logs && rm -f $$redo_results || exit 1; \ + fi; \ + fi; \ + if test -n "$$am__remaking_logs"; then \ + echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ + "recursion detected" >&2; \ + else \ + am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ + fi; \ + if $(am__make_dryrun); then :; else \ + st=0; \ + errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ + for i in $$redo_bases; do \ + test -f $$i.trs && test -r $$i.trs \ + || { echo "$$errmsg $$i.trs" >&2; st=1; }; \ + test -f $$i.log && test -r $$i.log \ + || { echo "$$errmsg $$i.log" >&2; st=1; }; \ + done; \ + test $$st -eq 0 || exit 1; \ + fi + @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \ + ws='[ ]'; \ + results=`for b in $$bases; do echo $$b.trs; done`; \ + test -n "$$results" || results=/dev/null; \ + all=` grep "^$$ws*:test-result:" $$results | wc -l`; \ + pass=` grep "^$$ws*:test-result:$$ws*PASS" $$results | wc -l`; \ + fail=` grep "^$$ws*:test-result:$$ws*FAIL" $$results | wc -l`; \ + skip=` grep "^$$ws*:test-result:$$ws*SKIP" $$results | wc -l`; \ + xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \ + xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \ + error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \ + if test `expr $$fail + $$xpass + $$error` -eq 0; then \ + success=true; \ + else \ + success=false; \ + fi; \ + br='==================='; br=$$br$$br$$br$$br; \ + result_count () \ + { \ + if test x"$$1" = x"--maybe-color"; then \ + maybe_colorize=yes; \ + elif test x"$$1" = x"--no-color"; then \ + maybe_colorize=no; \ + else \ + echo "$@: invalid 'result_count' usage" >&2; exit 4; \ + fi; \ + shift; \ + desc=$$1 count=$$2; \ + if test $$maybe_colorize = yes && test $$count -gt 0; then \ + color_start=$$3 color_end=$$std; \ + else \ + color_start= color_end=; \ + fi; \ + echo "$${color_start}# $$desc $$count$${color_end}"; \ + }; \ + create_testsuite_report () \ + { \ + result_count $$1 "TOTAL:" $$all "$$brg"; \ + result_count $$1 "PASS: " $$pass "$$grn"; \ + result_count $$1 "SKIP: " $$skip "$$blu"; \ + result_count $$1 "XFAIL:" $$xfail "$$lgn"; \ + result_count $$1 "FAIL: " $$fail "$$red"; \ + result_count $$1 "XPASS:" $$xpass "$$red"; \ + result_count $$1 "ERROR:" $$error "$$mgn"; \ + }; \ + { \ + echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \ + $(am__rst_title); \ + create_testsuite_report --no-color; \ + echo; \ + echo ".. contents:: :depth: 2"; \ + echo; \ + for b in $$bases; do echo $$b; done \ + | $(am__create_global_log); \ + } >$(TEST_SUITE_LOG).tmp || exit 1; \ + mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG); \ + if $$success; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ + fi; \ + echo "$${col}$$br$${std}"; \ + echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}$$br$${std}"; \ + create_testsuite_report --maybe-color; \ + echo "$$col$$br$$std"; \ + if $$success; then :; else \ + echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}"; \ + if test -n "$(PACKAGE_BUGREPORT)"; then \ + echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \ + fi; \ + echo "$$col$$br$$std"; \ + fi; \ + $$success || exit 1 + +check-TESTS: + @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list + @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list + @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + @set +e; $(am__set_TESTS_bases); \ + log_list=`for i in $$bases; do echo $$i.log; done`; \ + trs_list=`for i in $$bases; do echo $$i.trs; done`; \ + log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \ + $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \ + exit $$?; +recheck: all $(check_PROGRAMS) + @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) + @set +e; $(am__set_TESTS_bases); \ + bases=`for i in $$bases; do echo $$i; done \ + | $(am__list_recheck_tests)` || exit 1; \ + log_list=`for i in $$bases; do echo $$i.log; done`; \ + log_list=`echo $$log_list`; \ + $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \ + am__force_recheck=am--force-recheck \ + TEST_LOGS="$$log_list"; \ + exit $$? +./unit-tests.log: ./unit-tests$(EXEEXT) + @p='./unit-tests$(EXEEXT)'; \ + b='./unit-tests'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +.px.log: + @p='$<'; \ + $(am__set_b); \ + $(am__check_pre) $(PX_LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_PX_LOG_DRIVER_FLAGS) $(PX_LOG_DRIVER_FLAGS) -- $(PX_LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +@am__EXEEXT_TRUE@.px$(EXEEXT).log: +@am__EXEEXT_TRUE@ @p='$<'; \ +@am__EXEEXT_TRUE@ $(am__set_b); \ +@am__EXEEXT_TRUE@ $(am__check_pre) $(PX_LOG_DRIVER) --test-name "$$f" \ +@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ +@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_PX_LOG_DRIVER_FLAGS) $(PX_LOG_DRIVER_FLAGS) -- $(PX_LOG_COMPILE) \ +@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) + distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -1372,7 +1793,7 @@ distdir: $(DISTFILES) done check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) - $(MAKE) $(AM_MAKEFLAGS) check-local + $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am all-am: Makefile installdirs: @@ -1396,6 +1817,9 @@ install-strip: "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: + -test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS) + -test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs) + -test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) @@ -1475,7 +1899,7 @@ uninstall-am: .MAKE: check-am install-am install-strip -.PHONY: all all-am check check-am check-local clean \ +.PHONY: all all-am check check-TESTS check-am clean \ clean-checkPROGRAMS clean-generic cscopelist-am ctags-am \ distclean distclean-compile distclean-generic distdir dvi \ dvi-am html html-am info info-am install install-am \ @@ -1485,16 +1909,10 @@ uninstall-am: install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic pdf pdf-am ps ps-am tags-am uninstall \ - uninstall-am + mostlyclean-generic pdf pdf-am ps ps-am recheck tags-am \ + uninstall uninstall-am -.PHONY: test run-unit-tests run-px-tests - -check-local: test - -test: ../src/wget$(EXEEXT) run-unit-tests run-px-tests - ../src/wget$(EXEEXT): cd ../src && $(MAKE) $(AM_MAKEFLAGS) @@ -1506,12 +1924,6 @@ test: ../src/wget$(EXEEXT) run-unit-tests run-px-tests ../lib/libgnu.a: cd ../lib && $(MAKE) $(AM_MAKEFLAGS) -run-unit-tests: unit-tests$(EXEEXT) ../src/libunittest.a - ./unit-tests$(EXEEXT) - -run-px-tests: WgetTest.pm ../src/wget$(EXEEXT) - $(srcdir)/run-px $(top_srcdir) - # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/tests/Test--httpsonly-r.px b/tests/Test--httpsonly-r.px index 019df1a..69d8c60 100755 --- a/tests/Test--httpsonly-r.px +++ b/tests/Test--httpsonly-r.px @@ -3,6 +3,8 @@ use strict; use warnings; +use WgetFeature qw(https); + use HTTPTest; @@ -66,14 +68,11 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--httpsonly-r", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, output => \%expected_downloaded_files); -print $expected_error_code."\n"; exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test--no-content-disposition-trivial.px b/tests/Test--no-content-disposition-trivial.px index 337bc7c..cf89b4a 100755 --- a/tests/Test--no-content-disposition-trivial.px +++ b/tests/Test--no-content-disposition-trivial.px @@ -45,12 +45,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--no-content-disposition-trivial", - input => \%urls, +my $the_test = HTTPTest->new (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--no-content-disposition.px b/tests/Test--no-content-disposition.px index 27523a4..94f4d50 100755 --- a/tests/Test--no-content-disposition.px +++ b/tests/Test--no-content-disposition.px @@ -46,12 +46,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--no-content-disposition", - input => \%urls, +my $the_test = HTTPTest->new (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--post-file.px b/tests/Test--post-file.px index 1c017b7..9c866b6 100755 --- a/tests/Test--post-file.px +++ b/tests/Test--post-file.px @@ -8,15 +8,14 @@ use HTTPTest; ############################################################################### -my $cmdline = $WgetTest::WGETPATH . " -d --post-file=nofile http://localhost:{{port}}/"; +my $cmdline = $WgetTest::WGETPATH . " --post-file=nofile http://localhost:{{port}}/"; my $expected_error_code = 3; ############################################################################### -my $the_test = HTTPTest->new (name => "Test-missing-file", - cmdline => $cmdline, +my $the_test = HTTPTest->new (cmdline => $cmdline, errcode => $expected_error_code); exit $the_test->run(); diff --git a/tests/Test--spider-fail.px b/tests/Test--spider-fail.px index 98c1b9c..d0dfad6 100755 --- a/tests/Test--spider-fail.px +++ b/tests/Test--spider-fail.px @@ -42,12 +42,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--spider-fail", - input => \%urls, +my $the_test = HTTPTest->new (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-r--no-content-disposition-trivial.px b/tests/Test--spider-r--no-content-disposition-trivial.px index 88b53c4..0f28685 100755 --- a/tests/Test--spider-r--no-content-disposition-trivial.px +++ b/tests/Test--spider-r--no-content-disposition-trivial.px @@ -99,12 +99,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--spider-r--no-content-disposition-trivial", - input => \%urls, +my $the_test = HTTPTest->new (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-r--no-content-disposition.px b/tests/Test--spider-r--no-content-disposition.px index 6d7112a..53fb7a2 100755 --- a/tests/Test--spider-r--no-content-disposition.px +++ b/tests/Test--spider-r--no-content-disposition.px @@ -100,12 +100,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--spider-r--no-content-disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-r-HTTP-Content-Disposition.px b/tests/Test--spider-r-HTTP-Content-Disposition.px index 8917b72..963003e 100755 --- a/tests/Test--spider-r-HTTP-Content-Disposition.px +++ b/tests/Test--spider-r-HTTP-Content-Disposition.px @@ -100,12 +100,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--spider-r-HTTP-Content-Disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-r.px b/tests/Test--spider-r.px index b84bafb..dbafe2e 100755 --- a/tests/Test--spider-r.px +++ b/tests/Test--spider-r.px @@ -99,12 +99,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--spider-r", - input => \%urls, +my $the_test = HTTPTest->new (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 633c329..2443c95 100755 --- a/tests/Test--spider.px +++ b/tests/Test--spider.px @@ -42,12 +42,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test--spider", - input => \%urls, +my $the_test = HTTPTest->new (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--start-pos--continue.px b/tests/Test--start-pos--continue.px new file mode 100755 index 0000000..a821a78 --- /dev/null +++ b/tests/Test--start-pos--continue.px @@ -0,0 +1,54 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use HTTPTest; + + +############################################################################### + +my $existingfile = <<EOF; +content should be preserved. +EOF + +my $wholefile = "1234"; + +# code, msg, headers, content +my %urls = ( + '/somefile.txt' => { + code => "206", + msg => "Dontcare", + headers => { + "Content-type" => "text/plain", + }, + content => $wholefile, + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --start-pos=1 --continue --debug http://localhost:{{port}}/somefile.txt"; + +my $expected_error_code = 0; + +my %existing_files = ( + 'somefile.txt' => { + content => $existingfile, + }, +); + +my %expected_downloaded_files = ( + 'somefile.txt.1' => { + content => substr($wholefile, 1), + }, +); + +############################################################################### + +my $the_test = HTTPTest->new (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--start-pos.px b/tests/Test--start-pos.px new file mode 100755 index 0000000..5c887ab --- /dev/null +++ b/tests/Test--start-pos.px @@ -0,0 +1,43 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use HTTPTest; + + +############################################################################### + +my $dummyfile = "1234"; + +# code, msg, headers, content +my %urls = ( + '/dummy.txt' => { + code => "206", + msg => "Dontcare", + headers => { + "Content-Type" => "text/plain", + }, + content => $dummyfile + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --start-pos=1 http://localhost:{{port}}/dummy.txt"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + 'dummy.txt' => { + content => substr($dummyfile, 1), + } +); + +############################################################################### + +my $the_test = HTTPTest->new (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-204.px b/tests/Test-204.px new file mode 100755 index 0000000..e9eea1a --- /dev/null +++ b/tests/Test-204.px @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use HTTPTest; + + +############################################################################### + +# code, msg, headers, content +my %urls = ( + '/dummy' => { + code => "204", + msg => "Dontcare", + }, +); + +my $cmdline = $WgetTest::WGETPATH . " http://localhost:{{port}}/dummy"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( +); + +############################################################################### + +my $the_test = HTTPTest->new (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-E-k-K.px b/tests/Test-E-k-K.px index 211988b..aaae6fe 100755 --- a/tests/Test-E-k-K.px +++ b/tests/Test-E-k-K.px @@ -79,12 +79,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-E-k-K", - input => \%urls, +my $the_test = HTTPTest->new (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-E-k.px b/tests/Test-E-k.px index 99df5b4..dc1031b 100755 --- a/tests/Test-E-k.px +++ b/tests/Test-E-k.px @@ -76,12 +76,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-E-k", - input => \%urls, +my $the_test = HTTPTest->new (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-HTTP-Content-Disposition-1.px b/tests/Test-HTTP-Content-Disposition-1.px index ef82eda..343258c 100755 --- a/tests/Test-HTTP-Content-Disposition-1.px +++ b/tests/Test-HTTP-Content-Disposition-1.px @@ -65,8 +65,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition-1", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -74,4 +73,3 @@ my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition-1", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-HTTP-Content-Disposition-2.px b/tests/Test-HTTP-Content-Disposition-2.px index 55b2abb..e7a2703 100755 --- a/tests/Test-HTTP-Content-Disposition-2.px +++ b/tests/Test-HTTP-Content-Disposition-2.px @@ -65,8 +65,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition-2", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -74,4 +73,3 @@ my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition-2", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-HTTP-Content-Disposition.px b/tests/Test-HTTP-Content-Disposition.px index 9b966f7..29f56d1 100755 --- a/tests/Test-HTTP-Content-Disposition.px +++ b/tests/Test-HTTP-Content-Disposition.px @@ -46,12 +46,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-N--no-content-disposition-trivial.px b/tests/Test-N--no-content-disposition-trivial.px index 01e70c1..8abff7b 100755 --- a/tests/Test-N--no-content-disposition-trivial.px +++ b/tests/Test-N--no-content-disposition-trivial.px @@ -38,12 +38,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N--no-content-disposition-trivial", - input => \%urls, +my $the_test = HTTPTest->new (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-N--no-content-disposition.px b/tests/Test-N--no-content-disposition.px index 42ac7ee..7ece995 100755 --- a/tests/Test-N--no-content-disposition.px +++ b/tests/Test-N--no-content-disposition.px @@ -39,12 +39,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N--no-content-disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-N-HTTP-Content-Disposition.px b/tests/Test-N-HTTP-Content-Disposition.px index ab8cea8..de4609b 100755 --- a/tests/Test-N-HTTP-Content-Disposition.px +++ b/tests/Test-N-HTTP-Content-Disposition.px @@ -40,12 +40,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N-HTTP-Content-Disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-N-current.px b/tests/Test-N-current.px index fcf4d88..a8decdb 100755 --- a/tests/Test-N-current.px +++ b/tests/Test-N-current.px @@ -54,8 +54,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N-current", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -63,4 +62,3 @@ my $the_test = HTTPTest->new (name => "Test-N-current", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-N-no-info.px b/tests/Test-N-no-info.px index 698ce8b..3c772a5 100755 --- a/tests/Test-N-no-info.px +++ b/tests/Test-N-no-info.px @@ -52,8 +52,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N-current", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -61,4 +60,3 @@ my $the_test = HTTPTest->new (name => "Test-N-current", 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 0c0128c..6bb18cb 100755 --- a/tests/Test-N-old.px +++ b/tests/Test-N-old.px @@ -52,8 +52,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N-old", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -61,4 +60,3 @@ my $the_test = HTTPTest->new (name => "Test-N-old", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-N-smaller.px b/tests/Test-N-smaller.px index 2ea0ab8..34d4cd9 100755 --- a/tests/Test-N-smaller.px +++ b/tests/Test-N-smaller.px @@ -55,8 +55,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N-current", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -64,4 +63,3 @@ my $the_test = HTTPTest->new (name => "Test-N-current", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-N.px b/tests/Test-N.px index 91528db..65cc33f 100755 --- a/tests/Test-N.px +++ b/tests/Test-N.px @@ -38,12 +38,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-N", - input => \%urls, +my $the_test = HTTPTest->new (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-O--no-content-disposition-trivial.px b/tests/Test-O--no-content-disposition-trivial.px index a5b264b..cef3caa 100755 --- a/tests/Test-O--no-content-disposition-trivial.px +++ b/tests/Test-O--no-content-disposition-trivial.px @@ -36,12 +36,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-O--no-content-disposition-trivial", - input => \%urls, +my $the_test = HTTPTest->new (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-O--no-content-disposition.px b/tests/Test-O--no-content-disposition.px index 92263ff..9d2bf41 100755 --- a/tests/Test-O--no-content-disposition.px +++ b/tests/Test-O--no-content-disposition.px @@ -37,12 +37,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-O--no-content-disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-O-HTTP-Content-Disposition.px b/tests/Test-O-HTTP-Content-Disposition.px index 23ae687..d7a7f76 100755 --- a/tests/Test-O-HTTP-Content-Disposition.px +++ b/tests/Test-O-HTTP-Content-Disposition.px @@ -37,12 +37,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-O-HTTP-Content-Disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-O-nc.px b/tests/Test-O-nc.px index 94a7b43..171bf16 100755 --- a/tests/Test-O-nc.px +++ b/tests/Test-O-nc.px @@ -36,12 +36,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-O-nc", - input => \%urls, +my $the_test = HTTPTest->new (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-O-nonexisting.px b/tests/Test-O-nonexisting.px index 8fde7c8..d663b65 100755 --- a/tests/Test-O-nonexisting.px +++ b/tests/Test-O-nonexisting.px @@ -36,12 +36,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-O-nonexisting", - input => \%urls, +my $the_test = HTTPTest->new (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-O.px b/tests/Test-O.px index eed42de..7e4024c 100755 --- a/tests/Test-O.px +++ b/tests/Test-O.px @@ -36,12 +36,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-O", - input => \%urls, +my $the_test = HTTPTest->new (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-Restrict-Lowercase.px b/tests/Test-Restrict-Lowercase.px index 860e8a7..a675989 100755 --- a/tests/Test-Restrict-Lowercase.px +++ b/tests/Test-Restrict-Lowercase.px @@ -45,12 +45,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-Restrict-Lowercase", - input => \%urls, +my $the_test = HTTPTest->new (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-Restrict-Uppercase.px b/tests/Test-Restrict-Uppercase.px index 3021347..64e8a47 100755 --- a/tests/Test-Restrict-Uppercase.px +++ b/tests/Test-Restrict-Uppercase.px @@ -45,12 +45,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-Restrict-Uppercase", - input => \%urls, +my $the_test = HTTPTest->new (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-auth-basic.px b/tests/Test-auth-basic.px index 008b3fc..ce9100d 100755 --- a/tests/Test-auth-basic.px +++ b/tests/Test-auth-basic.px @@ -38,12 +38,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-auth-basic", - input => \%urls, +my $the_test = HTTPTest->new (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-auth-no-challenge-url.px b/tests/Test-auth-no-challenge-url.px index 46bb877..204e9a0 100755 --- a/tests/Test-auth-no-challenge-url.px +++ b/tests/Test-auth-no-challenge-url.px @@ -39,12 +39,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-auth-no-challenge-url", - input => \%urls, +my $the_test = HTTPTest->new (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-auth-no-challenge.px b/tests/Test-auth-no-challenge.px index 7ee2e41..0794ece 100755 --- a/tests/Test-auth-no-challenge.px +++ b/tests/Test-auth-no-challenge.px @@ -40,12 +40,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-auth-no-challenge", - input => \%urls, +my $the_test = HTTPTest->new (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-auth-retcode.px b/tests/Test-auth-retcode.px index 4d8e6d6..bc1ea8f 100644..100755 --- a/tests/Test-auth-retcode.px +++ b/tests/Test-auth-retcode.px @@ -28,8 +28,7 @@ my %expected_downloaded_files = (); ############################################################################### -my $the_test = HTTPTest->new (name => "Test-auth-retcode", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, output => \%expected_downloaded_files); diff --git a/tests/Test-auth-with-content-disposition.px b/tests/Test-auth-with-content-disposition.px index 96755ad..7e252a3 100755 --- a/tests/Test-auth-with-content-disposition.px +++ b/tests/Test-auth-with-content-disposition.px @@ -39,12 +39,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-auth-with-content-disposition", - input => \%urls, +my $the_test = HTTPTest->new (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-c-full.px b/tests/Test-c-full.px index 4aa8d96..973f885 100755 --- a/tests/Test-c-full.px +++ b/tests/Test-c-full.px @@ -46,8 +46,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-c-full", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -55,4 +54,3 @@ my $the_test = HTTPTest->new (name => "Test-c-full", 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 ccb20fd..2aca247 100755 --- a/tests/Test-c-partial.px +++ b/tests/Test-c-partial.px @@ -56,8 +56,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-c-partial", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -65,4 +64,3 @@ my $the_test = HTTPTest->new (name => "Test-c-partial", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-c-shorter.px b/tests/Test-c-shorter.px index c4802da..888ead0 100755 --- a/tests/Test-c-shorter.px +++ b/tests/Test-c-shorter.px @@ -53,8 +53,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-c-partial", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -62,4 +61,3 @@ my $the_test = HTTPTest->new (name => "Test-c-partial", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-c.px b/tests/Test-c.px index 0326697..48d55ae 100755 --- a/tests/Test-c.px +++ b/tests/Test-c.px @@ -43,8 +43,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-c", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -52,4 +51,3 @@ my $the_test = HTTPTest->new (name => "Test-c", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-cookies-401.px b/tests/Test-cookies-401.px index 1c02490..7226c2f 100755 --- a/tests/Test-cookies-401.px +++ b/tests/Test-cookies-401.px @@ -42,12 +42,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-cookies-401", - input => \%urls, +my $the_test = HTTPTest->new (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-cookies.px b/tests/Test-cookies.px index ac7da56..99fda8f 100755 --- a/tests/Test-cookies.px +++ b/tests/Test-cookies.px @@ -103,12 +103,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-cookies", - input => \%urls, +my $the_test = HTTPTest->new (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-ftp--start-pos.px b/tests/Test-ftp--start-pos.px new file mode 100755 index 0000000..00a9a00 --- /dev/null +++ b/tests/Test-ftp--start-pos.px @@ -0,0 +1,39 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use FTPTest; + + +############################################################################### + +my $dummyfile = "1234"; + +# code, msg, headers, content +my %urls = ( + '/dummy.txt' => { + content => $dummyfile + }, +); + +my $cmdline = $WgetTest::WGETPATH . " --start-pos=1 ftp://localhost:{{port}}/dummy.txt"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + 'dummy.txt' => { + content => substr($dummyfile, 1), + } +); + +############################################################################### + +my $the_test = FTPTest->new ( + 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-ftp-bad-list.px b/tests/Test-ftp-bad-list.px index 8584d0a..78afd77 100755 --- a/tests/Test-ftp-bad-list.px +++ b/tests/Test-ftp-bad-list.px @@ -56,7 +56,7 @@ my %preexisting_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-bad-list", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -66,4 +66,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-bad-list", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp-iri-disabled.px b/tests/Test-ftp-iri-disabled.px index d8dac31..4b4772f 100755 --- a/tests/Test-ftp-iri-disabled.px +++ b/tests/Test-ftp-iri-disabled.px @@ -41,7 +41,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-iri-disabled", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -49,4 +49,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-iri-disabled", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp-iri-fallback.px b/tests/Test-ftp-iri-fallback.px index c78518f..36c22c7 100755 --- a/tests/Test-ftp-iri-fallback.px +++ b/tests/Test-ftp-iri-fallback.px @@ -37,7 +37,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-iri-fallback", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -45,4 +45,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-iri-fallback", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp-iri-recursive.px b/tests/Test-ftp-iri-recursive.px index 46b6fd0..b487f70 100755 --- a/tests/Test-ftp-iri-recursive.px +++ b/tests/Test-ftp-iri-recursive.px @@ -37,7 +37,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-iri-recursive", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -45,4 +45,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-iri-recursive", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp-iri.px b/tests/Test-ftp-iri.px index a4b7fe1..e196dbe 100755 --- a/tests/Test-ftp-iri.px +++ b/tests/Test-ftp-iri.px @@ -38,7 +38,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-iri", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -46,4 +46,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-iri", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp-list-Multinet.px b/tests/Test-ftp-list-Multinet.px index 40a1bdb..e21b2a4 100644..100755 --- a/tests/Test-ftp-list-Multinet.px +++ b/tests/Test-ftp-list-Multinet.px @@ -56,7 +56,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-list-Multinet", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -64,4 +64,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-list-Multinet", server_behavior => {list_empty_if_list_a => 1, syst_response => "215 UNIX MultiNet Unix Emulation V5.3(93)"}); exit $the_test->run(); - diff --git a/tests/Test-ftp-list-UNIX-hidden.px b/tests/Test-ftp-list-UNIX-hidden.px index a99e9d2..d90d9f8 100644..100755 --- a/tests/Test-ftp-list-UNIX-hidden.px +++ b/tests/Test-ftp-list-UNIX-hidden.px @@ -55,11 +55,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-list-UNIX-hidden", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, output => \%expected_downloaded_files, server_behavior => {list_no_hidden_if_list => 1}); exit $the_test->run(); - diff --git a/tests/Test-ftp-list-Unknown-a.px b/tests/Test-ftp-list-Unknown-a.px index 3c10f4a..5360122 100644..100755 --- a/tests/Test-ftp-list-Unknown-a.px +++ b/tests/Test-ftp-list-Unknown-a.px @@ -66,7 +66,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown-a", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -74,4 +74,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown-a", server_behavior => {list_dont_clean_path => 1, syst_response => "215 Unknown ftp service"}); exit $the_test->run(); - diff --git a/tests/Test-ftp-list-Unknown-hidden.px b/tests/Test-ftp-list-Unknown-hidden.px index c41757f..c300761 100644..100755 --- a/tests/Test-ftp-list-Unknown-hidden.px +++ b/tests/Test-ftp-list-Unknown-hidden.px @@ -58,7 +58,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown-hidden", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -66,4 +66,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown-hidden", server_behavior => {list_no_hidden_if_list => 1, syst_response => "215 Unknown ftp service"}); exit $the_test->run(); - diff --git a/tests/Test-ftp-list-Unknown-list-a-fails.px b/tests/Test-ftp-list-Unknown-list-a-fails.px index e6192ff..e52b36a 100644..100755 --- a/tests/Test-ftp-list-Unknown-list-a-fails.px +++ b/tests/Test-ftp-list-Unknown-list-a-fails.px @@ -51,7 +51,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown-list-a-fails", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -59,4 +59,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown-list-a-fails", server_behavior => {list_fails_if_list_a => 1, syst_response => "215 Unknown ftp service"}); exit $the_test->run(); - diff --git a/tests/Test-ftp-list-Unknown.px b/tests/Test-ftp-list-Unknown.px index 23384d7..71e4362 100644..100755 --- a/tests/Test-ftp-list-Unknown.px +++ b/tests/Test-ftp-list-Unknown.px @@ -54,7 +54,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -62,4 +62,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-list-Unknown", server_behavior => {list_empty_if_list_a => 1, syst_response => "215 Unknown ftp service"}); exit $the_test->run(); - diff --git a/tests/Test-ftp-pasv-fail.px b/tests/Test-ftp-pasv-fail.px index e92f315..f050fdd 100755 --- a/tests/Test-ftp-pasv-fail.px +++ b/tests/Test-ftp-pasv-fail.px @@ -46,7 +46,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-pasv-fail", +my $the_test = FTPTest->new ( server_behavior => {fail_on_pasv => 1}, input => \%urls, cmdline => $cmdline, @@ -55,4 +55,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-pasv-fail", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp-recursive.px b/tests/Test-ftp-recursive.px index c9d7be4..88fb85e 100755 --- a/tests/Test-ftp-recursive.px +++ b/tests/Test-ftp-recursive.px @@ -44,7 +44,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp-recursive", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -52,4 +52,3 @@ my $the_test = FTPTest->new (name => "Test-ftp-recursive", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-ftp.px b/tests/Test-ftp.px index 2b8e25b..fdedfbc 100755 --- a/tests/Test-ftp.px +++ b/tests/Test-ftp.px @@ -34,7 +34,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-ftp", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -42,4 +42,3 @@ my $the_test = FTPTest->new (name => "Test-ftp", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-i-ftp.px b/tests/Test-i-ftp.px index aa9f3de..6fd2c05 100755 --- a/tests/Test-i-ftp.px +++ b/tests/Test-i-ftp.px @@ -69,7 +69,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = FTPTest->new (name => "Test-i-ftp", +my $the_test = FTPTest->new ( input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, @@ -77,4 +77,3 @@ my $the_test = FTPTest->new (name => "Test-i-ftp", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/Test-i-http.px b/tests/Test-i-http.px index 10dabcc..a076973 100755 --- a/tests/Test-i-http.px +++ b/tests/Test-i-http.px @@ -81,12 +81,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-i-http", - input => \%urls, +my $the_test = HTTPTest->new (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-idn-cmd-utf8.px b/tests/Test-idn-cmd-utf8.px index 500c3d5..42e4318 100755 --- a/tests/Test-idn-cmd-utf8.px +++ b/tests/Test-idn-cmd-utf8.px @@ -41,12 +41,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-idn-cmd-utf8", - input => \%urls, +my $the_test = HTTPTest->new (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-idn-cmd.px b/tests/Test-idn-cmd.px index a81da8c..3098419 100755 --- a/tests/Test-idn-cmd.px +++ b/tests/Test-idn-cmd.px @@ -41,12 +41,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-idn-cmd", - input => \%urls, +my $the_test = HTTPTest->new (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-idn-headers.px b/tests/Test-idn-headers.px index 7808b88..6b0c614 100755 --- a/tests/Test-idn-headers.px +++ b/tests/Test-idn-headers.px @@ -56,12 +56,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-idn-headers", - input => \%urls, +my $the_test = HTTPTest->new (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-idn-meta.px b/tests/Test-idn-meta.px index 9fdbbd0..fd7dcfa 100755 --- a/tests/Test-idn-meta.px +++ b/tests/Test-idn-meta.px @@ -27,7 +27,8 @@ my %urls = ( code => "200", msg => "You want fries with that?", headers => { - 'Content-Type' => 'text/html; charset=UTF-8', + # HTTP header preceeds http-equiv, simply just omit it here + #'Content-Type' => 'text/html; charset=UTF-8', }, content => $starter_file, }, @@ -57,12 +58,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-idn-meta", - input => \%urls, +my $the_test = HTTPTest->new (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-idn-robots-utf8.px b/tests/Test-idn-robots-utf8.px index 5f2dd85..1d1bfac 100755 --- a/tests/Test-idn-robots-utf8.px +++ b/tests/Test-idn-robots-utf8.px @@ -68,12 +68,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-idn-robots-utf8", - input => \%urls, +my $the_test = HTTPTest->new (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-idn-robots.px b/tests/Test-idn-robots.px index ae22b7c..888fcdf 100755 --- a/tests/Test-idn-robots.px +++ b/tests/Test-idn-robots.px @@ -93,12 +93,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-idn-robots", - input => \%urls, +my $the_test = HTTPTest->new (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-iri-disabled.px b/tests/Test-iri-disabled.px index c226a6e..e019d4f 100755 --- a/tests/Test-iri-disabled.px +++ b/tests/Test-iri-disabled.px @@ -186,12 +186,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-iri-disabled", - input => \%urls, +my $the_test = HTTPTest->new (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-iri-forced-remote.px b/tests/Test-iri-forced-remote.px index d1bed72..5dee3bb 100755 --- a/tests/Test-iri-forced-remote.px +++ b/tests/Test-iri-forced-remote.px @@ -48,7 +48,7 @@ my $pagefrancais = <<EOF; <html> <head> <title>La seule page en français</title> - <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <p> @@ -117,17 +117,10 @@ my %urls = ( content => "", }, '/p1_fran%C3%A7ais.html' => { # UTF-8 encoded - code => "404", - msg => "File not found", - headers => { - "Content-type" => "text/html; charset=UTF-8", - }, - content => $page404, - }, - '/p1_fran%E7ais.html' => { code => "200", msg => "Ok", headers => { + # wrong charset here, overridden by --remote-encoding=iso-8859-1 "Content-type" => "text/html; charset=UTF-8", }, content => $pagefrancais, @@ -140,14 +133,6 @@ my %urls = ( }, content => $pageeen, }, - '/p2_%E9%E9n.html' => { - code => "200", - msg => "Ok", - headers => { - "Content-type" => "text/html; charset=ISO-8859-1", - }, - content => $pageeen, - }, '/p3_%E2%82%AC%E2%82%AC%E2%82%AC.html' => { # UTF-8 encoded code => "200", msg => "Ok", @@ -156,14 +141,6 @@ my %urls = ( }, content => $pageeuro, }, - '/p3_%A4%A4%A4.html' => { - code => "200", - msg => "Ok", - headers => { - "Content-type" => "text/plain", - }, - content => $pageeuro, - }, '/p3_%C2%A4%C2%A4%C2%A4.html' => { # UTF-8 encoded code => "200", msg => "Ok", @@ -174,7 +151,7 @@ my %urls = ( }, ); -my $cmdline = $WgetTest::WGETPATH . " --iri --trust-server-names --remote-encoding=iso-8859-1 -nH -r http://localhost:{{port}}/"; +my $cmdline = $WgetTest::WGETPATH . " --iri -e robots=on --trust-server-names --remote-encoding=iso-8859-1 -nH -r http://localhost:{{port}}/"; my $expected_error_code = 0; @@ -185,7 +162,7 @@ my %expected_downloaded_files = ( 'robots.txt' => { content => "", }, - "p1_fran${ccedilla_l15}ais.html" => { + "p1_fran${ccedilla_u8}ais.html" => { content => $pagefrancais, }, "p2_${eacute_u8}${eacute_u8}n.html" => { @@ -198,12 +175,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-iri-forced-remote", - input => \%urls, +my $the_test = HTTPTest->new (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-iri-list.px b/tests/Test-iri-list.px index ad88e4c..5e56072 100755 --- a/tests/Test-iri-list.px +++ b/tests/Test-iri-list.px @@ -164,12 +164,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-iri-list", - input => \%urls, +my $the_test = HTTPTest->new (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-iri-percent.px b/tests/Test-iri-percent.px index fcac35c..7c4f4c8 100755 --- a/tests/Test-iri-percent.px +++ b/tests/Test-iri-percent.px @@ -11,6 +11,8 @@ use HTTPTest; my $ccedilla_l15 = "\xE7"; my $ccedilla_l15_pct = "%E7"; +my $ccedilla_u8 = "\xC3\xA7"; +my $ccedilla_u8_pct = "%C3%A7"; my $eacute_l1 = "\xE9"; my $eacute_u8 = "\xC3\xA9"; my $eacute_u8_pct = "%C3%A9"; @@ -52,7 +54,7 @@ my %urls = ( }, content => $pageindex, }, - "/hello_${ccedilla_l15_pct}${eacute_u8_pct}.html" => { + "/hello_${ccedilla_u8_pct}${eacute_u8_pct}.html" => { code => "200", msg => "Ok", headers => { @@ -70,19 +72,17 @@ my %expected_downloaded_files = ( 'index.html' => { content => $pageindex, }, - "hello_${ccedilla_l15}${eacute_u8}.html" => { + "hello_${ccedilla_u8}${eacute_u8}.html" => { content => $pagefrancais, }, ); ############################################################################### -my $the_test = HTTPTest->new (name => "Test-iri-percent", - input => \%urls, +my $the_test = HTTPTest->new (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-iri.px b/tests/Test-iri.px index 4865a1c..eb23b63 100755 --- a/tests/Test-iri.px +++ b/tests/Test-iri.px @@ -42,11 +42,12 @@ my $pageindex = <<EOF; </html> EOF +# specifying a wrong charset in http-equiv - it will be overridden by Content-Type HTTP header my $pagefrancais = <<EOF; <html> <head> <title>La seule page en français</title> - <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <p> @@ -131,18 +132,11 @@ my %urls = ( content => "", }, '/p1_fran%C3%A7ais.html' => { # UTF-8 encoded - code => "404", - msg => "File not found", - headers => { - "Content-type" => "text/html; charset=UTF-8", - }, - content => $page404, - }, - '/p1_fran%E7ais.html' => { code => "200", msg => "Ok", headers => { - "Content-type" => "text/html; charset=UTF-8", + # Content-Type header overrides http-equiv Content-Type + "Content-type" => "text/html; charset=ISO-8859-15", }, content => $pagefrancais, }, @@ -150,10 +144,10 @@ my %urls = ( code => "200", msg => "Ok", request_headers => { - "Referer" => qr|http://localhost:[0-9]+/p1_fran%E7ais.html|, + "Referer" => qr|http://localhost:[0-9]+/p1_fran%C3%A7ais.html|, }, headers => { - "Content-type" => "text/html; charset=ISO-8859-1", + "Content-type" => "text/html; charset=UTF-8", }, content => $pageeen, }, @@ -165,14 +159,6 @@ my %urls = ( }, content => $pageeuro, }, - '/p3_%A4%A4%A4.html' => { - code => "200", - msg => "Ok", - headers => { - "Content-type" => "text/plain; charset=ISO-8859-1", - }, - content => $pageeuro, - }, '/p4_m%C3%A9%C3%A9r.html' => { code => "200", msg => "Ok", @@ -197,7 +183,7 @@ my %expected_downloaded_files = ( 'robots.txt' => { content => "", }, - "p1_fran${ccedilla_l15}ais.html" => { + "p1_fran${ccedilla_u8}ais.html" => { content => $pagefrancais, }, "p2_${eacute_u8}${eacute_u8}n.html" => { @@ -213,12 +199,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-iri", - input => \%urls, +my $the_test = HTTPTest->new (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-k.px b/tests/Test-k.px index c853610..1258e14 100755 --- a/tests/Test-k.px +++ b/tests/Test-k.px @@ -76,12 +76,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-k", - input => \%urls, +my $the_test = HTTPTest->new (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-meta-robots.px b/tests/Test-meta-robots.px index 10db455..4a90338 100755 --- a/tests/Test-meta-robots.px +++ b/tests/Test-meta-robots.px @@ -104,12 +104,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-meta-robots", - input => \%urls, +my $the_test = HTTPTest->new (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-nonexisting-quiet.px b/tests/Test-nonexisting-quiet.px index 62ee241..9f68081 100755 --- a/tests/Test-nonexisting-quiet.px +++ b/tests/Test-nonexisting-quiet.px @@ -33,12 +33,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-nonexisting-quiet", - input => \%urls, +my $the_test = HTTPTest->new (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-noop.px b/tests/Test-noop.px index e2ebc35..d08cbcd 100755 --- a/tests/Test-noop.px +++ b/tests/Test-noop.px @@ -46,12 +46,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-noop", - input => \%urls, +my $the_test = HTTPTest->new (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-np.px b/tests/Test-np.px index 4afc27c..1253c5d 100755 --- a/tests/Test-np.px +++ b/tests/Test-np.px @@ -138,12 +138,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-np", - input => \%urls, +my $the_test = HTTPTest->new (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-proxied-https-auth-keepalive.px b/tests/Test-proxied-https-auth-keepalive.px new file mode 100755 index 0000000..349778a --- /dev/null +++ b/tests/Test-proxied-https-auth-keepalive.px @@ -0,0 +1,163 @@ +#!/usr/bin/env perl +# Simulate a tunneling proxy to a HTTPS URL that needs authentication. +# Use a persistent connection (Connection: keep-alive) + +use strict; +use warnings; + +use WgetFeature qw(https); +use WgetTests; # For $WGETPATH. + +my $cert_path; +my $key_path; +my $srcdir; + +if (@ARGV) { + $srcdir = shift @ARGV; +} elsif (defined $ENV{srcdir}) { + $srcdir = $ENV{srcdir}; +} + +if (defined $srcdir) { + $key_path = "$srcdir/certs/server-key.pem"; + $cert_path = "$srcdir/certs/server-cert.pem"; +} else { + $key_path = "certs/server-key.pem"; + $cert_path = "certs/server-cert.pem"; +} + + +use HTTP::Daemon; +use HTTP::Request; +use IO::Socket::SSL; + +my $SOCKET = HTTP::Daemon->new (LocalAddr => 'localhost', + ReuseAddr => 1) or die "Cannot create server!!!"; + +sub get_request { + my $conn = shift; + my $content = ''; + my $line; + + while (defined ($line = <$conn>)) { + $content .= $line; + last if $line eq "\r\n"; + } + + my $rqst = HTTP::Request->parse($content) + or die "Couldn't parse request:\n$content\n"; + + return $rqst; +} + +sub do_server { + my ($synch_callback) = @_; + my $s = $SOCKET; + my $conn; + my $rqst; + my $rspn; + + # sync with the parent + $synch_callback->(); + + # Simulate a HTTPS proxy server with tunneling. + + $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); + + # Now switch from plain to SSL (for simulating a transparent tunnel + # to an HTTPS server). + + 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"; + + 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"; + + unless ($expect_inner_auth) { + die "Early proxied auth\n" if $rqst->header('Authorization'); + + $rspn = HTTP::Response->new(401, 'Unauthorized', [ + 'WWW-Authenticate' => 'Basic realm="gondor"', + Connection => 'keep-alive' + ]); + } else { + die "No proxied auth\n" unless $rqst->header('Authorization'); + + $rspn = HTTP::Response->new(200, 'OK', [ + 'Content-Type' => 'text/plain', + 'Connection' => 'close', + ], "foobarbaz\n"); + } + + $rspn->protocol('HTTP/1.0'); + print STDERR "=====\n"; + print STDERR $rspn->as_string; + print STDERR "\n=====\n"; + print $conn $rspn->as_string; + } + + $conn->close; + undef $conn; + undef $s; +} + +sub fork_server { + pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!"; + select((select(TO_PARENT), $| = 1)[0]); + + my $pid = fork(); + if ($pid < 0) { + die "Cannot fork"; + } elsif ($pid == 0) { + # child + close FROM_CHILD; + do_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT }); + exit 0; + } else { + # parent + close TO_PARENT; + chomp(my $line = <FROM_CHILD>); + close FROM_CHILD; + } + + return $pid; +} + +unlink "needs-auth.txt"; +my $pid = &fork_server; + +my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee" + . " --password=Dodgson -e https_proxy=localhost:{{port}}" + . " --no-check-certificate" + . " https://no.such.domain/needs-auth.txt"; +$cmdline =~ s/{{port}}/$SOCKET->sockport()/e; + +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-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; +kill ('TERM', $pid); +exit ($code != 0); diff --git a/tests/Test-proxied-https-auth.px b/tests/Test-proxied-https-auth.px index 1de5357..d2c710a 100755 --- a/tests/Test-proxied-https-auth.px +++ b/tests/Test-proxied-https-auth.px @@ -1,20 +1,32 @@ #!/usr/bin/env perl +# Simulate a tunneling proxy to a HTTPS URL that needs authentication. +# Use two connections (Connection: close) use strict; use warnings; use WgetFeature qw(https); -use WgetTest; # For $WGETPATH. +use WgetTests; # For $WGETPATH. my $cert_path; my $key_path; +my $srcdir; if (@ARGV) { - my $top_srcdir = shift @ARGV; - $key_path = "$top_srcdir/tests/certs/server-key.pem"; - $cert_path = "$top_srcdir/tests/certs/server-cert.pem"; + $srcdir = shift @ARGV; +} elsif (defined $ENV{srcdir}) { + $srcdir = $ENV{srcdir}; } +if (defined $srcdir) { + $key_path = "$srcdir/certs/server-key.pem"; + $cert_path = "$srcdir/certs/server-cert.pem"; +} else { + $key_path = "certs/server-key.pem"; + $cert_path = "certs/server-cert.pem"; +} + + use HTTP::Daemon; use HTTP::Request; use IO::Socket::SSL; @@ -39,31 +51,33 @@ sub get_request { } sub do_server { - my $alrm = alarm 10; - + my ($synch_callback) = @_; my $s = $SOCKET; my $conn; my $rqst; 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->(); + + # Simulate a HTTPS proxy server with tunneling. + 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); - 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; + # Now switch from plain to SSL (for simulating a transparent tunnel + # to an HTTPS server). $conn = IO::Socket::SSL->new_from_fd($conn->fileno, @options) or die "Couldn't initiate SSL"; @@ -74,14 +88,10 @@ sub do_server { unless ($expect_inner_auth) { die "Early proxied auth\n" if $rqst->header('Authorization'); - # TODO: handle non-persistent connection here. $rspn = HTTP::Response->new(401, 'Unauthorized', [ 'WWW-Authenticate' => 'Basic realm="gondor"', Connection => 'close' ]); - $rspn->protocol('HTTP/1.0'); - print $rspn->as_string; - print $conn $rspn->as_string; } else { die "No proxied auth\n" unless $rqst->header('Authorization'); @@ -89,41 +99,64 @@ sub do_server { 'Content-Type' => 'text/plain', 'Connection' => 'close', ], "foobarbaz\n"); - $rspn->protocol('HTTP/1.0'); - print "=====\n"; - print $rspn->as_string; - print "\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; } + undef $conn; undef $s; - alarm $alrm; } sub fork_server { - my $pid = fork; - die "Couldn't fork" if ($pid < 0); - return $pid if $pid; + pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!"; + select((select(TO_PARENT), $| = 1)[0]); + + my $pid = fork(); + if ($pid < 0) { + die "Cannot fork"; + } elsif ($pid == 0) { + # child + close FROM_CHILD; + do_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT }); + exit 0; + } else { + # parent + close TO_PARENT; + chomp(my $line = <FROM_CHILD>); + close FROM_CHILD; + } - &do_server; - exit; + return $pid; } -system ('rm -f needs-auth.txt'); +unlink "needs-auth.txt"; my $pid = &fork_server; -sleep 1; my $cmdline = $WgetTest::WGETPATH . " --user=fiddle-dee-dee" . " --password=Dodgson -e https_proxy=localhost:{{port}}" . " --no-check-certificate" . " 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-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; kill ('TERM', $pid); -exit ($code >> 8); +exit ($code != 0); diff --git a/tests/Test-proxy-auth-basic.px b/tests/Test-proxy-auth-basic.px index f437678..4c2dee8 100755 --- a/tests/Test-proxy-auth-basic.px +++ b/tests/Test-proxy-auth-basic.px @@ -38,12 +38,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-auth-basic", - input => \%urls, +my $the_test = HTTPTest->new (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-restrict-ascii.px b/tests/Test-restrict-ascii.px index 48abc57..ecde384 100755 --- a/tests/Test-restrict-ascii.px +++ b/tests/Test-restrict-ascii.px @@ -58,12 +58,10 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-restrict-ascii", - input => \%urls, +my $the_test = HTTPTest->new (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-stdouterr.px b/tests/Test-stdouterr.px index d594ead..7bcfed9 100755 --- a/tests/Test-stdouterr.px +++ b/tests/Test-stdouterr.px @@ -21,7 +21,7 @@ my %urls = ( ); unless(-e "/dev/full") { - exit(2); # skip + exit 77; # skip } my $cmdline = $WgetTest::WGETPATH . " -c http://localhost:{{port}}/somefile.txt -O /dev/full"; @@ -36,8 +36,7 @@ my %expected_downloaded_files = ( ############################################################################### -my $the_test = HTTPTest->new (name => "Test-stdouterr", - input => \%urls, +my $the_test = HTTPTest->new (input => \%urls, cmdline => $cmdline, errcode => $expected_error_code, existing => \%existing_files, @@ -45,4 +44,3 @@ my $the_test = HTTPTest->new (name => "Test-stdouterr", exit $the_test->run(); # vim: et ts=4 sw=4 - diff --git a/tests/WgetFeature.pm b/tests/WgetFeature.pm index f58b998..28e0c11 100644 --- a/tests/WgetFeature.pm +++ b/tests/WgetFeature.pm @@ -3,26 +3,41 @@ package WgetFeature; use strict; use warnings; -use WgetTest; +our $VERSION = 0.01; -our %skip_messages; -require 'WgetFeature.cfg'; +use Carp; +use English qw(-no_match_vars); +use FindBin; +use WgetTests; + +our %SKIP_MESSAGES; +{ + my $cfgfile = "$FindBin::Bin/WgetFeature.cfg"; + open my $fh, '<', $cfgfile + or croak "Cannot open '$cfgfile': $ERRNO"; + my @lines = <$fh>; + close $fh or carp "Cannot close '$cfgfile': $ERRNO"; + my $evalstr = join q{}, @lines; + eval { $evalstr } or carp "Cannot eval '$cfgfile': $ERRNO"; +} sub import { my ($class, $feature) = @_; my $output = `$WgetTest::WGETPATH --version`; - my ($list) = $output =~ /^([\+\-]\S+(?:\s+[\+\-]\S+)+)/m; - my %have_features = map { - my $feature = $_; - $feature =~ s/^.//; - ($feature, /^\+/ ? 1 : 0); - } split /\s+/, $list; - - unless ($have_features{$feature}) { - print $skip_messages{$feature}, "\n"; - exit 2; # skip + my ($list) = $output =~ m/^([+-]\S+(?:\s+[+-]\S+)+)/msx; + my %have_features; + for my $f (split m/\s+/msx, $list) + { + my $feat = $f; + $feat =~ s/^.//msx; + $have_features{$feat} = $f =~ m/^[+]/msx ? 1 : 0; + } + if (!$have_features{$feature}) + { + print "$SKIP_MESSAGES{$feature}\n"; + exit 77; # skip } } diff --git a/tests/WgetTest.pm.in b/tests/WgetTest.pm.in deleted file mode 100644 index 58ad140..0000000 --- a/tests/WgetTest.pm.in +++ /dev/null @@ -1,321 +0,0 @@ -# WARNING! -# WgetTest.pm is a generated file! Do not edit! Edit WgetTest.pm.in -# instead. - -package WgetTest; -$VERSION = 0.01; - -use strict; -use warnings; - -use Cwd; -use File::Path; - -our $WGETPATH = "@abs_top_builddir@/src/wget"; - -my @unexpected_downloads = (); - -{ - my %_attr_data = ( # DEFAULT - _cmdline => "", - _workdir => Cwd::getcwd(), - _errcode => 0, - _existing => {}, - _input => {}, - _name => "", - _output => {}, - _server_behavior => {}, - ); - - sub _default_for - { - my ($self, $attr) = @_; - $_attr_data{$attr}; - } - - sub _standard_keys - { - keys %_attr_data; - } -} - - -sub new { - my ($caller, %args) = @_; - my $caller_is_obj = ref($caller); - my $class = $caller_is_obj || $caller; - #print STDERR "class = ", $class, "\n"; - #print STDERR "_attr_data {workdir} = ", $WgetTest::_attr_data{_workdir}, "\n"; - my $self = bless {}, $class; - foreach my $attrname ($self->_standard_keys()) { - #print STDERR "attrname = ", $attrname, " value = "; - my ($argname) = ($attrname =~ /^_(.*)/); - if (exists $args{$argname}) { - #printf STDERR "Setting up $attrname\n"; - $self->{$attrname} = $args{$argname}; - } elsif ($caller_is_obj) { - #printf STDERR "Copying $attrname\n"; - $self->{$attrname} = $caller->{$attrname}; - } else { - #printf STDERR "Using default for $attrname\n"; - $self->{$attrname} = $self->_default_for($attrname); - } - #print STDERR $attrname, '=', $self->{$attrname}, "\n"; - } - #printf STDERR "_workdir default = ", $self->_default_for("_workdir"); - return $self; -} - - -sub run { - my $self = shift; - my $result_message = "Test successful.\n"; - my $errcode; - - printf "Running test $self->{_name}\n"; - - # Setup - my $new_result = $self->_setup(); - chdir ("$self->{_workdir}/$self->{_name}/input"); - if (defined $new_result) { - $result_message = $new_result; - $errcode = 1; - goto cleanup; - } - - # Launch server - my $pid = $self->_fork_and_launch_server(); - - # Call wget - chdir ("$self->{_workdir}/$self->{_name}/output"); - my $cmdline = $self->{_cmdline}; - $cmdline = $self->_substitute_port($cmdline); - print "Calling $cmdline\n"; - $errcode = - ($cmdline =~ m{^/.*}) - ? system ($cmdline) - : system ("$self->{_workdir}/../src/$cmdline"); - $errcode >>= 8; # XXX: should handle abnormal error codes. - - # Shutdown server - # if we didn't explicitely kill the server, we would have to call - # waitpid ($pid, 0) here in order to wait for the child process to - # terminate - kill ('TERM', $pid); - - # Verify download - unless ($errcode == $self->{_errcode}) { - $result_message = "Test failed: wrong code returned (was: $errcode, expected: $self->{_errcode})\n"; - goto cleanup; - } - my $error_str; - if ($error_str = $self->_verify_download()) { - $result_message = $error_str; - } - - cleanup: - $self->_cleanup(); - - print $result_message; - return $errcode != $self->{_errcode} || ($error_str ? 1 : 0); -} - - -sub _setup { - my $self = shift; - - #print $self->{_name}, "\n"; - chdir ($self->{_workdir}); - - # Create temporary directory - mkdir ($self->{_name}); - chdir ($self->{_name}); - mkdir ("input"); - mkdir ("output"); - - # Setup existing files - chdir ("output"); - foreach my $filename (keys %{$self->{_existing}}) { - open (FILE, ">$filename") - or return "Test failed: cannot open pre-existing file $filename\n"; - - my $file = $self->{_existing}->{$filename}; - print FILE $file->{content} - or return "Test failed: cannot write pre-existing file $filename\n"; - - close (FILE); - - if (exists($file->{timestamp})) { - utime $file->{timestamp}, $file->{timestamp}, $filename - or return "Test failed: cannot set timestamp on pre-existing file $filename\n"; - } - } - - chdir ("../input"); - $self->_setup_server(); - - chdir ($self->{_workdir}); - return; -} - - -sub _cleanup { - my $self = shift; - - chdir ($self->{_workdir}); - File::Path::rmtree ($self->{_name}) unless $ENV{WGET_TEST_NO_CLEANUP}; -} - -# not a method -sub quotechar { - my $c = ord( shift ); - if ($c >= 0x7 && $c <= 0xD) { - return '\\' . qw(a b t n v f r)[$c - 0x7]; - } else { - return sprintf('\\x%02x', $c); - } -} - -# not a method -sub _show_diff { - my $SNIPPET_SIZE = 10; - - my ($expected, $actual) = @_; - - my $str = ''; - my $explen = length $expected; - my $actlen = length $actual; - - if ($explen != $actlen) { - $str .= "Sizes don't match: expected = $explen, actual = $actlen\n"; - } - - my $min = $explen <= $actlen? $explen : $actlen; - my $line = 1; - my $col = 1; - my $i; - for ($i=0; $i != $min; ++$i) { - last if substr($expected, $i, 1) ne substr($actual, $i, 1); - if (substr($expected, $i, 1) eq '\n') { - $line++; - $col = 0; - } else { - $col++; - } - } - my $snip_start = $i - ($SNIPPET_SIZE / 2); - if ($snip_start < 0) { - $SNIPPET_SIZE += $snip_start; # Take it from the end. - $snip_start = 0; - } - my $exp_snip = substr($expected, $snip_start, $SNIPPET_SIZE); - my $act_snip = substr($actual, $snip_start, $SNIPPET_SIZE); - $exp_snip =~s/[^[:print:]]/ quotechar($&) /ge; - $act_snip =~s/[^[:print:]]/ quotechar($&) /ge; - $str .= "Mismatch at line $line, col $col:\n"; - $str .= " $exp_snip\n"; - $str .= " $act_snip\n"; - - return $str; -} - -sub _verify_download { - my $self = shift; - - chdir ("$self->{_workdir}/$self->{_name}/output"); - - # use slurp mode to read file content - my $old_input_record_separator = $/; - undef $/; - - while (my ($filename, $filedata) = each %{$self->{_output}}) { - open (FILE, $filename) - or return "Test failed: file $filename not downloaded\n"; - - my $content = <FILE>; - my $expected_content = $filedata->{'content'}; - $expected_content = $self->_substitute_port($expected_content); - unless ($content eq $expected_content) { - return "Test failed: wrong content for file $filename\n" - . _show_diff($expected_content, $content); - } - - if (exists($filedata->{'timestamp'})) { - my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, - $atime, $mtime, $ctime, $blksize, $blocks) = stat FILE; - - $mtime == $filedata->{'timestamp'} - or return "Test failed: wrong timestamp for file $filename\n"; - } - - close (FILE); - } - - $/ = $old_input_record_separator; - - # make sure no unexpected files were downloaded - chdir ("$self->{_workdir}/$self->{_name}/output"); - - __dir_walk('.', sub { push @unexpected_downloads, $_[0] unless (exists $self->{_output}{$_[0]}) }, sub { shift; return @_ } ); - if (@unexpected_downloads) { - return "Test failed: unexpected downloaded files [" . join(', ', @unexpected_downloads) . "]\n"; - } - - return ""; -} - - -sub __dir_walk { - my ($top, $filefunc, $dirfunc) = @_; - - my $DIR; - - if (-d $top) { - my $file; - unless (opendir $DIR, $top) { - warn "Couldn't open directory $DIR: $!; skipping.\n"; - return; - } - - my @results; - while ($file = readdir $DIR) { - next if $file eq '.' || $file eq '..'; - my $nextdir = $top eq '.' ? $file : "$top/$file"; - push @results, __dir_walk($nextdir, $filefunc, $dirfunc); - } - - return $dirfunc ? $dirfunc->($top, @results) : () ; - } else { - return $filefunc ? $filefunc->($top) : () ; - } -} - - -sub _fork_and_launch_server -{ - my $self = shift; - - pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!"; - select((select(TO_PARENT), $| = 1)[0]); - - my $pid = fork(); - if ($pid < 0) { - die "Cannot fork"; - } elsif ($pid == 0) { - # child - close FROM_CHILD; - $self->_launch_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT }); - } else { - # father - close TO_PARENT; - chomp(my $line = <FROM_CHILD>); - close FROM_CHILD; - } - - return $pid; -} - -1; - -# vim: et ts=4 sw=4 - diff --git a/tests/WgetTests.pm b/tests/WgetTests.pm new file mode 100644 index 0000000..889a65b --- /dev/null +++ b/tests/WgetTests.pm @@ -0,0 +1,423 @@ +package WgetTest; + +use strict; +use warnings; + +our $VERSION = 0.01; + +use Carp; +use Cwd; +use English qw(-no_match_vars); +use File::Path; +use IO::Handle; +use POSIX qw(locale_h); +use locale; + +our $WGETPATH = '../src/wget'; + +my @unexpected_downloads = (); + +{ + my %_attr_data = ( # DEFAULT + _cmdline => q{}, + _workdir => Cwd::getcwd(), + _errcode => 0, + _existing => {}, + _input => {}, + _name => $PROGRAM_NAME, + _output => {}, + _server_behavior => {}, + ); + + sub _default_for + { + my ($self, $attr) = @_; + return $_attr_data{$attr}; + } + + sub _standard_keys + { + return keys %_attr_data; + } +} + +sub new +{ + my ($caller, %args) = @_; + my $caller_is_obj = ref $caller; + my $class = $caller_is_obj || $caller; + + #print STDERR "class = ", $class, "\n"; + #print STDERR "_attr_data {workdir} = ", $WgetTest::_attr_data{_workdir}, "\n"; + my $self = bless {}, $class; + for my $attrname ($self->_standard_keys()) + { + + #print STDERR "attrname = ", $attrname, " value = "; + my ($argname) = ($attrname =~ m/^_(.*)/msx); + if (exists $args{$argname}) + { + + #printf STDERR "Setting up $attrname\n"; + $self->{$attrname} = $args{$argname}; + } + elsif ($caller_is_obj) + { + + #printf STDERR "Copying $attrname\n"; + $self->{$attrname} = $caller->{$attrname}; + } + else + { + #printf STDERR "Using default for $attrname\n"; + $self->{$attrname} = $self->_default_for($attrname); + } + + #print STDERR $attrname, '=', $self->{$attrname}, "\n"; + } + + #printf STDERR "_workdir default = ", $self->_default_for("_workdir"); + return $self; +} + +sub run +{ + my $self = shift; + my $result_message = "Test successful.\n"; + my $errcode; + + $self->{_name} =~ s{.*/}{}msx; # remove path + $self->{_name} =~ s{[.][^.]+$}{}msx; # remove extension + printf "Running test $self->{_name}\n"; + + # Setup + my $new_result = $self->_setup(); + chdir "$self->{_workdir}/$self->{_name}/input" + or carp "Could not chdir to input directory: $ERRNO"; + if (defined $new_result) + { + $result_message = $new_result; + $errcode = 1; + goto cleanup; + } + + # Launch server + my $pid = $self->_fork_and_launch_server(); + + # Call wget + chdir "$self->{_workdir}/$self->{_name}/output" + or carp "Could not chdir to output directory: $ERRNO"; + + my $cmdline = $self->{_cmdline}; + $cmdline = $self->_substitute_port($cmdline); + $cmdline = + ($cmdline =~ m{^/.*}msx) ? $cmdline : "$self->{_workdir}/$cmdline"; + + my $valgrind = $ENV{VALGRIND_TESTS}; + if (!defined $valgrind || $valgrind eq q{} || $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"; + } + + print "Calling $cmdline\n"; + $errcode = system $cmdline; + $errcode >>= 8; # XXX: should handle abnormal error codes. + + # Shutdown server + # if we didn't explicitely kill the server, we would have to call + # waitpid ($pid, 0) here in order to wait for the child process to + # terminate + kill 'TERM', $pid; + + # Verify download + if ($errcode != $self->{_errcode}) + { + $result_message = + "Test failed: wrong code returned (was: $errcode, expected: $self->{_errcode})\n"; + goto CLEANUP; + } + my $error_str; + if ($error_str = $self->_verify_download()) + { + $result_message = $error_str; + } + + CLEANUP: + $self->_cleanup(); + + print $result_message; + return $errcode != $self->{_errcode} || ($error_str ? 1 : 0); +} + +sub _setup +{ + my $self = shift; + + chdir $self->{_workdir} + or carp "Could not chdir into $self->{_workdir}: $ERRNO"; + + # Create temporary directory + mkdir $self->{_name} or carp "Could not mkdir '$self->{_name}': $ERRNO"; + chdir $self->{_name} + or carp "Could not chdir into '$self->{_name}': $ERRNO"; + mkdir 'input' or carp "Could not mkdir 'input' $ERRNO"; + mkdir 'output' or carp "Could not mkdir 'output': $ERRNO"; + + # Setup existing files + chdir 'output' or carp "Could not chdir into 'output': $ERRNO"; + for my $filename (keys %{$self->{_existing}}) + { + open my $fh, '>', $filename + or return "Test failed: cannot open pre-existing file $filename\n"; + + my $file = $self->{_existing}->{$filename}; + print {$fh} $file->{content} + or return "Test failed: cannot write pre-existing file $filename\n"; + + close $fh or carp $ERRNO; + + if (exists($file->{timestamp})) + { + utime $file->{timestamp}, $file->{timestamp}, $filename + or return + "Test failed: cannot set timestamp on pre-existing file $filename\n"; + } + } + + chdir '../input' or carp "Cannot chdir into '../input': $ERRNO"; + $self->_setup_server(); + + chdir $self->{_workdir} + or carp "Cannot chdir into '$self->{_workdir}': $ERRNO"; + return; +} + +sub _cleanup +{ + my $self = shift; + + chdir $self->{_workdir} + or carp "Could not chdir into '$self->{_workdir}': $ERRNO"; + if (!$ENV{WGET_TEST_NO_CLEANUP}) + { + File::Path::rmtree($self->{_name}); + } + return 1; +} + +# not a method +sub quotechar +{ + my $c = ord shift; + if ($c >= 0x7 && $c <= 0xD) + { + return q{\\} . qw(a b t n v f r) [$c - 0x7]; + } + else + { + return sprintf '\\x%02x', $c; + } +} + +# not a method +sub _show_diff +{ + my ($expected, $actual) = @_; + my $SNIPPET_SIZE = 10; + + my $str = q{}; + my $explen = length $expected; + my $actlen = length $actual; + + if ($explen != $actlen) + { + $str .= "Sizes don't match: expected = $explen, actual = $actlen\n"; + } + + my $min = $explen <= $actlen ? $explen : $actlen; + my $line = 1; + my $col = 1; + my $i; + + # for ($i=0; $i != $min; ++$i) { + for my $i (0 .. $min - 1) + { + last if substr($expected, $i, 1) ne substr $actual, $i, 1; + if (substr($expected, $i, 1) eq q{\n}) + { + $line++; + $col = 0; + } + else + { + $col++; + } + } + my $snip_start = $i - ($SNIPPET_SIZE / 2); + if ($snip_start < 0) + { + $SNIPPET_SIZE += $snip_start; # Take it from the end. + $snip_start = 0; + } + my $exp_snip = substr $expected, $snip_start, $SNIPPET_SIZE; + my $act_snip = substr $actual, $snip_start, $SNIPPET_SIZE; + $exp_snip =~ s/[^[:print:]]/ quotechar($&) /gemsx; + $act_snip =~ s/[^[:print:]]/ quotechar($&) /gemsx; + $str .= "Mismatch at line $line, col $col:\n"; + $str .= " $exp_snip\n"; + $str .= " $act_snip\n"; + + return $str; +} + +sub _verify_download +{ + my $self = shift; + + chdir "$self->{_workdir}/$self->{_name}/output" + or carp "Could not chdir into output directory: $ERRNO"; + + # use slurp mode to read file content + my $old_input_record_separator = $INPUT_RECORD_SEPARATOR; + local $INPUT_RECORD_SEPARATOR = undef; + + while (my ($filename, $filedata) = each %{$self->{_output}}) + { + open my $fh, '<', $filename + or return "Test failed: file $filename not downloaded\n"; + + my $content = <$fh>; + + close $fh or carp $ERRNO; + + my $expected_content = $filedata->{'content'}; + $expected_content = $self->_substitute_port($expected_content); + if ($content ne $expected_content) + { + return "Test failed: wrong content for file $filename\n" + . _show_diff($expected_content, $content); + } + + if (exists($filedata->{'timestamp'})) + { + my ( + $dev, $ino, $mode, $nlink, $uid, + $gid, $rdev, $size, $atime, $mtime, + $ctime, $blksize, $blocks + ) + = stat $filename; + + $mtime == $filedata->{'timestamp'} + or return "Test failed: wrong timestamp for file $filename\n"; + } + + } + + local $INPUT_RECORD_SEPARATOR = $old_input_record_separator; + + # make sure no unexpected files were downloaded + chdir "$self->{_workdir}/$self->{_name}/output" + or carp "Could not change into output directory: $ERRNO"; + + __dir_walk( + q{.}, + sub { + if (!(exists $self->{_output}{$_[0]} || $self->{_existing}{$_[0]})) + { + push @unexpected_downloads, $_[0]; + } + }, + sub { shift; return @_ } + ); + if (@unexpected_downloads) + { + return 'Test failed: unexpected downloaded files [' . join ', ', + @unexpected_downloads . "]\n"; + } + + return q{}; +} + +sub __dir_walk +{ + my ($top, $filefunc, $dirfunc) = @_; + + my $DIR; + + if (-d $top) + { + my $file; + if (!opendir $DIR, $top) + { + warn "Couldn't open directory $DIR: $ERRNO; skipping.\n"; + return; + } + + my @results; + while ($file = readdir $DIR) + { + next if $file eq q{.} || $file eq q{..}; + my $nextdir = $top eq q{.} ? $file : "$top/$file"; + push @results, __dir_walk($nextdir, $filefunc, $dirfunc); + } + + return $dirfunc ? $dirfunc->($top, @results) : (); + } + else + { + return $filefunc ? $filefunc->($top) : (); + } +} + +sub _fork_and_launch_server +{ + my $self = shift; + + pipe FROM_CHILD, TO_PARENT or croak 'Cannot create pipe!'; + TO_PARENT->autoflush(); + + my $pid = fork; + if ($pid < 0) + { + carp 'Cannot fork'; + } + elsif ($pid == 0) + { + + # child + close FROM_CHILD or carp $ERRNO; + + # FTP Server has to start with english locale due to use of strftime month names in LIST command + setlocale(LC_ALL, 'C'); + $self->_launch_server( + sub { + print {*TO_PARENT} "SYNC\n"; + close TO_PARENT or carp $ERRNO; + } + ); + } + else + { + # father + close TO_PARENT or carp $ERRNO; + chomp(my $line = <FROM_CHILD>); + close FROM_CHILD or carp $ERRNO; + } + + return $pid; +} + +1; + +# vim: et ts=4 sw=4 diff --git a/tests/run-px b/tests/run-px deleted file mode 100755 index a3f61bb..0000000 --- a/tests/run-px +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/env perl - -use 5.006; -use strict; -use warnings; - -use Term::ANSIColor; - -die "Please specify the top source directory.\n" if (!@ARGV); -my $top_srcdir = shift @ARGV; - -my @tests = ( - 'Test-auth-basic.px', - 'Test-auth-no-challenge.px', - 'Test-auth-no-challenge-url.px', - 'Test-auth-with-content-disposition.px', - 'Test-auth-retcode.px', - 'Test-cookies.px', - 'Test-cookies-401.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-shorter.px', - 'Test-c.px', - 'Test-E-k-K.px', - 'Test-E-k.px', - 'Test-ftp.px', - 'Test-ftp-pasv-fail.px', - 'Test-ftp-bad-list.px', - 'Test-ftp-recursive.px', - 'Test-ftp-iri.px', - 'Test-ftp-iri-fallback.px', - 'Test-ftp-iri-recursive.px', - 'Test-ftp-iri-disabled.px', - 'Test-ftp-list-Multinet.px', - 'Test-ftp-list-Unknown.px', - 'Test-ftp-list-Unknown-a.px', - 'Test-ftp-list-Unknown-hidden.px', - 'Test-ftp-list-Unknown-list-a-fails.px', - 'Test-ftp-list-UNIX-hidden.px', - 'Test-HTTP-Content-Disposition-1.px', - 'Test-HTTP-Content-Disposition-2.px', - 'Test-HTTP-Content-Disposition.px', - 'Test-i-ftp.px', - 'Test-i-http.px', - 'Test-idn-headers.px', - 'Test-idn-meta.px', - 'Test-idn-cmd.px', - 'Test-idn-cmd-utf8.px', - 'Test-idn-robots.px', - 'Test-idn-robots-utf8.px', - 'Test-iri.px', - 'Test-iri-percent.px', - 'Test-iri-disabled.px', - 'Test-iri-forced-remote.px', - 'Test-iri-list.px', - 'Test-k.px', - 'Test-meta-robots.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--post-file.px', - 'Test-O-nc.px', - 'Test-restrict-ascii.px', - 'Test-Restrict-Lowercase.px', - 'Test-Restrict-Uppercase.px', - 'Test-stdouterr.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', - 'Test--httpsonly-r.px', -); - -foreach my $var (qw(SYSTEM_WGETRC WGETRC)) { - $ENV{$var} = '/dev/null'; -} - -my @tested; - -foreach my $test (@tests) { - print "Running $test\n\n"; - system("$^X -I$top_srcdir/tests $top_srcdir/tests/$test $top_srcdir"); - push @tested, { name => $test, result => $? >> 8 }; -} - -foreach my $var (qw(SYSTEM_WGETRC WGETRC)) { - delete $ENV{$var}; -} - -my %exit = ( - pass => 0, - fail => 1, - skip => 2, - unknown => 3, # or greater -); - -my %colors = ( - $exit{pass} => colored('pass:', 'green' ), - $exit{fail} => colored('FAIL:', 'red' ), - $exit{skip} => colored('Skip:', 'yellow' ), - $exit{unknown} => colored('Unknown:', 'magenta'), -); - -print "\n"; -foreach my $test (@tested) { - my $colored = exists $colors{$test->{result}} - ? $colors{$test->{result}} - : $colors{$exit{unknown}}; - print "$colored $test->{name}\n"; -} - -my $count = sub -{ - return { - pass => sub { scalar grep $_->{result} == $exit{pass}, @tested }, - fail => sub { scalar grep $_->{result} == $exit{fail}, @tested }, - skip => sub { scalar grep $_->{result} == $exit{skip}, @tested }, - unknown => sub { scalar grep $_->{result} >= $exit{unknown}, @tested }, - }->{$_[0]}->(); -}; - -my $summary = sub -{ - my @lines = ( - "${\scalar @tested} tests were run", - "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL", - "${\$count->('skip')} SKIP, ${\$count->('unknown')} UNKNOWN", - ); - my $len_longest = sub - { - local $_ = 0; - foreach my $line (@lines) { - if (length $line > $_) { - $_ = length $line; - } - } - return $_; - }->(); - return join "\n", - '=' x $len_longest, - @lines, - '=' x $len_longest; -}->(); - -print "\n"; -print $count->('fail') || $count->('unknown') - ? colored($summary, 'red') - : colored($summary, 'green'); -print "\n"; - -exit $count->('fail') + $count->('unknown'); |