Skip to content
Permalink
Browse files

test: make tests and test scripts use socksd for SOCKS

Make all SOCKS tests use socksd instead of ssh.
  • Loading branch information...
bagder committed Apr 8, 2019
1 parent 04fd675 commit 54c784556e3579c24de9cc79e435e8bbaa4f6c81
Showing with 149 additions and 142 deletions.
  1. +1 −1 tests/data/Makefile.inc
  2. +4 −0 tests/data/test702
  3. +4 −0 tests/data/test703
  4. +1 −2 tests/data/test711
  5. +44 −0 tests/data/test716
  6. +65 −0 tests/data/test717
  7. +1 −1 tests/getpart.pm
  8. +22 −120 tests/runtests.pl
  9. +7 −18 tests/sshserver.pl
@@ -86,7 +86,7 @@ test643 test644 test645 test646 test647 test648 test649 test650 test651 \
test652 test653 test654 test655 test656 test658 test659 \
\
test700 test701 test702 test703 test704 test705 test706 test707 test708 \
test709 test710 test711 test712 test713 test714 test715 \
test709 test710 test711 test712 test713 test714 test715 test716 test717 \
\
test800 test801 test802 test803 test804 test805 test806 test807 test808 \
test809 test810 test811 test812 test813 test814 test815 test816 test817 \
@@ -12,6 +12,10 @@ FAILURE
<reply>
<data>
</data>
# 91 is socks4 failure
<servercmd>
response 91
</servercmd>
</reply>

# Client-side
@@ -12,6 +12,10 @@ FAILURE
<reply>
<data>
</data>
# 1 is socks5 failure
<servercmd>
response 1
</servercmd>
</reply>

# Client-side
@@ -16,7 +16,6 @@ all_proxy
silly content
</data>
<servercmd>
backendport passthru
</servercmd>
</reply>

@@ -28,7 +27,7 @@ ftp
socks5
</server>
<setenv>
all_proxy=socks5://%HOSTIP:%SOCKSPORT
all_proxy=socks5://%HOSTIP:%SOCKSPORT
</setenv>
<name>
FTP fetch with all_proxy set to socks5
@@ -0,0 +1,44 @@
<testcase>
<info>
<keywords>
HTTP
SOCKS5
all_proxy
</keywords>
</info>
#
# Server-side
<reply>
# method 2 is SOCKS5 asking for user+password
<servercmd>
method 2
</servercmd>
</reply>

#
# Client-side
<client>
<server>
socks5
</server>
<features>
http
</features>
<name>
SOCKS5 proxy with too long user name
</name>

# it should never connect to the target server
<command>
http://hohoho.example.com:99/716 -x socks5://AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:b@%HOSTIP:%SOCKSPORT
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>
<errorcode>
43
</errorcode>
</verify>
</testcase>
@@ -0,0 +1,65 @@
<testcase>
<info>
<keywords>
HTTP
SOCKS5
all_proxy
</keywords>
</info>
#
# Server-side
<reply>
<data>
HTTP/1.1 200 OK
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
ETag: "21025-dc7-39462498"
Accept-Ranges: bytes
Content-Length: 6
Connection: close
Content-Type: text/html
Funny-head: yesyes

-foo-
</data>
# method 2 is SOCKS5 asking for user+password
<servercmd>
method 2
user uz3r
password p4ssworm
backendport %HTTPPORT
</servercmd>
</reply>

#
# Client-side
<client>
<server>
socks5
http
</server>
<name>
SOCKS5 proxy auth
</name>

# target a port that won't work without the SOCKS magic
<command>
http://%HOSTIP:1/717 -x socks5://uz3r:p4ssworm@%HOSTIP:%SOCKSPORT
</command>
</client>

