From 337a28d810e9e3c1803f69a6801004c0c944ba90 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 5 Aug 2020 15:39:34 +0200 Subject: [PATCH] runtests: move the TELNET server to a dynamic port Rename the port variable to TELNETPORT to better match the existing pattern. Closes #5785 --- tests/FILEFORMAT.md | 2 +- tests/data/test1452 | 2 +- tests/runtests.pl | 63 +++++++++++++++++++++------------------------ 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/tests/FILEFORMAT.md b/tests/FILEFORMAT.md index 6f6e71bb7..08dab7052 100644 --- a/tests/FILEFORMAT.md +++ b/tests/FILEFORMAT.md @@ -72,7 +72,7 @@ Available substitute variables include: - `%IMAP6PORT` - IPv6 port number of the IMAP server - `%IMAPPORT` - Port number of the IMAP server - `%MQTTPORT` - Port number of the MQTT server -- `%NEGTELNETPORT` - Port number of the telnet server +- `%TELNETPORT` - Port number of the telnet server - `%NOLISTENPORT` - Port number where no service is listening - `%POP36PORT` - IPv6 port number of the POP3 server - `%POP3PORT` - Port number of the POP3 server diff --git a/tests/data/test1452 b/tests/data/test1452 index 0a84cf8ce..6c76ef84a 100644 --- a/tests/data/test1452 +++ b/tests/data/test1452 @@ -29,7 +29,7 @@ Basic TELNET negotiation test1452 -telnet://%HOSTIP:%NEGTELNETPORT --upload-file - +telnet://%HOSTIP:%TELNETPORT --upload-file - diff --git a/tests/runtests.pl b/tests/runtests.pl index a46997a7b..24ddaeeae 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -163,7 +163,7 @@ my $HTTP2PORT=$noport; # HTTP/2 server port my $DICTPORT=$noport; # DICT server port my $SMBPORT=$noport; # SMB server port my $SMBSPORT=$noport; # SMBS server port -my $NEGTELNETPORT=$noport; # TELNET server port with negotiation +my $TELNETPORT=$noport; # TELNET server port with negotiation my $HTTPUNIXPATH; # HTTP server Unix domain socket path my $SSHSRVMD5 = "[uninitialized]"; # MD5 of ssh server public key @@ -2552,7 +2552,7 @@ sub runsmbserver { # start the telnet server # sub runnegtelnetserver { - my ($verbose, $alt, $port) = @_; + my ($verbose, $alt) = @_; my $proto = "telnet"; my $ip = $HOSTIP; my $ipvnum = 4; @@ -2589,37 +2589,34 @@ sub runnegtelnetserver { $flags .= "--verbose 1 " if($debugprotocol); $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" "; $flags .= "--id $idnum " if($idnum > 1); - $flags .= "--port $port --srcdir \"$srcdir\""; + $flags .= "--srcdir \"$srcdir\""; - my $cmd = "$srcdir/negtelnetserver.py $flags"; - my ($ntelpid, $pid2) = startnew($cmd, $pidfile, 15, 0); + my ($ntelpid, $pid2); + my $port = 32000; + for(1 .. 10) { + $port += int(rand(800)); + my $aflags = "--port $port $flags"; + my $cmd = "$srcdir/negtelnetserver.py $aflags"; + ($ntelpid, $pid2) = startnew($cmd, $pidfile, 15, 0); - if($ntelpid <= 0 || !pidexists($ntelpid)) { - # it is NOT alive - logmsg "RUN: failed to start the $srvrname server\n"; - stopserver($server, "$pid2"); - displaylogs($testnumcheck); - $doesntrun{$pidfile} = 1; - return (0,0); + if($ntelpid <= 0 || !pidexists($ntelpid)) { + # it is NOT alive + logmsg "RUN: failed to start the $srvrname server\n"; + stopserver($server, "$pid2"); + displaylogs($testnumcheck); + $doesntrun{$pidfile} = 1; + $ntelpid = $pid2 = 0; + next; + } + $doesntrun{$pidfile} = 0; + + if($verbose) { + logmsg "RUN: $srvrname server PID $ntelpid port $port\n"; + } + last; } - # Server is up. Verify that we can speak to it. - my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port); - if(!$pid3) { - logmsg "RUN: $srvrname server failed verification\n"; - # failed to talk to it properly. Kill the server and return failure - stopserver($server, "$ntelpid $pid2"); - displaylogs($testnumcheck); - $doesntrun{$pidfile} = 1; - return (0,0); - } - $pid2 = $pid3; - - if($verbose) { - logmsg "RUN: $srvrname server is now running PID $ntelpid\n"; - } - - return ($ntelpid, $pid2); + return ($ntelpid, $pid2, $port); } @@ -3281,7 +3278,7 @@ sub subVariables { $$thing =~ s/${prefix}DICTPORT/$DICTPORT/g; $$thing =~ s/${prefix}SMBPORT/$SMBPORT/g; $$thing =~ s/${prefix}SMBSPORT/$SMBSPORT/g; - $$thing =~ s/${prefix}NEGTELNETPORT/$NEGTELNETPORT/g; + $$thing =~ s/${prefix}TELNETPORT/$TELNETPORT/g; $$thing =~ s/${prefix}NOLISTENPORT/$NOLISTENPORT/g; # server Unix domain socket paths @@ -4985,9 +4982,8 @@ sub startservers { } elsif($what eq "telnet") { if(!$run{'telnet'}) { - ($pid, $pid2) = runnegtelnetserver($verbose, - "", - $NEGTELNETPORT); + ($pid, $pid2, $TELNETPORT) = + runnegtelnetserver($verbose, ""); if($pid <= 0) { return "failed starting neg TELNET server"; } @@ -5490,7 +5486,6 @@ if ($gdbthis) { $minport = $base; # original base port number $DICTPORT = $base++; # DICT port -$NEGTELNETPORT = $base++; # TELNET port with negotiation $HTTPUNIXPATH = "http$$.sock"; # HTTP server Unix domain socket path $maxport = $base-1; # updated base port number