runtests: move the TELNET server to a dynamic port

Rename the port variable to TELNETPORT to better match the existing
pattern.

Closes #5785
This commit is contained in:
Daniel Stenberg 2020-08-05 15:39:34 +02:00
parent 2754a89362
commit 337a28d810
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
3 changed files with 31 additions and 36 deletions

View File

@ -72,7 +72,7 @@ Available substitute variables include:
- `%IMAP6PORT` - IPv6 port number of the IMAP server - `%IMAP6PORT` - IPv6 port number of the IMAP server
- `%IMAPPORT` - Port number of the IMAP server - `%IMAPPORT` - Port number of the IMAP server
- `%MQTTPORT` - Port number of the MQTT 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 - `%NOLISTENPORT` - Port number where no service is listening
- `%POP36PORT` - IPv6 port number of the POP3 server - `%POP36PORT` - IPv6 port number of the POP3 server
- `%POP3PORT` - Port number of the POP3 server - `%POP3PORT` - Port number of the POP3 server

View File

@ -29,7 +29,7 @@ Basic TELNET negotiation
test1452 test1452
</stdin> </stdin>
<command> <command>
telnet://%HOSTIP:%NEGTELNETPORT --upload-file - telnet://%HOSTIP:%TELNETPORT --upload-file -
</command> </command>
</client> </client>

View File

@ -163,7 +163,7 @@ my $HTTP2PORT=$noport; # HTTP/2 server port
my $DICTPORT=$noport; # DICT server port my $DICTPORT=$noport; # DICT server port
my $SMBPORT=$noport; # SMB server port my $SMBPORT=$noport; # SMB server port
my $SMBSPORT=$noport; # SMBS 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 $HTTPUNIXPATH; # HTTP server Unix domain socket path
my $SSHSRVMD5 = "[uninitialized]"; # MD5 of ssh server public key my $SSHSRVMD5 = "[uninitialized]"; # MD5 of ssh server public key
@ -2552,7 +2552,7 @@ sub runsmbserver {
# start the telnet server # start the telnet server
# #
sub runnegtelnetserver { sub runnegtelnetserver {
my ($verbose, $alt, $port) = @_; my ($verbose, $alt) = @_;
my $proto = "telnet"; my $proto = "telnet";
my $ip = $HOSTIP; my $ip = $HOSTIP;
my $ipvnum = 4; my $ipvnum = 4;
@ -2589,10 +2589,15 @@ sub runnegtelnetserver {
$flags .= "--verbose 1 " if($debugprotocol); $flags .= "--verbose 1 " if($debugprotocol);
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" "; $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
$flags .= "--id $idnum " if($idnum > 1); $flags .= "--id $idnum " if($idnum > 1);
$flags .= "--port $port --srcdir \"$srcdir\""; $flags .= "--srcdir \"$srcdir\"";
my $cmd = "$srcdir/negtelnetserver.py $flags"; my ($ntelpid, $pid2);
my ($ntelpid, $pid2) = startnew($cmd, $pidfile, 15, 0); 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)) { if($ntelpid <= 0 || !pidexists($ntelpid)) {
# it is NOT alive # it is NOT alive
@ -2600,26 +2605,18 @@ sub runnegtelnetserver {
stopserver($server, "$pid2"); stopserver($server, "$pid2");
displaylogs($testnumcheck); displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1; $doesntrun{$pidfile} = 1;
return (0,0); $ntelpid = $pid2 = 0;
next;
} }
$doesntrun{$pidfile} = 0;
# 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) { if($verbose) {
logmsg "RUN: $srvrname server is now running PID $ntelpid\n"; logmsg "RUN: $srvrname server PID $ntelpid port $port\n";
}
last;
} }
return ($ntelpid, $pid2); return ($ntelpid, $pid2, $port);
} }
@ -3281,7 +3278,7 @@ sub subVariables {
$$thing =~ s/${prefix}DICTPORT/$DICTPORT/g; $$thing =~ s/${prefix}DICTPORT/$DICTPORT/g;
$$thing =~ s/${prefix}SMBPORT/$SMBPORT/g; $$thing =~ s/${prefix}SMBPORT/$SMBPORT/g;
$$thing =~ s/${prefix}SMBSPORT/$SMBSPORT/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; $$thing =~ s/${prefix}NOLISTENPORT/$NOLISTENPORT/g;
# server Unix domain socket paths # server Unix domain socket paths
@ -4985,9 +4982,8 @@ sub startservers {
} }
elsif($what eq "telnet") { elsif($what eq "telnet") {
if(!$run{'telnet'}) { if(!$run{'telnet'}) {
($pid, $pid2) = runnegtelnetserver($verbose, ($pid, $pid2, $TELNETPORT) =
"", runnegtelnetserver($verbose, "");
$NEGTELNETPORT);
if($pid <= 0) { if($pid <= 0) {
return "failed starting neg TELNET server"; return "failed starting neg TELNET server";
} }
@ -5490,7 +5486,6 @@ if ($gdbthis) {
$minport = $base; # original base port number $minport = $base; # original base port number
$DICTPORT = $base++; # DICT port $DICTPORT = $base++; # DICT port
$NEGTELNETPORT = $base++; # TELNET port with negotiation
$HTTPUNIXPATH = "http$$.sock"; # HTTP server Unix domain socket path $HTTPUNIXPATH = "http$$.sock"; # HTTP server Unix domain socket path
$maxport = $base-1; # updated base port number $maxport = $base-1; # updated base port number