From 48b85c46f16f04e803e00b0bad42a4fa0295f517 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 16 Nov 2020 17:54:07 +0100 Subject: [PATCH] runtests: add support for gophers, gopher over TLS --- tests/FILEFORMAT.md | 3 +++ tests/runtests.pl | 59 +++++++++++++++++++++++++++++++++++++-------- tests/serverhelp.pm | 2 +- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/tests/FILEFORMAT.md b/tests/FILEFORMAT.md index a91332700..ab6b3f565 100644 --- a/tests/FILEFORMAT.md +++ b/tests/FILEFORMAT.md @@ -117,6 +117,7 @@ Available substitute variables include: - `%FTPTIME3` - Even longer than %FTPTIME2 - `%GOPHER6PORT` - IPv6 port number of the Gopher server - `%GOPHERPORT` - Port number of the Gopher server +- `%GOPHERSPORT` - Port number of the Gophers server - `%HOST6IP` - IPv6 address of the host running this test - `%HOSTIP` - IPv4 address of the host running this test - `%HTTP6PORT` - IPv6 port number of the HTTP server @@ -329,6 +330,8 @@ What server(s) this test case requires/uses. Available servers: - `ftp-ipv6` - `ftp` - `ftps` +- `gopher` +- `gophers` - `http-ipv6` - `http-proxy` - `http-unix` diff --git a/tests/runtests.pl b/tests/runtests.pl index 0858127db..daa0c33a5 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -151,6 +151,7 @@ my $SMTP6PORT=$noport; # SMTP IPv6 server port my $RTSPPORT=$noport; # RTSP my $RTSP6PORT=$noport; # RTSP IPv6 server port my $GOPHERPORT=$noport; # Gopher +my $GOPHERSPORT=$noport; # Gophers my $GOPHER6PORT=$noport; # Gopher IPv6 server port my $HTTPTLSPORT=$noport; # HTTP TLS (non-stunnel) server port my $HTTPTLS6PORT=$noport; # HTTP TLS (non-stunnel) IPv6 server port @@ -417,7 +418,7 @@ delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'}); # possible servers. # sub init_serverpidfile_hash { - for my $proto (('ftp', 'http', 'imap', 'pop3', 'smtp', 'http/2')) { + for my $proto (('ftp', 'gopher', 'http', 'imap', 'pop3', 'smtp', 'http/2')) { for my $ssl (('', 's')) { for my $ipvnum ((4, 6)) { for my $idnum ((1, 2, 3)) { @@ -430,7 +431,7 @@ sub init_serverpidfile_hash { } } } - for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'gopher', 'httptls', + for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'httptls', 'dict', 'smb', 'smbs', 'telnet', 'mqtt')) { for my $ipvnum ((4, 6)) { for my $idnum ((1, 2)) { @@ -1601,10 +1602,9 @@ sub runhttpserver { # start the https stunnel based server # sub runhttpsserver { - my ($verbose, $ipv6, $proxy, $certfile) = @_; - my $proto = 'https'; - my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP"; - my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4; + my ($verbose, $proto, $proxy, $certfile) = @_; + my $ip = $HOSTIP; + my $ipvnum = 4; my $idnum = 1; my $server; my $srvrname; @@ -1648,7 +1648,10 @@ sub runhttpsserver { $flags .= "--ipv$ipvnum --proto $proto "; $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem'); $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" "; - if(!$proxy) { + if($proto eq "gophers") { + $flags .= "--connect $GOPHERPORT"; + } + elsif(!$proxy) { $flags .= "--connect $HTTPPORT"; } else { @@ -3233,6 +3236,7 @@ sub subVariables { $$thing =~ s/${prefix}FTPPORT/$FTPPORT/g; $$thing =~ s/${prefix}GOPHER6PORT/$GOPHER6PORT/g; $$thing =~ s/${prefix}GOPHERPORT/$GOPHERPORT/g; + $$thing =~ s/${prefix}GOPHERSPORT/$GOPHERSPORT/g; $$thing =~ s/${prefix}HTTPTLS6PORT/$HTTPTLS6PORT/g; $$thing =~ s/${prefix}HTTPTLSPORT/$HTTPTLSPORT/g; $$thing =~ s/${prefix}HTTP6PORT/$HTTP6PORT/g; @@ -4640,7 +4644,7 @@ sub startservers { $what =~ s/[^a-z0-9\/-]//g; my $certfile; - if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) { + if($what =~ /^(ftp|gopher|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) { $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem'; } @@ -4857,7 +4861,7 @@ sub startservers { } if(!$run{'https'}) { ($pid, $pid2, $HTTPSPORT) = - runhttpsserver($verbose, "", "", $certfile); + runhttpsserver($verbose, "https", "", $certfile); if($pid <= 0) { return "failed starting HTTPS server (stunnel)"; } @@ -4866,6 +4870,41 @@ sub startservers { $run{'https'}="$pid $pid2"; } } + elsif($what eq "gophers") { + if(!$stunnel) { + # we can't run TLS tests without stunnel + return "no stunnel"; + } + if($runcert{'gophers'} && ($runcert{'gophers'} ne $certfile)) { + # stop server when running and using a different cert + stopserver('gophers'); + } + if($torture && $run{'gopher'} && + !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) { + stopserver('gopher'); + } + if(!$run{'gopher'}) { + ($pid, $pid2, $GOPHERPORT) = + runhttpserver("gopher", $verbose, 0); + if($pid <= 0) { + return "failed starting GOPHER server"; + } + printf ("* pid gopher => %d %d\n", $pid, $pid2) if($verbose); + print "GOPHERPORT => $GOPHERPORT\n" if($verbose); + $run{'gopher'}="$pid $pid2"; + } + if(!$run{'gophers'}) { + ($pid, $pid2, $GOPHERSPORT) = + runhttpsserver($verbose, "gophers", "", $certfile); + if($pid <= 0) { + return "failed starting GOPHERS server (stunnel)"; + } + logmsg sprintf("* pid gophers => %d %d\n", $pid, $pid2) + if($verbose); + print "GOPHERSPORT => $GOPHERSPORT\n" if($verbose); + $run{'gophers'}="$pid $pid2"; + } + } elsif($what eq "https-proxy") { if(!$stunnel) { # we can't run https-proxy tests without stunnel @@ -4886,7 +4925,7 @@ sub startservers { if(!$run{'https-proxy'}) { ($pid, $pid2, $HTTPSPROXYPORT) = - runhttpsserver($verbose, "", "proxy", $certfile); + runhttpsserver($verbose, "https", "proxy", $certfile); if($pid <= 0) { return "failed starting HTTPS-proxy (stunnel)"; } diff --git a/tests/serverhelp.pm b/tests/serverhelp.pm index 83f783af8..77eceec1a 100644 --- a/tests/serverhelp.pm +++ b/tests/serverhelp.pm @@ -106,7 +106,7 @@ sub servername_str { $proto = uc($proto) if($proto); die "unsupported protocol: '$proto'" unless($proto && - ($proto =~ /^(((FTP|HTTP|HTTP\/2|IMAP|POP3|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|GOPHER|HTTPTLS|DICT|SMB|SMBS|TELNET|MQTT))$/)); + ($proto =~ /^(((FTP|HTTP|HTTP\/2|IMAP|POP3|GOPHER|SMTP|HTTP-PIPE)S?)|(TFTP|SFTP|SOCKS|SSH|RTSP|HTTPTLS|DICT|SMB|SMBS|TELNET|MQTT))$/)); $ipver = (not $ipver) ? 'ipv4' : lc($ipver); die "unsupported IP version: '$ipver'" unless($ipver &&