#
# Verify data after the test has been "shot"
<verify>
<strip>
^User-Agent:.*
</strip>
<protocol>
GET /717 HTTP/1.1
Host: %HOSTIP:1
Accept: */*

</protocol>
</verify>
</testcase>
@@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
# Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
@@ -276,7 +276,7 @@ BEGIN
my $sshdverstr; # for socks server, ssh daemon version string
my $sshderror; # for socks server, ssh daemon version error

my $defserverlogslocktimeout = 20; # timeout to await server logs lock removal
my $defserverlogslocktimeout = 2; # timeout to await server logs lock removal
my $defpostcommanddelay = 0; # delay between command and postcheck sections

my $timestats; # time stamping and stats generation
@@ -2012,7 +2012,6 @@ sub runsshserver {
my ($id, $verbose, $ipv6) = @_;
my $ip=$HOSTIP;
my $port = $SSHPORT;
my $socksport = $SOCKSPORT;
my $proto = 'ssh';
my $ipvnum = 4;
my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
@@ -2046,7 +2045,7 @@ sub runsshserver {
$flags .= "--pidfile \"$pidfile\" ";
$flags .= "--id $idnum " if($idnum > 1);
$flags .= "--ipv$ipvnum --addr \"$ip\" ";
$flags .= "--sshport $port --socksport $socksport ";
$flags .= "--sshport $port ";
$flags .= "--user \"$USER\"";

my $cmd = "$perl $srcdir/sshserver.pl $flags";
@@ -2139,108 +2138,27 @@ sub runsocksserver {

$logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);

# The ssh server must be already running
if(!$run{'ssh'}) {
logmsg "RUN: SOCKS server cannot find running SSH server\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}

# Find out ssh daemon canonical file name
my $sshd = find_sshd();
if(!$sshd) {
logmsg "RUN: SOCKS server cannot find $sshdexe\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}

# Find out ssh daemon version info
($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
if(!$sshdid) {
# Not an OpenSSH or SunSSH ssh daemon
logmsg "$sshderror\n" if($verbose);
logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}
logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);

# Find out ssh client canonical file name
my $ssh = find_ssh();
if(!$ssh) {
logmsg "RUN: SOCKS server cannot find $sshexe\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}

# Find out ssh client version info
my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
if(!$sshid) {
# Not an OpenSSH or SunSSH ssh client
logmsg "$ssherror\n" if($verbose);
logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}

# Verify minimum ssh client version
if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
(($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
logmsg "ssh client found $ssh is $sshverstr\n";
logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}
logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);

# Verify if ssh client and ssh daemon versions match
if(($sshdid ne $sshid) || ($sshdvernum != $sshvernum)) {
# Our test harness might work with slightly mismatched versions
logmsg "Warning: version mismatch: sshd $sshdverstr - ssh $sshverstr\n"
if($verbose);
}
# start our socks server, get commands from the FTP cmd file
my $cmd="$srcdir/server/socksd".
" --port $port ".
" --pidfile $pidfile".
" --backend $HOSTIP".
" --config $FTPDCMD";
my ($sockspid, $pid2) = startnew($cmd, $pidfile, 30, 0);

# Config file options for ssh client are previously set from sshserver.pl
if(! -e $sshconfig) {
logmsg "RUN: SOCKS server cannot find $sshconfig\n";
$doesntrun{$pidfile} = 1;
return (0,0);
}

$sshlog = server_logfilename($LOGDIR, 'socks', $ipvnum, $idnum);

# start our socks server
my $cmd="\"$ssh\" -N -F $sshconfig $ip > $sshlog 2>&1";
my ($sshpid, $pid2) = startnew($cmd, $pidfile, 30, 1); # fake pidfile

if($sshpid <= 0 || !pidexists($sshpid)) {
if($sockspid <= 0 || !pidexists($sockspid)) {
# it is NOT alive
logmsg "RUN: failed to start the $srvrname server\n";
display_sshlog();
display_sshconfig();
display_sshdlog();
display_sshdconfig();
stopserver($server, "$pid2");
$doesntrun{$pidfile} = 1;
return (0,0);
}

# Ugly hack but ssh doesn't support pid files. PID is from fake pidfile.
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, "$sshpid $pid2");
$doesntrun{$pidfile} = 1;
return (0,0);
}
$pid2 = $pid3;

if($verbose) {
logmsg "RUN: $srvrname server is now running PID $pid2\n";
}

return ($pid2, $sshpid);
return ($pid2, $sockspid);
}

#######################################################################
@@ -3642,6 +3560,7 @@ sub singletest {
}
}
$ENV{$var} = "$content";
print "setenv $var = $content\n" if($verbose);
}
}
}
@@ -3757,7 +3676,7 @@ sub singletest {
}

# if this section exists, it might be FTP server instructions:
my @ftpservercmd = getpart("reply", "servercmd");
my @ftpservercmd = fixarray ( getpart("reply", "servercmd") );

my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout

@@ -4974,7 +4893,7 @@ sub startservers {
$run{'tftp-ipv6'}="$pid $pid2";
}
}
elsif($what eq "sftp" || $what eq "scp" || $what eq "socks4" || $what eq "socks5" ) {
elsif($what eq "sftp" || $what eq "scp") {
if(!$run{'ssh'}) {
($pid, $pid2) = runsshserver("", $verbose);
if($pid <= 0) {
@@ -4983,32 +4902,15 @@ sub startservers {
printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
$run{'ssh'}="$pid $pid2";
}
if($what eq "socks4" || $what eq "socks5") {
if(!$run{'socks'}) {
($pid, $pid2) = runsocksserver("", $verbose);
if($pid <= 0) {
return "failed starting socks server";
}
printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
$run{'socks'}="$pid $pid2";
}
}
if($what eq "socks5") {
if(!$sshdid) {
# Not an OpenSSH or SunSSH ssh daemon
logmsg "Not OpenSSH or SunSSH; socks5 tests need at least OpenSSH 3.7\n";
return "failed starting socks5 server";
}
elsif(($sshdid =~ /OpenSSH/) && ($sshdvernum < 370)) {
# Need OpenSSH 3.7 for socks5 - https://www.openssh.com/txt/release-3.7
logmsg "$sshdverstr insufficient; socks5 tests need at least OpenSSH 3.7\n";
return "failed starting socks5 server";
}
elsif(($sshdid =~ /SunSSH/) && ($sshdvernum < 100)) {
# Need SunSSH 1.0 for socks5
logmsg "$sshdverstr insufficient; socks5 tests need at least SunSSH 1.0\n";
return "failed starting socks5 server";
}
elsif($what eq "socks4" || $what eq "socks5" ) {
if(!$run{'socks'}) {
($pid, $pid2) = runsocksserver("", $verbose);
if($pid <= 0) {
return "failed starting socks server";
}
printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
$run{'socks'}="$pid $pid2";
}
}
elsif($what eq "http-unix") {
Oops, something went wrong.

0 comments on commit 54c7845

Please sign in to comment.
You can’t perform that action at this time.