From 0825cd80a62c21725fb3615f1fdd3aa6cc5f0f34 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Wed, 12 May 2010 15:33:22 +0200 Subject: FTP: WILDCARDMATCH/CHUNKING/FNMATCH added --- tests/data/Makefile.am | 1 + tests/data/test1113 | 71 ++++++++++++ tests/data/test1114 | 136 +++++++++++++++++++++++ tests/data/test146 | 2 +- tests/data/test149 | 2 +- tests/data/test539 | 2 +- tests/data/test574 | 71 ++++++++++++ tests/data/test575 | 79 ++++++++++++++ tests/data/test576 | 192 ++++++++++++++++++++++++++++++++ tests/data/test577 | 38 +++++++ tests/directories.pm | 266 +++++++++++++++++++++++++++++++++++++++++++++ tests/ftpserver.pl | 107 +++++++++++++++++- tests/libtest/Makefile.inc | 9 ++ tests/libtest/lib574.c | 56 ++++++++++ tests/libtest/lib575.c | 109 +++++++++++++++++++ tests/libtest/lib576.c | 107 ++++++++++++++++++ tests/libtest/lib577.c | 217 ++++++++++++++++++++++++++++++++++++ 17 files changed, 1461 insertions(+), 4 deletions(-) create mode 100644 tests/data/test1113 create mode 100644 tests/data/test1114 create mode 100644 tests/data/test574 create mode 100644 tests/data/test575 create mode 100644 tests/data/test576 create mode 100644 tests/data/test577 create mode 100644 tests/directories.pm create mode 100644 tests/libtest/lib574.c create mode 100644 tests/libtest/lib575.c create mode 100644 tests/libtest/lib576.c create mode 100644 tests/libtest/lib577.c (limited to 'tests') diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index dabe3d195..a8cf5d7a6 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -60,6 +60,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \ test1072 test1073 test1074 test1075 test1076 test1077 test1078 test1079 \ test1080 test1081 test1082 test1083 test1084 test1085 test633 test634 \ test635 test636 test637 test558 test559 test1086 test1087 test1088 \ + test574 test575 test576 test577 test1113 test1114 \ test1089 test1090 test1091 test1092 test1093 test1094 test1095 test1096 \ test1097 test560 test561 test1098 test1099 test562 test563 test1100 \ test564 test1101 test1102 test1103 test1104 test299 test310 test311 \ diff --git a/tests/data/test1113 b/tests/data/test1113 new file mode 100644 index 000000000..6ff1d1951 --- /dev/null +++ b/tests/data/test1113 @@ -0,0 +1,71 @@ + + + +FTP +wildcardmatch +ftplistparser + + + +# +# Server-side + + + + + +# Client-side + + +ftp + + +lib574 + + +FTP wildcard download - changed fnmatch, 2x perform (DOS LIST response) + + +ftp://%HOSTIP:%FTPPORT/fully_simulated/DOS/*.txt + + + +############################################ +# Verify data after the test has been "shot" + + +0 + + +^RETR.* +^EPSV.* +^PWD.* +^CWD.* +^TYPE.* +^LIST.* + + +s/USER.*/USER/ +s/PASS.*/PASS/ +s/QUIT.*/QUIT/ + +# THERE SHOULD NOT BE "SIZE"! and once "USER && PASS" + +USER +PASS +QUIT + + +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. + + + diff --git a/tests/data/test1114 b/tests/data/test1114 new file mode 100644 index 000000000..8eee4293b --- /dev/null +++ b/tests/data/test1114 @@ -0,0 +1,136 @@ + + + +FTP +wildcardmatch +ftplistparser + + + +# Server-side + + + + + +# Client-side + + +ftp + + +lib576 + + +FTP wildcard download - skip/parser_correctness/CURLOPT_FNMATCH_FUNCTION (DOS) + + +ftp://%HOSTIP:%FTPPORT/fully_simulated/DOS/* + + + +# Verify data after the test has been "shot" + + +0 + + +============================================================= +Remains: 12 +Filename: . +Size: 0B +Time: 04-27-10 05:12AM +Filetype: directory +============================================================= +Remains: 11 +Filename: .. +Size: 0B +Time: 04-23-10 03:12AM +Filetype: directory +============================================================= +Remains: 10 +Filename: chmod1 +Size: 38B +Time: 01-11-10 10:00AM +Filetype: regular file +Content: +------------------------------------------------------------- +This file should have permissions 444 +------------------------------------------------------------- +============================================================= +Remains: 9 +Filename: chmod2 +Size: 38B +Time: 02-01-10 08:00AM +Filetype: regular file +Content: +------------------------------------------------------------- +This file should have permissions 666 +------------------------------------------------------------- +============================================================= +Remains: 8 +Filename: chmod3 +Size: 38B +Time: 02-01-10 08:00AM +Filetype: regular file +Content: +------------------------------------------------------------- +This file should have permissions 777 +------------------------------------------------------------- +============================================================= +Remains: 7 +Filename: chmod4 +Size: 0B +Time: 05-04-10 04:31AM +Filetype: directory +============================================================= +Remains: 6 +Filename: chmod5 +Size: 0B +Time: 05-04-10 04:31AM +Filetype: directory +============================================================= +Remains: 5 +Filename: empty_file.dat +Size: 0B +Time: 04-27-10 11:01AM +Filetype: regular file +Content: +------------------------------------------------------------- +------------------------------------------------------------- +============================================================= +Remains: 4 +Filename: file.txt +Size: 35B +Time: 04-27-10 11:01AM +Filetype: regular file +Content: +------------------------------------------------------------- +This is content of file "file.txt" +------------------------------------------------------------- +============================================================= +Remains: 3 +Filename: .NeXT +Size: 0B +Time: 01-23-05 02:05AM +Filetype: directory +============================================================= +Remains: 2 +Filename: someothertext.txt +Size: 47B +Time: 04-27-10 11:01AM +Filetype: regular file +Content: +------------------------------------------------------------- +# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK # +------------------------------------------------------------- +============================================================= +Remains: 1 +Filename: weirddir.txt +Size: 0B +Time: 04-23-10 03:12AM +Filetype: directory +============================================================= + + + diff --git a/tests/data/test146 b/tests/data/test146 index e04f8f04d..3cd4bd5aa 100644 --- a/tests/data/test146 +++ b/tests/data/test146 @@ -45,7 +45,7 @@ EPSV TYPE I SIZE 146 RETR 146 -CWD /nowhere/anywhere +CWD / EPSV SIZE 146 RETR 146 diff --git a/tests/data/test149 b/tests/data/test149 index bdbdcc77f..f7973f497 100644 --- a/tests/data/test149 +++ b/tests/data/test149 @@ -34,7 +34,7 @@ CWD dir1 EPSV TYPE I STOR 149 -CWD /nowhere/anywhere +CWD / CWD dir2 EPSV STOR 149 diff --git a/tests/data/test539 b/tests/data/test539 index f1ad70107..2406c5473 100644 --- a/tests/data/test539 +++ b/tests/data/test539 @@ -53,7 +53,7 @@ TYPE I SIZE 539 RETR 539 SYST -CWD /nowhere/anywhere +CWD / EPSV TYPE A LIST path/to/the/file/539./ diff --git a/tests/data/test574 b/tests/data/test574 new file mode 100644 index 000000000..9d500457a --- /dev/null +++ b/tests/data/test574 @@ -0,0 +1,71 @@ + + + +FTP +wildcardmatch +ftplistparser + + + +# +# Server-side + + + + + +# Client-side + + +ftp + + +lib574 + + +FTP wildcard download - changed fnmatch, 2x perform (UNIX LIST response) + + +ftp://%HOSTIP:%FTPPORT/fully_simulated/UNIX/*.txt + + + +############################################ +# Verify data after the test has been "shot" + + +0 + + +^RETR.* +^EPSV.* +^PWD.* +^CWD.* +^TYPE.* +^LIST.* + + +s/USER.*/USER/ +s/PASS.*/PASS/ +s/QUIT.*/QUIT/ + +# THERE SHOULD NOT BE "SIZE"! and once "USER && PASS" + +USER +PASS +QUIT + + +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. + + + diff --git a/tests/data/test575 b/tests/data/test575 new file mode 100644 index 000000000..c460467d2 --- /dev/null +++ b/tests/data/test575 @@ -0,0 +1,79 @@ + + + +FTP +multi +wildcardmatch +ftplistparser + + + +# Server-side + + + + + +# Client-side + + +ftp + + +lib575 + + +FTP wildcard download - dup_handle && multi interface + + +ftp://%HOSTIP:%FTPPORT/fully_simulated/UNIX/* + + +# Verify data after the test has been "shot" + + +^RETR.* +^EPSV.* +^CWD.* +^PWD.* +^TYPE.* + + +s/^USER.*/USER/ +s/^PASS.*/PASS/ +s/^LIST.*/LIST/ +s/^QUIT.*/QUIT/ + + +0 + + +USER +PASS +LIST +LIST +QUIT +USER +PASS +LIST +QUIT + + +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. +This file should have permissions 444 +This file should have permissions 666 +This file should have permissions 777 +This is content of file "file.txt" +Some junk ;-) This file does not really exist. + + + diff --git a/tests/data/test576 b/tests/data/test576 new file mode 100644 index 000000000..4d4b90c80 --- /dev/null +++ b/tests/data/test576 @@ -0,0 +1,192 @@ + + + +FTP +wildcardmatch +ftplistparser + + + +# Server-side + + + + + +# Client-side + + +ftp + + +lib576 + + +FTP wildcard download - skip/parser_correctness/CURLOPT_FNMATCH_FUNCTION (UNIX) + + +ftp://%HOSTIP:%FTPPORT/fully_simulated/UNIX/* + + + +# Verify data after the test has been "shot" + + +0 + + +============================================================= +Remains: 14 +Filename: . +Permissions: rwxrwxrwx (parsed => 777) +Size: 20480B +User: ftp-default +Group: ftp-default +Time: Apr 27 5:12 +Filetype: directory +============================================================= +Remains: 13 +Filename: .. +Permissions: rwxrwxrwx (parsed => 777) +Size: 20480B +User: ftp-default +Group: ftp-default +Time: Apr 23 3:12 +Filetype: directory +============================================================= +Remains: 12 +Filename: chmod1 +Permissions: r--r--r-- (parsed => 444) +Size: 38B +User: ftp-default +Group: ftp-default +Time: Jan 11 10:00 +Filetype: regular file +Content: +------------------------------------------------------------- +This file should have permissions 444 +------------------------------------------------------------- +============================================================= +Remains: 11 +Filename: chmod2 +Permissions: rw-rw-rw- (parsed => 666) +Size: 38B +User: ftp-default +Group: ftp-default +Time: Feb 1 8:00 +Filetype: regular file +Content: +------------------------------------------------------------- +This file should have permissions 666 +------------------------------------------------------------- +============================================================= +Remains: 10 +Filename: chmod3 +Permissions: rwxrwxrwx (parsed => 777) +Size: 38B +User: ftp-default +Group: ftp-default +Time: Feb 1 8:00 +Filetype: regular file +Content: +------------------------------------------------------------- +This file should have permissions 777 +------------------------------------------------------------- +============================================================= +Remains: 9 +Filename: chmod4 +Permissions: --S--S--t (parsed => 7001) +Size: 4096B +User: ftp-default +Group: ftp-default +Time: May 4 4:31 +Filetype: directory +============================================================= +Remains: 8 +Filename: chmod5 +Permissions: --s--s--T (parsed => 7110) +Size: 4096B +User: ftp-default +Group: ftp-default +Time: May 4 4:31 +Filetype: directory +============================================================= +Remains: 7 +Filename: empty_file.dat +Permissions: rw-r--r-- (parsed => 644) +Size: 0B +User: ftp-default +Group: ftp-default +Time: Apr 27 11:01 +Filetype: regular file +Content: +------------------------------------------------------------- +------------------------------------------------------------- +============================================================= +Remains: 6 +Filename: file.txt +Permissions: rw-r--r-- (parsed => 644) +Size: 35B +User: ftp-default +Group: ftp-default +Time: Apr 27 11:01 +Filetype: regular file +Content: +------------------------------------------------------------- +This is content of file "file.txt" +------------------------------------------------------------- +============================================================= +Remains: 5 +Filename: link +Permissions: rwxrwxrwx (parsed => 777) +Size: 0B +User: ftp-default +Group: ftp-default +Time: Jan 6 4:42 +Filetype: symlink +Target: file.txt +============================================================= +Remains: 4 +Filename: link_absolute +Permissions: rwxrwxrwx (parsed => 777) +Size: 0B +User: ftp-default +Group: ftp-default +Time: Jan 6 4:45 +Filetype: symlink +Target: /data/ftp/file.txt +============================================================= +Remains: 3 +Filename: .NeXT +Permissions: rwxrwxrwx (parsed => 777) +Size: 4096B +User: ftp-default +Group: ftp-default +Time: Jan 23 2:05 +Filetype: directory +============================================================= +Remains: 2 +Filename: someothertext.txt +Permissions: rw-r--r-- (parsed => 644) +Size: 47B +User: ftp-default +Group: ftp-default +Time: Apr 27 11:01 +Filetype: regular file +Content: +------------------------------------------------------------- +# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK # +------------------------------------------------------------- +============================================================= +Remains: 1 +Filename: weirddir.txt +Permissions: rwxr-xrwx (parsed => 757) +Size: 4096B +User: ftp-default +Group: ftp-default +Time: Apr 23 3:12 +Filetype: directory +============================================================= + + + diff --git a/tests/data/test577 b/tests/data/test577 new file mode 100644 index 000000000..5f1898f70 --- /dev/null +++ b/tests/data/test577 @@ -0,0 +1,38 @@ + + + +wildcardmatch + + +# +# Server-side + + + +# Client-side + + +none + +# tool is what to use instead of 'curl' + +lib577 + + + +Curl_fnmatch() testing + + +nothing + + + +# +# Verify data after the test has been "shot" + + +=========================== +=========================== + + + diff --git a/tests/directories.pm b/tests/directories.pm new file mode 100644 index 000000000..6f20e6feb --- /dev/null +++ b/tests/directories.pm @@ -0,0 +1,266 @@ +%file_chmod1 = ( + 'name' => 'chmod1', + 'content' => "This file should have permissions 444\n", + 'perm' => 'r--r--r--', + 'time' => 'Jan 11 10:00', + 'dostime' => '01-11-10 10:00AM', +); + +%file_chmod2 = ( + 'name' => 'chmod2', + 'content' => "This file should have permissions 666\n", + 'perm' => 'rw-rw-rw-', + 'time' => 'Feb 1 8:00', + 'dostime' => '02-01-10 08:00AM', +); + +%file_chmod3 = ( + 'name' => 'chmod3', + 'content' => "This file should have permissions 777\n", + 'perm' => 'rwxrwxrwx', + 'time' => 'Feb 1 8:00', + 'dostime' => '02-01-10 08:00AM', +); + +%file_chmod4 = ( + 'type' => 'd', + 'name' => 'chmod4', + 'content' => "This file should have permissions 001\n", + 'perm' => '--S--S--t', + 'time' => 'May 4 4:31', + 'dostime' => '05-04-10 04:31AM' +); + +%file_chmod5 = ( + 'type' => 'd', + 'name' => 'chmod5', + 'content' => "This file should have permissions 110\n", + 'perm' => '--s--s--T', + 'time' => 'May 4 4:31', + 'dostime' => '05-04-10 04:31AM' +); + +%link_link = ( + 'type' => 'l', + 'name' => 'link -> file.txt', + 'size' => '8', + 'perm' => 'rwxrwxrwx', + 'time' => 'Jan 6 4:42' +); + +%link_link_absolute = ( + 'type' => 'l', + 'name' => 'link_absolute -> /data/ftp/file.txt', + 'size' => '15', + 'perm' => 'rwxrwxrwx', + 'time' => 'Jan 6 4:45' +); + +%dir_dot = ( + 'type' => "d", + 'name' => ".", + 'hlink' => "4", + 'time' => "Apr 27 5:12", + 'size' => "20480", + 'dostime' => "04-27-10 05:12AM", + 'perm' => "rwxrwxrwx" +); + +%dir_ddot = ( + 'type' => "d", + 'name' => "..", + 'hlink' => "4", + 'size' => "20480", + 'time' => "Apr 23 3:12", + 'dostime' => "04-23-10 03:12AM", + 'perm' => "rwxrwxrwx" +); + +%dir_weirddir_txt = ( + 'type' => "d", + 'name' => "weirddir.txt", + 'hlink' => "2", + 'size' => "4096", + 'time' => "Apr 23 3:12", + 'dostime' => "04-23-10 03:12AM", + 'perm' => "rwxr-xrwx" +); + +%dir_UNIX = ( + 'type' => "d", + 'name' => "UNIX", + 'hlink' => "11", + 'size' => "4096", + 'time' => "Nov 01 2008", + 'dostime' => "11-01-08 11:11AM", + 'perm' => "rwx--x--x" +); + +%dir_DOS = ( + 'type' => "d", + 'name' => "DOS", + 'hlink' => "11", + 'size' => "4096", + 'time' => "Nov 01 2008", + 'dostime' => "11-01-08 11:11AM", + 'perm' => "rwx--x--x" +); + +%dir_dot_NeXT = ( + 'type' => "d", + 'name' => ".NeXT", + 'hlink' => "4", + 'size' => "4096", + 'time' => "Jan 23 2:05", + 'dostime' => "01-23-05 02:05AM", + 'perm' => "rwxrwxrwx" +); + +%file_empty_file_dat = ( + 'name' => "empty_file.dat", + 'content' => "", + 'perm' => "rw-r--r--", + 'time' => "Apr 27 11:01", + 'dostime' => "04-27-10 11:01AM" +); + +%file_file_txt = ( + 'name' => "file.txt", + 'content' => "This is content of file \"file.txt\"\n", + 'time' => "Apr 27 11:01", + 'dostime' => "04-27-10 11:01AM", + 'perm' => "rw-r--r--" +); + +%file_someothertext_txt = ( + 'name' => "someothertext.txt", + 'content' => "Some junk ;-) This file does not really exist.\n", + 'time' => "Apr 27 11:01", + 'dostime' => "04-27-10 11:01AM", + 'perm' => "rw-r--r--" +); + +%lists = ( + '/fully_simulated/' => { + 'files' => [ \%dir_dot, \%dir_ddot, \%dir_DOS, \%dir_UNIX ], + 'eol' => "\r\n", + 'type' => "unix" + }, + '/fully_simulated/UNIX/' => { + 'files' => [ \%dir_dot, \%dir_ddot, + \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5, + \%file_empty_file_dat, \%file_file_txt, + \%link_link, \%link_link_absolute, \%dir_dot_NeXT, + \%file_someothertext_txt, \%dir_weirddir_txt ], + 'eol' => "\r\n", + 'type' => 'unix' + }, + '/fully_simulated/DOS/' => { + 'files' => [ \%dir_dot, \%dir_ddot, + \%file_chmod1, \%file_chmod2, \%file_chmod3, \%file_chmod4, \%file_chmod5, + \%file_empty_file_dat, \%file_file_txt, + \%dir_dot_NeXT, \%file_someothertext_txt, \%dir_weirddir_txt ], + 'eol' => "\r\n", + 'type' => 'dos' + } +); + +sub ftp_createcontent($) { + my (%list) = @_; + + $type = $$list{'type'}; + $eol = $$list{'eol'}; + $list_ref = $$list{'files'}; + + my @diroutput; + my @contentlist; + if($type eq "unix") { + for(@$list_ref) { + my %file = %$_; + my $line = ""; + my $ftype = $file{'type'} ? $file{'type'} : "-"; + my $fperm = $file{'perm'} ? $file{'perm'} : "rwxr-xr-x"; + my $fuser = $file{'user'} ? sprintf("%15s", $file{'user'}) : "ftp-default"; + my $fgroup = $file{'group'} ? sprintf("%15s", $file{'group'}) : "ftp-default"; + my $fsize = ""; + if($file{'type'} eq "d") { + $fsize = $file{'size'} ? sprintf("%7s", $file{'size'}) : sprintf("%7d", 4096); + } + else { + $fsize = sprintf("%7d", length $file{'content'}); + } + my $fhlink = $file{'hlink'} ? sprintf("%4d", $file{'hlink'}) : " 1"; + my $ftime = $file{'time'} ? sprintf("%10s", $file{'time'}) : "Jan 9 1933"; + push(@contentlist, "$ftype$fperm $fhlink $fuser $fgroup $fsize $ftime $file{'name'}$eol"); + } + + return @contentlist; + } + elsif($type =~ /^dos$/) { + for(@$list_ref) { + my %file = %$_; + my $line = ""; + my $time = $file{'dostime'} ? $file{'dostime'} : "06-25-97 09:12AM"; + my $size_or_dir; + if($file{'type'} =~ /^d$/) { + $size_or_dir = " "; + } + else { + $size_or_dir = sprintf("%20d", length $file{'content'}); + } + push(@contentlist, "$time $size_or_dir $file{'name'}$eol"); + } + return @contentlist; + } +} + +sub wildcard_filesize($$) { + my ($list_type, $file) = @_; + $list = $lists{$list_type}; + if($list) { + my $files = $list->{'files'}; + for(@$files) { + my %f = %$_; + if ($f{'name'} eq $file) { + if($f{'content'}) { + return length $f{'content'}; + } + elsif ($f{'type'} ne "d"){ + return 0; + } + else { + return -1; + } + } + } + } + return -1; +} +sub wildcard_getfile($$) { + my ($list_type, $file) = @_; + $list = $lists{$list_type}; + if($list) { + my $files = $list->{'files'}; + for(@$files) { + my %f = %$_; + if ($f{'name'} eq $file) { + if($f{'content'}) { + return (length $f{'content'}, $f{'content'}); + } + elsif ($f{'type'} ne "d"){ + return (0, ""); + } + else { + return (-1, 0); + } + } + } + } + return (-1, 0); +} + +sub ftp_contentlist { + my $listname = $_[0]; + $list = $lists{$listname}; + return ftp_createcontent(\$list); +} diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl index cc69585c8..ed2a83268 100755 --- a/tests/ftpserver.pl +++ b/tests/ftpserver.pl @@ -54,6 +54,7 @@ use IPC::Open2; require "getpart.pm"; require "ftp.pm"; +require "directories.pm"; use serverhelp qw( servername_str @@ -136,6 +137,13 @@ my %customreply; # my %customcount; # my %delayreply; # +#********************************************************************** +# global variables for to test ftp wildcardmatching or other test that +# need flexible LIST responses.. and corresponding files. +# $ftptargetdir is keeping the fake "name" of LIST directory. +my $ftplistparserstate; +my $ftptargetdir; + #********************************************************************** # global vars used for signal handling # @@ -344,6 +352,8 @@ sub protocolsetup { 'LIST' => \&LIST_ftp, 'NLST' => \&NLST_ftp, 'PASV' => \&PASV_ftp, + 'CWD' => \&CWD_ftp, + 'PWD' => \&PWD_ftp, 'EPSV' => \&PASV_ftp, 'RETR' => \&RETR_ftp, 'SIZE' => \&SIZE_ftp, @@ -362,7 +372,6 @@ sub protocolsetup { 'CWD' => '250 CWD command successful.', 'SYST' => '215 UNIX Type: L8', # just fake something 'QUIT' => '221 bye bye baby', # just reply something - 'PWD' => '257 "/nowhere/anywhere" is current directory', 'MKD' => '257 Created your requested directory', 'REST' => '350 Yeah yeah we set it there for you', 'DELE' => '200 OK OK OK whatever you say', @@ -683,6 +692,64 @@ sub REST_ftp { logmsg "Set REST position to $rest\n" } +sub switch_directory_goto { + my $target_dir = $_; + + if(!$ftptargetdir) { + $ftptargetdir = "/"; + } + + if($target_dir eq "") { + $ftptargetdir = "/"; + } + elsif($target_dir eq "..") { + if($ftptargetdir eq "/") { + $ftptargetdir = "/"; + } + else { + $ftptargetdir =~ s/[[:alnum:]]+\/$//; + } + } + else { + $ftptargetdir .= $target_dir . "/"; + } +} + +sub switch_directory { + my $target_dir = $_[0]; + + if($target_dir eq "/") { + $ftptargetdir = "/"; + } + else { + my @dirs = split("/", $target_dir); + for(@dirs) { + switch_directory_goto($_); + } + } +} + +sub CWD_ftp { + my ($folder, $fullcommand) = $_[0]; + switch_directory($folder); + if($ftptargetdir =~ /^\/fully_simulated/) { + $ftplistparserstate = "enabled"; + } + else { + undef $ftplistparserstate; + } +} + +sub PWD_ftp { + my $mydir; + $mydir = $ftptargetdir ? $ftptargetdir : "/"; + + if($mydir ne "/") { + $mydir =~ s/\/$//; + } + sendcontrol "257 \"$mydir\" is current directory\r\n"; +} + sub LIST_ftp { # print "150 ASCII data connection for /bin/ls (193.15.23.1,59196) (0 bytes)\r\n"; @@ -699,6 +766,10 @@ my @ftpdir=("total 20\r\n", "drwxrwxrwx 2 98 1 512 Oct 30 14:33 pub\r\n", "dr-xr-xr-x 5 0 1 512 Oct 1 1997 usr\r\n"); + if($ftplistparserstate) { + @ftpdir = ftp_contentlist($ftptargetdir); + } + logmsg "pass LIST data on data connection\n"; for(@ftpdir) { senddata $_; @@ -748,6 +819,16 @@ sub MDTM_ftp { sub SIZE_ftp { my $testno = $_[0]; + if($ftplistparserstate) { + my $size = wildcard_filesize($ftptargetdir, $testno); + if($size == -1) { + sendcontrol "550 $testno: No such file or directory.\r\n"; + } + else { + sendcontrol "213 $size\r\n"; + } + return 0; + } if($testno =~ /^verifiedserver$/) { my $response = "WE ROOLZ: $$\r\n"; @@ -803,6 +884,21 @@ sub SIZE_ftp { sub RETR_ftp { my ($testno) = @_; + if($ftplistparserstate) { + my @content = wildcard_getfile($ftptargetdir, $testno); + if($content[0] == -1) { + #file not found + } + else { + my $size = length $content[1]; + sendcontrol "150 Binary data connection for $testno ($size bytes).\r\n", + senddata $content[1]; + close_dataconn(0); + sendcontrol "226 File transfer complete\r\n"; + } + return 0; + } + if($testno =~ /^verifiedserver$/) { # this is the secret command that verifies that this actually is # the curl test server @@ -1326,6 +1422,15 @@ while(1) { &customize(); # read test control instructions sendcontrol @welcome; + + #remove global variables from last connection + if($ftplistparserstate) { + undef $ftplistparserstate; + } + if($ftptargetdir) { + undef $ftptargetdir; + } + if($verbose) { for(@welcome) { print STDERR "OUT: $_"; diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 58d5d9226..814c01e6c 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -8,6 +8,7 @@ SUPPORTFILES = first.c test.h noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \ lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516 \ lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526 lib527 \ + lib574 lib575 lib576 lib577 \ lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \ lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \ lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 lib567 \ @@ -124,6 +125,14 @@ lib559_CFLAGS = -DLIB559 lib560_SOURCES = lib560.c $(SUPPORTFILES) +lib574_SOURCES = lib574.c $(SUPPORTFILES) + +lib575_SOURCES = lib575.c $(SUPPORTFILES) + +lib576_SOURCES = lib576.c $(SUPPORTFILES) + +lib577_SOURCES = lib577.c $(SUPPORTFILES) + lib562_SOURCES = lib562.c $(SUPPORTFILES) lib564_SOURCES = lib564.c $(SUPPORTFILES) $(TESTUTIL) diff --git a/tests/libtest/lib574.c b/tests/libtest/lib574.c new file mode 100644 index 000000000..69b2979a8 --- /dev/null +++ b/tests/libtest/lib574.c @@ -0,0 +1,56 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" + +#include "memdebug.h" + +static int new_fnmatch(const char *pattern, const char *string) +{ + (void)pattern; + (void)string; + return CURL_FNMATCHFUNC_MATCH; +} + +int test(char *URL) +{ + int res; + CURL *curl; + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + test_setopt(curl, CURLOPT_URL, URL); + test_setopt(curl, CURLOPT_WILDCARDMATCH, 1L); + test_setopt(curl, CURLOPT_FNMATCH_FUNCTION, new_fnmatch); + + res = curl_easy_perform(curl); + if(res) { + fprintf(stderr, "curl_easy_perform() failed %d\n", res); + goto test_cleanup; + } + res = curl_easy_perform(curl); + if(res) { + fprintf(stderr, "curl_easy_perform() failed %d\n", res); + goto test_cleanup; + } + +test_cleanup: + curl_easy_cleanup(curl); + curl_global_cleanup(); + return res; +} diff --git a/tests/libtest/lib575.c b/tests/libtest/lib575.c new file mode 100644 index 000000000..3bf15ea26 --- /dev/null +++ b/tests/libtest/lib575.c @@ -0,0 +1,109 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" + +#include +#include +#include + +#include "testutil.h" +#include "memdebug.h" + +/* 3x download! + * 1. normal + * 2. dup handle + * 3. with multi interface + */ + +int test(char *URL) +{ + CURLMcode m; + CURL *handle = NULL, *duphandle; + CURLM *mhandle = NULL; + int res = 0; + int still_running = 0; + + if(curl_global_init(CURL_GLOBAL_ALL)) { + fprintf(stderr, "curl_global_init() failed\n"); + goto test_cleanup; + } + + handle = curl_easy_init(); + if(!handle) { + res = CURLE_OUT_OF_MEMORY; + goto test_cleanup; + } + + test_setopt(handle, CURLOPT_URL, URL); + test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L); + test_setopt(handle, CURLOPT_VERBOSE, 1L); + + res = curl_easy_perform(handle); + if(res) + goto test_cleanup; + + res = curl_easy_perform(handle); + if(res) + goto test_cleanup; + + duphandle = curl_easy_duphandle(handle); + if(!duphandle) + goto test_cleanup; + curl_easy_cleanup(handle); + handle = duphandle; + + mhandle = curl_multi_init(); + if(!mhandle) { + fprintf(stderr, "curl_multi_init() failed\n"); + goto test_cleanup; + } + + curl_multi_add_handle(mhandle, handle); + + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(mhandle, &still_running)); + + while(still_running) { + struct timeval timeout; + int rc; + fd_set fdread; + fd_set fdwrite; + fd_set fdexcep; + int max_fdset = -1; + FD_ZERO(&fdread); + FD_ZERO(&fdwrite); + FD_ZERO(&fdexcep); + timeout.tv_sec = 3; + timeout.tv_usec = 0; + + m = curl_multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &max_fdset); + rc = select(max_fdset + 1, &fdread, &fdwrite, &fdexcep, &timeout); + if(rc == -1) { + fprintf(stderr, "select() error\n"); + goto test_cleanup; + } + else if(rc == 0) { + fprintf(stderr, "select() timeout!\n"); + goto test_cleanup; + } + else { + while(CURLM_CALL_MULTI_PERFORM == + curl_multi_perform(mhandle, &still_running)); + } + } + +test_cleanup: + if(mhandle) + curl_multi_cleanup(mhandle); + if(handle) + curl_easy_cleanup(handle); + curl_global_cleanup(); + return res; +} diff --git a/tests/libtest/lib576.c b/tests/libtest/lib576.c new file mode 100644 index 000000000..7f2c7ae37 --- /dev/null +++ b/tests/libtest/lib576.c @@ -0,0 +1,107 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" +#include "testutil.h" +#include "memdebug.h" + +typedef struct { + int remains; + int print_content; +} chunk_data_t; + +long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains); +long chunk_end(void *ptr); + +long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains) +{ + chunk_data_t *ch_d = ptr; + ch_d->remains = remains; + + printf("=============================================================\n"); + printf("Remains: %d\n", remains); + printf("Filename: %s\n", finfo->filename); + if(finfo->strings.perm) { + printf("Permissions: %s", finfo->strings.perm); + if(finfo->flags & CURLFINFOFLAG_KNOWN_PERM) + printf(" (parsed => %o)", finfo->perm); + printf("\n"); + } + printf("Size: %lldB\n", (long long int)finfo->size); + if(finfo->strings.user) + printf("User: %s\n", finfo->strings.user); + if(finfo->strings.group) + printf("Group: %s\n", finfo->strings.group); + if(finfo->strings.time) + printf("Time: %s\n", finfo->strings.time); + printf("Filetype: "); + switch(finfo->filetype) { + case CURLFILETYPE_FILE: + printf("regular file\n"); + break; + case CURLFILETYPE_DIRECTORY: + printf("directory\n"); + break; + case CURLFILETYPE_SYMLINK: + printf("symlink\n"); + printf("Target: %s\n", finfo->strings.target); + break; + default: + printf("other type\n"); + break; + } + if(finfo->filetype == CURLFILETYPE_FILE) { + ch_d->print_content = 1; + printf("Content:\n-------------------------------------------------------------\n"); + } + if(strcmp(finfo->filename, "someothertext.txt") == 0) { + printf("# THIS CONTENT WAS SKIPPED IN CHUNK_BGN CALLBACK #\n"); + return CURL_CHUNK_BGN_FUNC_SKIP; + } + return CURL_CHUNK_BGN_FUNC_OK; +} + +long chunk_end(void *ptr) +{ + chunk_data_t *ch_d = ptr; + if(ch_d->print_content) { + ch_d->print_content = 0; + printf("-------------------------------------------------------------\n"); + } + if(ch_d->remains == 1) + printf("=============================================================\n"); + return CURL_CHUNK_END_FUNC_OK; +} + +int test(char *URL) +{ + CURL *handle = NULL; + CURLcode res = 0; + chunk_data_t chunk_data = {0,0}; + curl_global_init(CURL_GLOBAL_ALL); + handle = curl_easy_init(); + if(!handle) { + res = CURLE_OUT_OF_MEMORY; + goto test_cleanup; + } + + test_setopt(handle, CURLOPT_URL, URL); + test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L); + test_setopt(handle, CURLOPT_CHUNK_BGN_FUNCTION, chunk_bgn); + test_setopt(handle, CURLOPT_CHUNK_END_FUNCTION, chunk_end); + test_setopt(handle, CURLOPT_CHUNK_DATA, &chunk_data); + + res = curl_easy_perform(handle); + +test_cleanup: + if(handle) + curl_easy_cleanup(handle); + curl_global_cleanup(); + return res; +} diff --git a/tests/libtest/lib577.c b/tests/libtest/lib577.c new file mode 100644 index 000000000..8b434f8fb --- /dev/null +++ b/tests/libtest/lib577.c @@ -0,0 +1,217 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" + +#include "memdebug.h" + +#include "curl_fnmatch.h" + +#define MATCH CURL_FNMATCH_MATCH +#define NOMATCH CURL_FNMATCH_NOMATCH +#define ERROR CURL_FNMATCH_FAIL + +#define MAX_PATTERN_L 100 +#define MAX_STRING_L 100 + +struct testcase { + char pattern[MAX_PATTERN_L]; + char string[MAX_STRING_L]; + int result; +}; + +static const struct testcase tests[] = { + /* brackets syntax */ + { "\\[", "[", MATCH }, + { "[", "[", ERROR }, + { "[]", "[]", ERROR }, + { "[][]", "[", MATCH }, + { "[][]", "]", MATCH }, + { "[[]", "[", MATCH }, + { "[[[]", "[", MATCH }, + { "[[[[]", "[", MATCH }, + { "[[[[]", "[", MATCH }, + + { "[][[]", "]", MATCH }, + { "[][[[]", "[", MATCH }, + { "[[]", "]", NOMATCH }, + + { "[a-z]", "a", MATCH }, + { "[a-z]", "A", NOMATCH }, + { "?[a-z]", "?Z", NOMATCH }, + { "[A-Z]", "C", MATCH }, + { "[A-Z]", "c", NOMATCH }, + { "[0-9]", "7", MATCH }, + { "[7-8]", "7", MATCH }, + { "[7-]", "7", MATCH }, + { "[7-]", "-", MATCH }, + { "[7-]", "[", NOMATCH }, + { "[a-bA-F]", "F", MATCH }, + { "[a-bA-B9]", "9", MATCH }, + { "[a-bA-B98]", "8", MATCH }, + { "[a-bA-B98]", "C", NOMATCH }, + { "[a-bA-Z9]", "F", MATCH }, + { "[a-bA-Z9]ero*", "Zero chance.", MATCH }, + { "S[a-][x]opho*", "Saxophone", MATCH }, + { "S[a-][x]opho*", "SaXophone", NOMATCH }, + { "S[a-][x]*.txt", "S-x.txt", MATCH }, + { "[\\a-\\b]", "a", MATCH }, + { "[\\a-\\b]", "b", MATCH }, + { "[?*[][?*[][?*[]", "?*[", MATCH }, + { "[][?*-]", "]", MATCH }, + { "[][?*-]", "[", MATCH }, + { "[][?*-]", "?", MATCH }, + { "[][?*-]", "*", MATCH }, + { "[][?*-]", "-", MATCH }, + { "[]?*-]", "-", MATCH }, + { "?/b/c", "a/b/c", MATCH }, + { "^_{}~", "^_{}~", MATCH }, + { "!#%+,-./01234567889", "!#%+,-./01234567889", MATCH }, + { "PQRSTUVWXYZ]abcdefg", "PQRSTUVWXYZ]abcdefg", MATCH }, + { ":;=@ABCDEFGHIJKLMNO", ":;=@ABCDEFGHIJKLMNO", MATCH }, + + /* negate */ + { "[!a]", "b", MATCH }, + { "[!a]", "a", NOMATCH }, + { "[^a]", "b", MATCH }, + { "[^a]", "a", NOMATCH }, + { "[^a-z0-9A-Z]", "a", NOMATCH }, + { "[^a-z0-9A-Z]", "-", MATCH }, + { "curl[!a-z]lib", "curl lib", MATCH }, + { "curl[! ]lib", "curl lib", NOMATCH }, + { "[! ][ ]", " ", NOMATCH }, + { "[! ][ ]", "a ", MATCH }, + { "*[^a].t?t", "a.txt", NOMATCH }, + { "*[^a].t?t", "ba.txt", NOMATCH }, + { "*[^a].t?t", "ab.txt", MATCH }, + { "[!?*[]", "?", NOMATCH }, + { "[!!]", "!", NOMATCH }, + { "[!!]", "x", MATCH }, + + { "[[:alpha:]]", "a", MATCH }, + { "[[:alpha:]]", "9", NOMATCH }, + { "[[:alnum:]]", "a", MATCH }, + { "[[:alnum:]]", "[", NOMATCH }, + { "[[:alnum:]]", "]", NOMATCH }, + { "[[:alnum:]]", "9", MATCH }, + { "[[:digit:]]", "9", MATCH }, + { "[[:xdigit:]]", "9", MATCH }, + { "[[:xdigit:]]", "F", MATCH }, + { "[[:xdigit:]]", "G", NOMATCH }, + { "[[:upper:]]", "U", MATCH }, + { "[[:upper:]]", "u", NOMATCH }, + { "[[:lower:]]", "l", MATCH }, + { "[[:lower:]]", "L", NOMATCH }, + { "[[:print:]]", "L", MATCH }, + { "[[:print:]]", {'\10'}, NOMATCH }, + { "[[:print:]]", {'\10'}, NOMATCH }, + { "[[:space:]]", " ", MATCH }, + { "[[:space:]]", "x", NOMATCH }, + { "[[:graph:]]", " ", NOMATCH }, + { "[[:graph:]]", "x", MATCH }, + { "[[:blank:]]", {'\t'}, MATCH }, + { "[[:blank:]]", {' '}, MATCH }, + { "[[:blank:]]", {'\r'}, NOMATCH }, + { "[^[:blank:]]", {'\t'}, NOMATCH }, + { "[^[:print:]]", {'\10'}, MATCH }, + { "[[:lower:]][[:lower:]]", "ll", MATCH }, + + { "Curl[[:blank:]];-)", "Curl ;-)", MATCH }, + { "*[[:blank:]]*", " ", MATCH }, + { "*[[:blank:]]*", "", NOMATCH }, + { "*[[:blank:]]*", "hi, im_Pavel", MATCH }, + + /* common using */ + { "filename.dat", "filename.dat", MATCH }, + { "*curl*", "lets use curl!!", MATCH }, + { "filename.txt", "filename.dat", NOMATCH }, + { "*.txt", "text.txt", MATCH }, + { "*.txt", "a.txt", MATCH }, + { "*.txt", ".txt", MATCH }, + { "*.txt", "txt", NOMATCH }, + { "??.txt", "99.txt", MATCH }, + { "??.txt", "a99.txt", NOMATCH }, + { "?.???", "a.txt", MATCH }, + { "*.???", "somefile.dat", MATCH }, + { "*.???", "photo.jpeg", NOMATCH }, + { ".*", ".htaccess", MATCH }, + { ".*", ".", MATCH }, + { ".*", "..", MATCH }, + + /* many stars => one star */ + { "**.txt", "text.txt", MATCH }, + { "***.txt", "t.txt", MATCH }, + { "****.txt", ".txt", MATCH }, + + /* empty string or pattern */ + { "", "", MATCH } , + { "", "hello", NOMATCH }, + { "file", "", NOMATCH }, + { "?", "", NOMATCH }, + { "*", "", MATCH }, + { "x", "", NOMATCH }, + + /* backslash */ + { "\\", "\\", ERROR }, + { "\\\\", "\\", MATCH }, + { "\\\\", "\\\\", NOMATCH }, + { "\\?", "?", MATCH }, + { "\\*", "*", MATCH }, + { "?.txt", "?.txt", MATCH }, + { "*.txt", "*.txt", MATCH }, + { "\\?.txt", "?.txt", MATCH }, + { "\\*.txt", "*.txt", MATCH }, + { "\\?.txt", "x.txt", NOMATCH }, + { "\\*.txt", "x.txt", NOMATCH }, + { "\\*\\\\.txt", "*\\.txt", MATCH }, + { "*\\**\\?*\\\\*", "cc*cc?cc\\cc*cc", MATCH }, + { "*\\**\\?*\\\\*", "cc*cc?cccc", NOMATCH }, + { "*\\**\\?*\\\\*", "cc*cc?cc\\cc*cc", MATCH }, + { "*\\?*\\**", "cc?c*c", MATCH }, + { "*\\?*\\**curl*", "cc?c*curl", MATCH }, + { "*\\?*\\**", "cc?cc", NOMATCH }, + { "\\\"\\$\\&\\'\\(\\)", "\"$&'()", MATCH }, + { "\\*\\?\\[\\\\\\`\\|", "*?[\\`|", MATCH }, + { "[\\a\\b]c", "ac", MATCH }, + { "[\\a\\b]c", "bc", MATCH }, + { "[\\a\\b]d", "bc", NOMATCH }, + { "[a-bA-B\\?]", "?", MATCH }, + { "cu[a-ab-b\\r]l", "curl", MATCH }, + { "[\\a-z]", "c", MATCH }, + + { "?*?*?.*?*", "abc.c", MATCH }, + { "?*?*?.*?*", "abcc", NOMATCH }, + { "?*?*?.*?*", "abc.", NOMATCH }, + { "?*?*?.*?*", "abc.c++", MATCH }, + { "?*?*?.*?*", "abcdef.c++", MATCH }, + { "?*?*?.?", "abcdef.c", MATCH }, + { "?*?*?.?", "abcdef.cd", NOMATCH }, + + { "Lindmätarv", "Lindmätarv", MATCH }, + + { "", "", MATCH } +}; + + +int test(char *URL) +{ + int testnum = sizeof(tests) / sizeof(struct testcase); + int i, rc; + (void)URL; /* not used */ + printf("===========================\n"); + for(i = 0; i < testnum; i++) { + rc = Curl_fnmatch(tests[i].pattern, tests[i].string); + if(rc != tests[i].result) { + printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n", + tests[i].pattern, tests[i].string, tests[i].result, rc); + } + } + printf("===========================\n"); + return 0; +} -- cgit v1.2.3